@nu-art/file-upload-frontend 0.400.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,13 @@
1
+ import { AppToolsScreen, ComponentSync } from '@nu-art/thunderstorm-frontend/index';
2
+ import { ResolvableContent } from '@nu-art/ts-common';
3
+ type Props = {
4
+ pageTitle?: ResolvableContent<string>;
5
+ };
6
+ type State = {};
7
+ export declare class ATS_FileUploader extends ComponentSync<Props, State> {
8
+ static screen: AppToolsScreen;
9
+ static defaultProps: Partial<Props>;
10
+ constructor(p: Props);
11
+ render(): import("react/jsx-runtime").JSX.Element;
12
+ }
13
+ export {};
@@ -0,0 +1,35 @@
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
+ import { FirebaseAnalyticsModule } from '@nu-art/firebase-frontend/index';
3
+ // import {TS_Icons} from '@nu-art/ts-styles';
4
+ import { ATS_Fullstack, ComponentSync, LL_H_C, LL_H_T, LL_V_L, openContent, TS_DragAndDrop } from '@nu-art/thunderstorm-frontend/index';
5
+ import { ModuleFE_AssetUploader } from '../modules/ModuleFE_AssetUploader.js';
6
+ import { ModuleFE_Assets } from '../modules/ModuleFE_Assets.js';
7
+ import { resolveContent, sortArray } from '@nu-art/ts-common';
8
+ export class ATS_FileUploader extends ComponentSync {
9
+ static screen = {
10
+ name: `File Uploader`,
11
+ renderer: this,
12
+ group: ATS_Fullstack,
13
+ modulesToAwait: [ModuleFE_Assets],
14
+ };
15
+ static defaultProps = {
16
+ pageTitle: () => this.screen.name
17
+ };
18
+ constructor(p) {
19
+ super(p);
20
+ // @ts-ignore
21
+ FirebaseAnalyticsModule.setCurrentScreen(resolveContent(this.props.pageTitle));
22
+ }
23
+ render() {
24
+ return _jsxs(LL_H_T, { children: ["\u00A7", _jsx(LL_V_L, { children: sortArray([...ModuleFE_Assets.cache.all()], asset => asset.__updated).map(asset => {
25
+ const tooltip = openContent.tooltip.bottom(`${asset._id}-tooltip`, () => {
26
+ return _jsxs(LL_V_L, { children: [asset.bucketName, "/", asset.path] });
27
+ }, { offset: 10 });
28
+ return _jsx(LL_H_C, { className: "clickable h-gap__n", ...tooltip, children: asset.name }, asset._id);
29
+ }) }), _jsx("div", { style: { width: 400, height: 302 }, children: _jsx(TS_DragAndDrop, { validate: files => {
30
+ return files.map(file => ({ file, accepted: true }));
31
+ }, onChange: acceptedFiles => {
32
+ return ModuleFE_AssetUploader.upload(acceptedFiles, 'test-upload');
33
+ } }) })] });
34
+ }
35
+ }
@@ -0,0 +1,2 @@
1
+ .ts-ats.ats-FileUploader {
2
+ }
@@ -0,0 +1 @@
1
+ export * from './ATS_FileUploader.js';
@@ -0,0 +1 @@
1
+ export * from './ATS_FileUploader.js';
@@ -0,0 +1 @@
1
+ export declare const ModulePackFE_FileUploader: (import("@nu-art/push-pub-sub-frontend/index").ModuleFE_PushPubSub_Class | import("../modules/ModuleFE_AssetUploader.js").ModuleFE_AssetUploader_Class | import("@nu-art/firebase-frontend").ModuleFE_Firebase_Class | import("@nu-art/push-pub-sub-frontend/modules/ModuleFE_PushSubscription").ModuleFE_PushSubscription_Class | import("../modules/ModuleFE_Assets.js").ModuleFE_Assets_Class)[];
@@ -0,0 +1,26 @@
1
+ /*
2
+ * Permissions management system, define access level for each of
3
+ * your server apis, and restrict users by giving them access levels
4
+ *
5
+ * Copyright (C) 2020 Adam van der Kruk aka TacB0sS
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ import { ModuleFE_AssetUploader } from '../modules/ModuleFE_AssetUploader.js';
20
+ import { ModulePackFE_PushPubSub } from '@nu-art/push-pub-sub-frontend/index';
21
+ import { ModuleFE_Assets } from '../modules/ModuleFE_Assets.js';
22
+ export const ModulePackFE_FileUploader = [
23
+ ...ModulePackFE_PushPubSub,
24
+ ModuleFE_Assets,
25
+ ModuleFE_AssetUploader,
26
+ ];
package/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './core/module-pack.js';
2
+ export * from './modules/ModuleFE_Assets.js';
3
+ export * from './modules/ModuleFE_AssetUploader.js';
package/index.js ADDED
@@ -0,0 +1,21 @@
1
+ /*
2
+ * Permissions management system, define access level for each of
3
+ * your server apis, and restrict users by giving them access levels
4
+ *
5
+ * Copyright (C) 2020 Adam van der Kruk aka TacB0sS
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ export * from './core/module-pack.js';
20
+ export * from './modules/ModuleFE_Assets.js';
21
+ export * from './modules/ModuleFE_AssetUploader.js';
@@ -0,0 +1,17 @@
1
+ import { ThunderDispatcher } from '@nu-art/thunderstorm-frontend/index';
2
+ import { ApiStruct_AssetUploader, OnFileStatusChanged, TempSignedUrl, UI_Asset } from '@nu-art/file-upload-shared';
3
+ import { ModuleBase_AssetUploader } from '@nu-art/file-upload-shared/modules/ModuleBase_AssetUploader';
4
+ import { PushMessage_Payload } from '@nu-art/push-pub-sub-shared';
5
+ import { ApiDef, ApiDefCaller, BaseHttpRequest, TypedApi } from '@nu-art/thunderstorm-shared';
6
+ import { PushMessage_FileUploaded } from '@nu-art/file-upload-shared/assets/messages';
7
+ export declare class ModuleFE_AssetUploader_Class extends ModuleBase_AssetUploader {
8
+ protected readonly dispatch_fileStatusChange: ThunderDispatcher<OnFileStatusChanged, "__onFileStatusChanged", [id: string], void>;
9
+ readonly vv1: ApiDefCaller<ApiStruct_AssetUploader>['vv1'];
10
+ constructor();
11
+ upload(files: File[], key: string, _public?: boolean): UI_Asset[];
12
+ createRequest<API extends TypedApi<any, any, any, any>>(uploadFile: ApiDef<API>): BaseHttpRequest<API>;
13
+ protected dispatchFileStatusChange(id: string): void;
14
+ protected subscribeToPush(toSubscribe: TempSignedUrl[]): Promise<void>;
15
+ __onMessageReceived(notification: PushMessage_Payload<PushMessage_FileUploaded>): void;
16
+ }
17
+ export declare const ModuleFE_AssetUploader: ModuleFE_AssetUploader_Class;
@@ -0,0 +1,62 @@
1
+ /*
2
+ * Permissions management system, define access level for each of
3
+ * your server apis, and restrict users by giving them access levels
4
+ *
5
+ * Copyright (C) 2020 Adam van der Kruk aka TacB0sS
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ import { apiWithBody, apiWithQuery, ModuleFE_XHR, ThunderDispatcher } from '@nu-art/thunderstorm-frontend/index';
20
+ import { ApiDef_AssetUploader, FileStatus, PushKey_FileUploaded } from '@nu-art/file-upload-shared';
21
+ import { ModuleBase_AssetUploader } from '@nu-art/file-upload-shared/modules/ModuleBase_AssetUploader';
22
+ import { ModuleFE_PushPubSub } from '@nu-art/push-pub-sub-frontend/modules/ModuleFE_PushPubSub';
23
+ import { generateHex } from '@nu-art/ts-common';
24
+ export class ModuleFE_AssetUploader_Class extends ModuleBase_AssetUploader {
25
+ dispatch_fileStatusChange = new ThunderDispatcher('__onFileStatusChanged');
26
+ vv1;
27
+ constructor() {
28
+ super();
29
+ this.vv1 = {
30
+ getUploadUrl: apiWithBody(ApiDef_AssetUploader.vv1.getUploadUrl),
31
+ processAssetManually: apiWithQuery(ApiDef_AssetUploader.vv1.processAssetManually),
32
+ };
33
+ }
34
+ upload(files, key, _public = false) {
35
+ return this.uploadImpl(files.map((file => {
36
+ return {
37
+ feId: generateHex(32),
38
+ name: file.name,
39
+ mimeType: file.type,
40
+ key,
41
+ file,
42
+ ext: ''
43
+ };
44
+ })));
45
+ }
46
+ createRequest(uploadFile) {
47
+ return ModuleFE_XHR.createRequest(uploadFile);
48
+ }
49
+ dispatchFileStatusChange(id) {
50
+ this.dispatch_fileStatusChange.dispatchUI(id);
51
+ }
52
+ async subscribeToPush(toSubscribe) {
53
+ const subscriptions = toSubscribe.map(r => ({ topic: PushKey_FileUploaded, props: { feId: r.asset.feId } }));
54
+ await ModuleFE_PushPubSub.v1.registerAll(subscriptions).executeSync();
55
+ }
56
+ __onMessageReceived(notification) {
57
+ super.__onMessageReceived(notification);
58
+ if (notification.message?.status === FileStatus.Completed || notification.message?.status?.startsWith('Error'))
59
+ ModuleFE_PushPubSub.v1.unregister({ topic: PushKey_FileUploaded, filter: notification.filter });
60
+ }
61
+ }
62
+ export const ModuleFE_AssetUploader = new ModuleFE_AssetUploader_Class();
@@ -0,0 +1,14 @@
1
+ import { ModuleFE_BaseApi, ThunderDispatcher } from '@nu-art/thunderstorm-frontend/index';
2
+ import { ApiStruct_Assets, DBProto_Assets } from '@nu-art/file-upload-shared';
3
+ import { ApiDefCaller } from '@nu-art/thunderstorm-shared';
4
+ import { ApiCallerEventType } from '@nu-art/thunderstorm-frontend/core/db-api-gen/types';
5
+ export interface OnAssetsUpdated {
6
+ __onAssetsUpdated: (...params: ApiCallerEventType<DBProto_Assets>) => void;
7
+ }
8
+ export declare const dispatch_onAssetsListChanged: ThunderDispatcher<OnAssetsUpdated, "__onAssetsUpdated", ApiCallerEventType<DBProto_Assets>, void>;
9
+ export declare class ModuleFE_Assets_Class extends ModuleFE_BaseApi<DBProto_Assets> {
10
+ readonly vv1: ApiDefCaller<ApiStruct_Assets>['vv1'];
11
+ constructor();
12
+ resolveValidSignedUrl(assetId: string): Promise<string>;
13
+ }
14
+ export declare const ModuleFE_Assets: ModuleFE_Assets_Class;
@@ -0,0 +1,23 @@
1
+ import { apiWithBody, ModuleFE_BaseApi, ThunderDispatcher } from '@nu-art/thunderstorm-frontend/index';
2
+ import { currentTimeMillis } from '@nu-art/ts-common';
3
+ import { ApiDef_Assets, DBDef_Assets } from '@nu-art/file-upload-shared';
4
+ export const dispatch_onAssetsListChanged = new ThunderDispatcher('__onAssetsUpdated');
5
+ export class ModuleFE_Assets_Class extends ModuleFE_BaseApi {
6
+ vv1;
7
+ constructor() {
8
+ super(DBDef_Assets, dispatch_onAssetsListChanged);
9
+ this.vv1 = {
10
+ getReadSignedUrl: apiWithBody(ApiDef_Assets.vv1.getReadSignedUrl),
11
+ };
12
+ }
13
+ async resolveValidSignedUrl(assetId) {
14
+ const asset = this.cache.unique(assetId);
15
+ const signedUrl = (asset?.signedUrl?.validUntil || 0) > currentTimeMillis() ? asset?.signedUrl : undefined;
16
+ if (signedUrl)
17
+ return signedUrl.url;
18
+ const request = this.vv1.getReadSignedUrl({ _id: assetId });
19
+ const response = await request.executeSync();
20
+ return response.signedUrl;
21
+ }
22
+ }
23
+ export const ModuleFE_Assets = new ModuleFE_Assets_Class();
package/package.json ADDED
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "@nu-art/file-upload-frontend",
3
+ "version": "0.400.7",
4
+ "description": "File Uploader - Express & Typescript based backend framework Frontend",
5
+ "keywords": [
6
+ "TacB0sS",
7
+ "infra",
8
+ "nu-art",
9
+ "storm",
10
+ "thunderstorm",
11
+ "typescript"
12
+ ],
13
+ "homepage": "https://github.com/nu-art-js/file-upload",
14
+ "bugs": {
15
+ "url": "https://github.com/nu-art-js/file-upload/issues"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+ssh://git@github.com:nu-art-js/file-upload.git"
20
+ },
21
+ "publishConfig": {
22
+ "directory": "dist",
23
+ "linkDirectory": true
24
+ },
25
+ "license": "Apache-2.0",
26
+ "author": "TacB0sS",
27
+ "files": [
28
+ "**/*"
29
+ ],
30
+ "scripts": {
31
+ "build": "tsc"
32
+ },
33
+ "dependencies": {
34
+ "@nu-art/file-upload-shared": "0.400.7",
35
+ "@google-cloud/common": "^5.0.2",
36
+ "@google-cloud/firestore": "^7.11.0",
37
+ "@google-cloud/storage": "^7.15.0",
38
+ "@nu-art/firebase-frontend": "0.400.7",
39
+ "@nu-art/firebase-shared": "0.400.7",
40
+ "@nu-art/permissions-frontend": "0.400.7",
41
+ "@nu-art/permissions-shared": "0.400.7",
42
+ "@nu-art/push-pub-sub-frontend": "0.400.7",
43
+ "@nu-art/push-pub-sub-shared": "0.400.7",
44
+ "@nu-art/thunderstorm-frontend": "0.400.7",
45
+ "@nu-art/thunderstorm-shared": "0.400.7",
46
+ "@nu-art/ts-common": "0.400.7",
47
+ "@nu-art/ts-styles": "0.400.7",
48
+ "@nu-art/user-account-frontend": "0.400.7",
49
+ "@nu-art/user-account-shared": "0.400.7",
50
+ "express": "^4.18.2",
51
+ "file-type": "^21.0.0",
52
+ "firebase": "^11.9.0",
53
+ "firebase-admin": "13.4.0",
54
+ "firebase-functions": "6.3.2",
55
+ "google-auth-library": "^10.0.0",
56
+ "jszip": "^3.2.2",
57
+ "react": "^18.0.0"
58
+ },
59
+ "devDependencies": {
60
+ "@types/react": "^18.0.0",
61
+ "@types/compression": "^1.0.1",
62
+ "@types/express": "^4.17.17"
63
+ },
64
+ "unitConfig": {
65
+ "type": "typescript-lib"
66
+ },
67
+ "type": "module",
68
+ "exports": {
69
+ ".": {
70
+ "types": "./index.d.ts",
71
+ "import": "./index.js"
72
+ },
73
+ "./*": {
74
+ "types": "./*.d.ts",
75
+ "import": "./*.js"
76
+ }
77
+ }
78
+ }
package/shared.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from '@nu-art/file-upload-shared';
package/shared.js ADDED
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Permissions management system, define access level for each of
3
+ * your server apis, and restrict users by giving them access levels
4
+ *
5
+ * Copyright (C) 2020 Adam van der Kruk aka TacB0sS
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ export * from '@nu-art/file-upload-shared';