@webiny/api-file-manager 0.0.0-unstable.99666aeb00 → 0.0.0-unstable.a9593f74dd
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.
- package/FileManagerContextSetup.js +8 -6
- package/FileManagerContextSetup.js.map +1 -1
- package/cmsFileStorage/CmsFilesStorage.js +28 -25
- package/cmsFileStorage/CmsFilesStorage.js.map +1 -1
- package/cmsFileStorage/ListFilesWhereProcessor.js +8 -10
- package/cmsFileStorage/ListFilesWhereProcessor.js.map +1 -1
- package/cmsFileStorage/ListTagsWhereProcessor.js +8 -10
- package/cmsFileStorage/ListTagsWhereProcessor.js.map +1 -1
- package/cmsFileStorage/createFileManagerPlugins.d.ts +5 -3
- package/cmsFileStorage/createFileManagerPlugins.js +8 -25
- package/cmsFileStorage/createFileManagerPlugins.js.map +1 -1
- package/cmsFileStorage/createModelField.js +5 -1
- package/cmsFileStorage/createModelField.js.map +1 -1
- package/cmsFileStorage/file.model.d.ts +5 -3
- package/cmsFileStorage/file.model.js +64 -29
- package/cmsFileStorage/file.model.js.map +1 -1
- package/cmsFileStorage/isInstallationPending.js +3 -1
- package/cmsFileStorage/isInstallationPending.js.map +1 -1
- package/contants.js +3 -1
- package/contants.js.map +1 -1
- package/createFileManager/files.crud.js +83 -55
- package/createFileManager/files.crud.js.map +1 -1
- package/createFileManager/index.js +8 -5
- package/createFileManager/index.js.map +1 -1
- package/createFileManager/permissions/FilesPermissions.js +3 -1
- package/createFileManager/permissions/FilesPermissions.js.map +1 -1
- package/createFileManager/settings.crud.js +28 -12
- package/createFileManager/settings.crud.js.map +1 -1
- package/createFileManager/system.crud.js +6 -4
- package/createFileManager/system.crud.js.map +1 -1
- package/delivery/AssetDelivery/AliasAssetRequestResolver.d.ts +10 -0
- package/delivery/AssetDelivery/AliasAssetRequestResolver.js +74 -0
- package/delivery/AssetDelivery/AliasAssetRequestResolver.js.map +1 -0
- package/delivery/AssetDelivery/Asset.d.ts +30 -0
- package/delivery/AssetDelivery/Asset.js +64 -0
- package/delivery/AssetDelivery/Asset.js.map +1 -0
- package/delivery/AssetDelivery/AssetDeliveryConfig.d.ts +63 -0
- package/delivery/AssetDelivery/AssetDeliveryConfig.js +102 -0
- package/delivery/AssetDelivery/AssetDeliveryConfig.js.map +1 -0
- package/delivery/AssetDelivery/AssetRequest.d.ts +24 -0
- package/delivery/AssetDelivery/AssetRequest.js +29 -0
- package/delivery/AssetDelivery/AssetRequest.js.map +1 -0
- package/delivery/AssetDelivery/FilesAssetRequestResolver.d.ts +6 -0
- package/delivery/AssetDelivery/FilesAssetRequestResolver.js +33 -0
- package/delivery/AssetDelivery/FilesAssetRequestResolver.js.map +1 -0
- package/delivery/AssetDelivery/NullAssetOutputStrategy.d.ts +4 -0
- package/delivery/AssetDelivery/NullAssetOutputStrategy.js +15 -0
- package/delivery/AssetDelivery/NullAssetOutputStrategy.js.map +1 -0
- package/delivery/AssetDelivery/NullAssetReply.d.ts +4 -0
- package/delivery/AssetDelivery/NullAssetReply.js +20 -0
- package/delivery/AssetDelivery/NullAssetReply.js.map +1 -0
- package/delivery/AssetDelivery/NullAssetResolver.d.ts +5 -0
- package/delivery/AssetDelivery/NullAssetResolver.js +14 -0
- package/delivery/AssetDelivery/NullAssetResolver.js.map +1 -0
- package/delivery/AssetDelivery/NullRequestResolver.d.ts +4 -0
- package/delivery/AssetDelivery/NullRequestResolver.js +14 -0
- package/delivery/AssetDelivery/NullRequestResolver.js.map +1 -0
- package/delivery/AssetDelivery/SetCacheControlHeaders.d.ts +8 -0
- package/delivery/AssetDelivery/SetCacheControlHeaders.js +25 -0
- package/delivery/AssetDelivery/SetCacheControlHeaders.js.map +1 -0
- package/delivery/AssetDelivery/SetResponseHeaders.d.ts +18 -0
- package/delivery/AssetDelivery/SetResponseHeaders.js +25 -0
- package/delivery/AssetDelivery/SetResponseHeaders.js.map +1 -0
- package/delivery/AssetDelivery/abstractions/AssetContentsReader.d.ts +5 -0
- package/delivery/AssetDelivery/abstractions/AssetContentsReader.js +7 -0
- package/delivery/AssetDelivery/abstractions/AssetContentsReader.js.map +1 -0
- package/delivery/AssetDelivery/abstractions/AssetOutputStrategy.d.ts +4 -0
- package/delivery/AssetDelivery/abstractions/AssetOutputStrategy.js +7 -0
- package/delivery/AssetDelivery/abstractions/AssetOutputStrategy.js.map +1 -0
- package/delivery/AssetDelivery/abstractions/AssetProcessor.d.ts +4 -0
- package/delivery/AssetDelivery/abstractions/AssetProcessor.js +7 -0
- package/delivery/AssetDelivery/abstractions/AssetProcessor.js.map +1 -0
- package/delivery/AssetDelivery/abstractions/AssetReply.d.ts +25 -0
- package/delivery/AssetDelivery/abstractions/AssetReply.js +38 -0
- package/delivery/AssetDelivery/abstractions/AssetReply.js.map +1 -0
- package/delivery/AssetDelivery/abstractions/AssetRequestResolver.d.ts +5 -0
- package/delivery/AssetDelivery/abstractions/AssetRequestResolver.js +7 -0
- package/delivery/AssetDelivery/abstractions/AssetRequestResolver.js.map +1 -0
- package/delivery/AssetDelivery/abstractions/AssetResolver.d.ts +4 -0
- package/delivery/AssetDelivery/abstractions/AssetResolver.js +7 -0
- package/delivery/AssetDelivery/abstractions/AssetResolver.js.map +1 -0
- package/delivery/AssetDelivery/abstractions/AssetTransformationStrategy.d.ts +4 -0
- package/delivery/AssetDelivery/abstractions/AssetTransformationStrategy.js +7 -0
- package/delivery/AssetDelivery/abstractions/AssetTransformationStrategy.js.map +1 -0
- package/delivery/AssetDelivery/createAssetDeliveryPluginLoader.d.ts +2 -0
- package/delivery/AssetDelivery/createAssetDeliveryPluginLoader.js +15 -0
- package/delivery/AssetDelivery/createAssetDeliveryPluginLoader.js.map +1 -0
- package/delivery/AssetDelivery/privateFiles/AssetAuthorizer.d.ts +4 -0
- package/delivery/AssetDelivery/privateFiles/AssetAuthorizer.js +7 -0
- package/delivery/AssetDelivery/privateFiles/AssetAuthorizer.js.map +1 -0
- package/delivery/AssetDelivery/privateFiles/NotAuthorizedAssetReply.d.ts +4 -0
- package/delivery/AssetDelivery/privateFiles/NotAuthorizedAssetReply.js +26 -0
- package/delivery/AssetDelivery/privateFiles/NotAuthorizedAssetReply.js.map +1 -0
- package/delivery/AssetDelivery/privateFiles/NotAuthorizedOutputStrategy.d.ts +4 -0
- package/delivery/AssetDelivery/privateFiles/NotAuthorizedOutputStrategy.js +15 -0
- package/delivery/AssetDelivery/privateFiles/NotAuthorizedOutputStrategy.js.map +1 -0
- package/delivery/AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.d.ts +7 -0
- package/delivery/AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.js +28 -0
- package/delivery/AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.js.map +1 -0
- package/delivery/AssetDelivery/privateFiles/PrivateCache.d.ts +4 -0
- package/delivery/AssetDelivery/privateFiles/PrivateCache.js +18 -0
- package/delivery/AssetDelivery/privateFiles/PrivateCache.js.map +1 -0
- package/delivery/AssetDelivery/privateFiles/PrivateFileAssetRequestResolver.d.ts +7 -0
- package/delivery/AssetDelivery/privateFiles/PrivateFileAssetRequestResolver.js +37 -0
- package/delivery/AssetDelivery/privateFiles/PrivateFileAssetRequestResolver.js.map +1 -0
- package/delivery/AssetDelivery/privateFiles/PrivateFilesAssetProcessor.d.ts +13 -0
- package/delivery/AssetDelivery/privateFiles/PrivateFilesAssetProcessor.js +62 -0
- package/delivery/AssetDelivery/privateFiles/PrivateFilesAssetProcessor.js.map +1 -0
- package/delivery/AssetDelivery/privateFiles/PublicCache.d.ts +4 -0
- package/delivery/AssetDelivery/privateFiles/PublicCache.js +18 -0
- package/delivery/AssetDelivery/privateFiles/PublicCache.js.map +1 -0
- package/delivery/AssetDelivery/privateFiles/RedirectToPrivateUrlOutputStrategy.d.ts +6 -0
- package/delivery/AssetDelivery/privateFiles/RedirectToPrivateUrlOutputStrategy.js +27 -0
- package/delivery/AssetDelivery/privateFiles/RedirectToPrivateUrlOutputStrategy.js.map +1 -0
- package/delivery/AssetDelivery/privateFiles/RedirectToPublicUrlOutputStrategy.d.ts +6 -0
- package/delivery/AssetDelivery/privateFiles/RedirectToPublicUrlOutputStrategy.js +27 -0
- package/delivery/AssetDelivery/privateFiles/RedirectToPublicUrlOutputStrategy.js.map +1 -0
- package/delivery/AssetDelivery/privateFiles/internalIdentity.d.ts +7 -0
- package/delivery/AssetDelivery/privateFiles/internalIdentity.js +19 -0
- package/delivery/AssetDelivery/privateFiles/internalIdentity.js.map +1 -0
- package/delivery/AssetDelivery/transformation/PassthroughAssetProcessor.d.ts +4 -0
- package/delivery/AssetDelivery/transformation/PassthroughAssetProcessor.js +14 -0
- package/delivery/AssetDelivery/transformation/PassthroughAssetProcessor.js.map +1 -0
- package/delivery/AssetDelivery/transformation/PassthroughAssetTransformationStrategy.d.ts +4 -0
- package/delivery/AssetDelivery/transformation/PassthroughAssetTransformationStrategy.js +14 -0
- package/delivery/AssetDelivery/transformation/PassthroughAssetTransformationStrategy.js.map +1 -0
- package/delivery/AssetDelivery/transformation/TransformationAssetProcessor.d.ts +6 -0
- package/delivery/AssetDelivery/transformation/TransformationAssetProcessor.js +25 -0
- package/delivery/AssetDelivery/transformation/TransformationAssetProcessor.js.map +1 -0
- package/delivery/index.d.ts +15 -0
- package/delivery/index.js +172 -0
- package/delivery/index.js.map +1 -0
- package/delivery/setupAssetDelivery.d.ts +6 -0
- package/delivery/setupAssetDelivery.js +124 -0
- package/delivery/setupAssetDelivery.js.map +1 -0
- package/graphql/baseSchema.js +4 -1
- package/graphql/baseSchema.js.map +1 -1
- package/graphql/createFilesTypeDefs.js +29 -6
- package/graphql/createFilesTypeDefs.js.map +1 -1
- package/graphql/filesSchema.js +13 -5
- package/graphql/filesSchema.js.map +1 -1
- package/graphql/getFileByUrl.d.ts +3 -0
- package/graphql/getFileByUrl.js +78 -0
- package/graphql/getFileByUrl.js.map +1 -0
- package/graphql/index.d.ts +2 -1
- package/graphql/index.js +24 -2
- package/graphql/index.js.map +1 -1
- package/graphql/utils.js +3 -1
- package/graphql/utils.js.map +1 -1
- package/handlers/{transform/managers → manage}/imageManager.d.ts +2 -3
- package/handlers/{transform/managers → manage}/imageManager.js +11 -9
- package/handlers/manage/imageManager.js.map +1 -0
- package/handlers/manage/index.d.ts +1 -1
- package/handlers/manage/index.js +9 -5
- package/handlers/manage/index.js.map +1 -1
- package/handlers/{transform → manage}/legacyUtils.d.ts +0 -5
- package/handlers/{transform → manage}/legacyUtils.js +3 -7
- package/handlers/manage/legacyUtils.js.map +1 -0
- package/handlers/{transform → manage}/utils.js +3 -1
- package/handlers/manage/utils.js.map +1 -0
- package/handlers/types.d.ts +1 -1
- package/handlers/types.js +3 -1
- package/handlers/types.js.map +1 -1
- package/handlers/utils/getEnvironment.js +3 -1
- package/handlers/utils/getEnvironment.js.map +1 -1
- package/handlers/utils/getObjectParams.js +3 -1
- package/handlers/utils/getObjectParams.js.map +1 -1
- package/handlers/utils/index.js +3 -1
- package/handlers/utils/index.js.map +1 -1
- package/index.d.ts +4 -1
- package/index.js +27 -7
- package/index.js.map +1 -1
- package/modelModifier/CmsModelModifier.d.ts +3 -1
- package/modelModifier/CmsModelModifier.js +13 -10
- package/modelModifier/CmsModelModifier.js.map +1 -1
- package/package.json +26 -26
- package/plugins/FilePhysicalStoragePlugin.js +3 -3
- package/plugins/FilePhysicalStoragePlugin.js.map +1 -1
- package/plugins/FileStorageTransformPlugin.js +3 -4
- package/plugins/FileStorageTransformPlugin.js.map +1 -1
- package/plugins/index.js +3 -1
- package/plugins/index.js.map +1 -1
- package/storage/FileStorage.d.ts +2 -1
- package/storage/FileStorage.js +20 -16
- package/storage/FileStorage.js.map +1 -1
- package/types/file.d.ts +11 -0
- package/types/file.js +3 -1
- package/types/file.js.map +1 -1
- package/types/file.lifecycle.js +3 -1
- package/types.d.ts +22 -2
- package/types.js +3 -1
- package/types.js.map +1 -1
- package/createFileManager/filevalidation.disabled.d.ts +0 -0
- package/createFileManager/filevalidation.disabled.js +0 -55
- package/createFileManager/filevalidation.disabled.js.map +0 -1
- package/handlers/download/byAlias.d.ts +0 -6
- package/handlers/download/byAlias.js +0 -89
- package/handlers/download/byAlias.js.map +0 -1
- package/handlers/download/byExactKey.d.ts +0 -2
- package/handlers/download/byExactKey.js +0 -57
- package/handlers/download/byExactKey.js.map +0 -1
- package/handlers/download/extractFileInformation.d.ts +0 -9
- package/handlers/download/extractFileInformation.js +0 -20
- package/handlers/download/extractFileInformation.js.map +0 -1
- package/handlers/download/getS3Object.d.ts +0 -12
- package/handlers/download/getS3Object.js +0 -72
- package/handlers/download/getS3Object.js.map +0 -1
- package/handlers/download/index.d.ts +0 -2
- package/handlers/download/index.js +0 -27
- package/handlers/download/index.js.map +0 -1
- package/handlers/transform/index.d.ts +0 -2
- package/handlers/transform/index.js +0 -92
- package/handlers/transform/index.js.map +0 -1
- package/handlers/transform/legacyUtils.js.map +0 -1
- package/handlers/transform/loaders/imageLoader.d.ts +0 -30
- package/handlers/transform/loaders/imageLoader.js +0 -94
- package/handlers/transform/loaders/imageLoader.js.map +0 -1
- package/handlers/transform/loaders/index.d.ts +0 -8
- package/handlers/transform/loaders/index.js +0 -10
- package/handlers/transform/loaders/index.js.map +0 -1
- package/handlers/transform/loaders/sanitizeImageTransformations.d.ts +0 -11
- package/handlers/transform/loaders/sanitizeImageTransformations.js +0 -45
- package/handlers/transform/loaders/sanitizeImageTransformations.js.map +0 -1
- package/handlers/transform/managers/imageManager.js.map +0 -1
- package/handlers/transform/managers/index.d.ts +0 -5
- package/handlers/transform/managers/index.js +0 -10
- package/handlers/transform/managers/index.js.map +0 -1
- package/handlers/transform/optimizeImage.d.ts +0 -3
- package/handlers/transform/optimizeImage.js +0 -42
- package/handlers/transform/optimizeImage.js.map +0 -1
- package/handlers/transform/transformImage.d.ts +0 -13
- package/handlers/transform/transformImage.js +0 -28
- package/handlers/transform/transformImage.js.map +0 -1
- package/handlers/transform/utils.js.map +0 -1
- /package/handlers/{transform → manage}/utils.d.ts +0 -0
package/plugins/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./FilePhysicalStoragePlugin\";\nexport * from \"./FileStorageTransformPlugin\";\n"],"mappings":";;;;;AAAA;
|
|
1
|
+
{"version":3,"names":["_FilePhysicalStoragePlugin","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_FileStorageTransformPlugin"],"sources":["index.ts"],"sourcesContent":["export * from \"./FilePhysicalStoragePlugin\";\nexport * from \"./FileStorageTransformPlugin\";\n"],"mappings":";;;;;AAAA,IAAAA,0BAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,0BAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,0BAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,0BAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,2BAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,2BAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,2BAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,2BAAA,CAAAL,GAAA;IAAA;EAAA;AAAA"}
|
package/storage/FileStorage.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { FileManagerContext } from "../types";
|
|
3
|
+
import { FilePhysicalStoragePlugin } from "../plugins/FilePhysicalStoragePlugin";
|
|
3
4
|
export declare type Result = Record<string, any>;
|
|
4
5
|
export interface FileStorageUploadParams {
|
|
5
6
|
buffer: Buffer;
|
|
@@ -23,9 +24,9 @@ export interface FileStorageParams {
|
|
|
23
24
|
context: FileManagerContext;
|
|
24
25
|
}
|
|
25
26
|
export declare class FileStorage {
|
|
26
|
-
private readonly storagePlugin;
|
|
27
27
|
private readonly context;
|
|
28
28
|
constructor({ context }: FileStorageParams);
|
|
29
|
+
get storagePlugin(): FilePhysicalStoragePlugin<import("../plugins/FilePhysicalStoragePlugin").FilePhysicalStoragePluginUploadParams, import("../plugins/FilePhysicalStoragePlugin").FilePhysicalStoragePluginDeleteParams>;
|
|
29
30
|
upload(params: FileStorageUploadParams): Promise<Result>;
|
|
30
31
|
uploadFiles({ files }: FileStorageUploadMultipleParams): Promise<import("../types").File[]>;
|
|
31
32
|
delete(params: FileStorageDeleteParams): Promise<boolean>;
|
package/storage/FileStorage.js
CHANGED
|
@@ -5,22 +5,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.FileStorage = void 0;
|
|
8
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
8
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
9
|
const storagePluginType = "api-file-manager-storage";
|
|
12
10
|
class FileStorage {
|
|
13
11
|
constructor({
|
|
14
12
|
context
|
|
15
13
|
}) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
this.context = context;
|
|
15
|
+
}
|
|
16
|
+
get storagePlugin() {
|
|
17
|
+
const storagePlugin = this.context.plugins.byType(storagePluginType).pop();
|
|
19
18
|
if (!storagePlugin) {
|
|
20
19
|
throw new _error.default(`Missing plugin of type "${storagePluginType}".`, "STORAGE_PLUGIN_ERROR");
|
|
21
20
|
}
|
|
22
|
-
|
|
23
|
-
this.context = context;
|
|
21
|
+
return storagePlugin;
|
|
24
22
|
}
|
|
25
23
|
async upload(params) {
|
|
26
24
|
const settings = await this.context.fileManager.getSettings();
|
|
@@ -31,17 +29,19 @@ class FileStorage {
|
|
|
31
29
|
// Add file to cloud storage.
|
|
32
30
|
const {
|
|
33
31
|
file: fileData
|
|
34
|
-
} = await this.storagePlugin.upload(
|
|
32
|
+
} = await this.storagePlugin.upload({
|
|
33
|
+
...params,
|
|
35
34
|
settings
|
|
36
|
-
})
|
|
35
|
+
});
|
|
37
36
|
|
|
38
37
|
// Save file in DB.
|
|
39
|
-
return this.context.fileManager.createFile(
|
|
38
|
+
return this.context.fileManager.createFile({
|
|
39
|
+
...fileData,
|
|
40
40
|
meta: {
|
|
41
41
|
private: Boolean(params.hideInFileManager)
|
|
42
42
|
},
|
|
43
43
|
tags: Array.isArray(params.tags) ? params.tags : []
|
|
44
|
-
})
|
|
44
|
+
});
|
|
45
45
|
}
|
|
46
46
|
async uploadFiles({
|
|
47
47
|
files
|
|
@@ -54,15 +54,17 @@ class FileStorage {
|
|
|
54
54
|
// TODO: improve types of this.storagePlugin.
|
|
55
55
|
const {
|
|
56
56
|
file
|
|
57
|
-
} = await this.storagePlugin.upload(
|
|
57
|
+
} = await this.storagePlugin.upload({
|
|
58
|
+
...item,
|
|
58
59
|
settings
|
|
59
|
-
})
|
|
60
|
-
return
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
...file,
|
|
61
63
|
meta: {
|
|
62
64
|
private: Boolean(item.hideInFileManager)
|
|
63
65
|
},
|
|
64
66
|
tags: Array.isArray(item.tags) ? item.tags : []
|
|
65
|
-
}
|
|
67
|
+
};
|
|
66
68
|
}));
|
|
67
69
|
return this.context.fileManager.createFilesInBatch(filesData);
|
|
68
70
|
}
|
|
@@ -83,4 +85,6 @@ class FileStorage {
|
|
|
83
85
|
return await fileManager.deleteFile(id);
|
|
84
86
|
}
|
|
85
87
|
}
|
|
86
|
-
exports.FileStorage = FileStorage;
|
|
88
|
+
exports.FileStorage = FileStorage;
|
|
89
|
+
|
|
90
|
+
//# sourceMappingURL=FileStorage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["storagePluginType","FileStorage","constructor","context","storagePlugin","plugins","byType","pop","WebinyError","upload","params","settings","fileManager","getSettings","file","fileData","createFile","meta","private","Boolean","hideInFileManager","tags","Array","isArray","uploadFiles","files","filesData","Promise","all","map","item","createFilesInBatch","delete","id","key","deleteFile"],"sources":["FileStorage.ts"],"sourcesContent":["import { FileManagerContext } from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { FilePhysicalStoragePlugin } from \"~/plugins/FilePhysicalStoragePlugin\";\n\nexport type Result = Record<string, any>;\n\nconst storagePluginType = \"api-file-manager-storage\";\n\nexport interface FileStorageUploadParams {\n buffer: Buffer;\n hideInFileManager: boolean | string;\n size: number;\n name: string;\n type: string;\n id?: string;\n key?: string;\n tags?: string[];\n keyPrefix?: string;\n}\nexport interface FileStorageDeleteParams {\n id: string;\n key: string;\n}\n\nexport interface FileStorageUploadMultipleParams {\n files: FileStorageUploadParams[];\n}\n\nexport interface FileStorageParams {\n context: FileManagerContext;\n}\nexport class FileStorage {\n private readonly
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","storagePluginType","FileStorage","constructor","context","storagePlugin","plugins","byType","pop","WebinyError","upload","params","settings","fileManager","getSettings","file","fileData","createFile","meta","private","Boolean","hideInFileManager","tags","Array","isArray","uploadFiles","files","filesData","Promise","all","map","item","createFilesInBatch","delete","id","key","deleteFile","exports"],"sources":["FileStorage.ts"],"sourcesContent":["import { FileManagerContext } from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { FilePhysicalStoragePlugin } from \"~/plugins/FilePhysicalStoragePlugin\";\n\nexport type Result = Record<string, any>;\n\nconst storagePluginType = \"api-file-manager-storage\";\n\nexport interface FileStorageUploadParams {\n buffer: Buffer;\n hideInFileManager: boolean | string;\n size: number;\n name: string;\n type: string;\n id?: string;\n key?: string;\n tags?: string[];\n keyPrefix?: string;\n}\nexport interface FileStorageDeleteParams {\n id: string;\n key: string;\n}\n\nexport interface FileStorageUploadMultipleParams {\n files: FileStorageUploadParams[];\n}\n\nexport interface FileStorageParams {\n context: FileManagerContext;\n}\nexport class FileStorage {\n private readonly context: FileManagerContext;\n\n constructor({ context }: FileStorageParams) {\n this.context = context;\n }\n\n get storagePlugin() {\n const storagePlugin = this.context.plugins\n .byType<FilePhysicalStoragePlugin>(storagePluginType)\n .pop();\n\n if (!storagePlugin) {\n throw new WebinyError(\n `Missing plugin of type \"${storagePluginType}\".`,\n \"STORAGE_PLUGIN_ERROR\"\n );\n }\n\n return storagePlugin;\n }\n\n async upload(params: FileStorageUploadParams): Promise<Result> {\n const settings = await this.context.fileManager.getSettings();\n if (!settings) {\n throw new WebinyError(\"Missing File Manager Settings.\", \"FILE_MANAGER_ERROR\");\n }\n\n // Add file to cloud storage.\n const { file: fileData } = await this.storagePlugin.upload({\n ...params,\n settings\n });\n\n // Save file in DB.\n return this.context.fileManager.createFile({\n ...fileData,\n meta: {\n private: Boolean(params.hideInFileManager)\n },\n tags: Array.isArray(params.tags) ? params.tags : []\n });\n }\n\n async uploadFiles({ files }: FileStorageUploadMultipleParams) {\n const settings = await this.context.fileManager.getSettings();\n if (!settings) {\n throw new WebinyError(\"Missing File Manager Settings.\", \"FILE_MANAGER_ERROR\");\n }\n\n const filesData = await Promise.all(\n files.map(async item => {\n // TODO: improve types of this.storagePlugin.\n const { file } = await this.storagePlugin.upload({\n ...item,\n settings\n });\n\n return {\n ...file,\n meta: {\n private: Boolean(item.hideInFileManager)\n },\n tags: Array.isArray(item.tags) ? item.tags : []\n };\n })\n );\n\n return this.context.fileManager.createFilesInBatch(filesData);\n }\n\n async delete(params: FileStorageDeleteParams) {\n const { id, key } = params;\n const { fileManager } = this.context;\n // Delete file from cloud storage.\n await this.storagePlugin.delete({\n key\n });\n\n // Delete file from the DB.\n return await fileManager.deleteFile(id);\n }\n}\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,MAAMC,iBAAiB,GAAG,0BAA0B;AAyB7C,MAAMC,WAAW,CAAC;EAGrBC,WAAWA,CAAC;IAAEC;EAA2B,CAAC,EAAE;IACxC,IAAI,CAACA,OAAO,GAAGA,OAAO;EAC1B;EAEA,IAAIC,aAAaA,CAAA,EAAG;IAChB,MAAMA,aAAa,GAAG,IAAI,CAACD,OAAO,CAACE,OAAO,CACrCC,MAAM,CAA4BN,iBAAiB,CAAC,CACpDO,GAAG,CAAC,CAAC;IAEV,IAAI,CAACH,aAAa,EAAE;MAChB,MAAM,IAAII,cAAW,CAChB,2BAA0BR,iBAAkB,IAAG,EAChD,sBACJ,CAAC;IACL;IAEA,OAAOI,aAAa;EACxB;EAEA,MAAMK,MAAMA,CAACC,MAA+B,EAAmB;IAC3D,MAAMC,QAAQ,GAAG,MAAM,IAAI,CAACR,OAAO,CAACS,WAAW,CAACC,WAAW,CAAC,CAAC;IAC7D,IAAI,CAACF,QAAQ,EAAE;MACX,MAAM,IAAIH,cAAW,CAAC,gCAAgC,EAAE,oBAAoB,CAAC;IACjF;;IAEA;IACA,MAAM;MAAEM,IAAI,EAAEC;IAAS,CAAC,GAAG,MAAM,IAAI,CAACX,aAAa,CAACK,MAAM,CAAC;MACvD,GAAGC,MAAM;MACTC;IACJ,CAAC,CAAC;;IAEF;IACA,OAAO,IAAI,CAACR,OAAO,CAACS,WAAW,CAACI,UAAU,CAAC;MACvC,GAAGD,QAAQ;MACXE,IAAI,EAAE;QACFC,OAAO,EAAEC,OAAO,CAACT,MAAM,CAACU,iBAAiB;MAC7C,CAAC;MACDC,IAAI,EAAEC,KAAK,CAACC,OAAO,CAACb,MAAM,CAACW,IAAI,CAAC,GAAGX,MAAM,CAACW,IAAI,GAAG;IACrD,CAAC,CAAC;EACN;EAEA,MAAMG,WAAWA,CAAC;IAAEC;EAAuC,CAAC,EAAE;IAC1D,MAAMd,QAAQ,GAAG,MAAM,IAAI,CAACR,OAAO,CAACS,WAAW,CAACC,WAAW,CAAC,CAAC;IAC7D,IAAI,CAACF,QAAQ,EAAE;MACX,MAAM,IAAIH,cAAW,CAAC,gCAAgC,EAAE,oBAAoB,CAAC;IACjF;IAEA,MAAMkB,SAAS,GAAG,MAAMC,OAAO,CAACC,GAAG,CAC/BH,KAAK,CAACI,GAAG,CAAC,MAAMC,IAAI,IAAI;MACpB;MACA,MAAM;QAAEhB;MAAK,CAAC,GAAG,MAAM,IAAI,CAACV,aAAa,CAACK,MAAM,CAAC;QAC7C,GAAGqB,IAAI;QACPnB;MACJ,CAAC,CAAC;MAEF,OAAO;QACH,GAAGG,IAAI;QACPG,IAAI,EAAE;UACFC,OAAO,EAAEC,OAAO,CAACW,IAAI,CAACV,iBAAiB;QAC3C,CAAC;QACDC,IAAI,EAAEC,KAAK,CAACC,OAAO,CAACO,IAAI,CAACT,IAAI,CAAC,GAAGS,IAAI,CAACT,IAAI,GAAG;MACjD,CAAC;IACL,CAAC,CACL,CAAC;IAED,OAAO,IAAI,CAAClB,OAAO,CAACS,WAAW,CAACmB,kBAAkB,CAACL,SAAS,CAAC;EACjE;EAEA,MAAMM,MAAMA,CAACtB,MAA+B,EAAE;IAC1C,MAAM;MAAEuB,EAAE;MAAEC;IAAI,CAAC,GAAGxB,MAAM;IAC1B,MAAM;MAAEE;IAAY,CAAC,GAAG,IAAI,CAACT,OAAO;IACpC;IACA,MAAM,IAAI,CAACC,aAAa,CAAC4B,MAAM,CAAC;MAC5BE;IACJ,CAAC,CAAC;;IAEF;IACA,OAAO,MAAMtB,WAAW,CAACuB,UAAU,CAACF,EAAE,CAAC;EAC3C;AACJ;AAACG,OAAA,CAAAnC,WAAA,GAAAA,WAAA"}
|
package/types/file.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
declare type PublicAccess = {
|
|
2
|
+
type: "public";
|
|
3
|
+
};
|
|
4
|
+
declare type PrivateAuthenticatedAccess = {
|
|
5
|
+
type: "private-authenticated";
|
|
6
|
+
};
|
|
1
7
|
export interface File {
|
|
2
8
|
id: string;
|
|
3
9
|
key: string;
|
|
@@ -5,14 +11,18 @@ export interface File {
|
|
|
5
11
|
type: string;
|
|
6
12
|
name: string;
|
|
7
13
|
meta: Record<string, any>;
|
|
14
|
+
accessControl?: PublicAccess | PrivateAuthenticatedAccess;
|
|
8
15
|
location: {
|
|
9
16
|
folderId: string;
|
|
10
17
|
};
|
|
11
18
|
tags: string[];
|
|
12
19
|
aliases: string[];
|
|
13
20
|
createdOn: string;
|
|
21
|
+
modifiedOn: string | null;
|
|
14
22
|
savedOn: string;
|
|
15
23
|
createdBy: CreatedBy;
|
|
24
|
+
modifiedBy: CreatedBy | null;
|
|
25
|
+
savedBy: CreatedBy;
|
|
16
26
|
/**
|
|
17
27
|
* Added with new storage operations refactoring.
|
|
18
28
|
*/
|
|
@@ -35,3 +45,4 @@ export interface CreatedBy {
|
|
|
35
45
|
displayName: string | null;
|
|
36
46
|
type: string;
|
|
37
47
|
}
|
|
48
|
+
export {};
|
package/types/file.js
CHANGED
package/types/file.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["file.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"names":[],"sources":["file.ts"],"sourcesContent":["type PublicAccess = {\n type: \"public\";\n};\n\ntype PrivateAuthenticatedAccess = {\n type: \"private-authenticated\";\n};\n\nexport interface File {\n id: string;\n key: string;\n size: number;\n type: string;\n name: string;\n meta: Record<string, any>;\n accessControl?: PublicAccess | PrivateAuthenticatedAccess;\n location: {\n folderId: string;\n };\n tags: string[];\n aliases: string[];\n\n createdOn: string;\n modifiedOn: string | null;\n savedOn: string;\n createdBy: CreatedBy;\n modifiedBy: CreatedBy | null;\n savedBy: CreatedBy;\n\n /**\n * Added with new storage operations refactoring.\n */\n tenant: string;\n locale: string;\n webinyVersion: string;\n /**\n * User can add new fields to the File object, so we must allow it in the types.\n */\n\n [key: string]: any;\n}\n\nexport interface FileAlias {\n tenant: string;\n locale: string;\n fileId: string;\n alias: string;\n}\n\nexport interface CreatedBy {\n id: string;\n displayName: string | null;\n type: string;\n}\n"],"mappings":""}
|
package/types/file.lifecycle.js
CHANGED
package/types.d.ts
CHANGED
|
@@ -4,15 +4,17 @@ import { TenancyContext } from "@webiny/api-tenancy/types";
|
|
|
4
4
|
import { SecurityContext, SecurityPermission } from "@webiny/api-security/types";
|
|
5
5
|
import { Context } from "@webiny/api/types";
|
|
6
6
|
import { FileLifecycleEvents } from "./types/file.lifecycle";
|
|
7
|
-
import { File } from "./types/file";
|
|
7
|
+
import { CreatedBy, File } from "./types/file";
|
|
8
8
|
import { Topic } from "@webiny/pubsub/types";
|
|
9
9
|
import { CmsContext } from "@webiny/api-headless-cms/types";
|
|
10
|
+
import { Context as TasksContext } from "@webiny/tasks/types";
|
|
10
11
|
export * from "./types/file.lifecycle";
|
|
11
12
|
export * from "./types/file";
|
|
13
|
+
export * from "./types/file";
|
|
12
14
|
export interface FileManagerContextObject extends FilesCRUD, SettingsCRUD, SystemCRUD {
|
|
13
15
|
storage: FileStorage;
|
|
14
16
|
}
|
|
15
|
-
export interface FileManagerContext extends Context, SecurityContext, TenancyContext, I18NContext, CmsContext {
|
|
17
|
+
export interface FileManagerContext extends Context, SecurityContext, TenancyContext, I18NContext, CmsContext, TasksContext {
|
|
16
18
|
fileManager: FileManagerContextObject;
|
|
17
19
|
}
|
|
18
20
|
export interface FilePermission extends SecurityPermission {
|
|
@@ -22,6 +24,12 @@ export interface FilePermission extends SecurityPermission {
|
|
|
22
24
|
}
|
|
23
25
|
export interface FileInput {
|
|
24
26
|
id: string;
|
|
27
|
+
createdOn?: string | Date | null;
|
|
28
|
+
modifiedOn?: string | Date | null;
|
|
29
|
+
savedOn?: string | Date | null;
|
|
30
|
+
createdBy?: CreatedBy | null;
|
|
31
|
+
modifiedBy?: CreatedBy | null;
|
|
32
|
+
savedBy?: CreatedBy | null;
|
|
25
33
|
key: string;
|
|
26
34
|
name: string;
|
|
27
35
|
size: number;
|
|
@@ -96,11 +104,23 @@ export interface FileManagerSystem {
|
|
|
96
104
|
version: string;
|
|
97
105
|
tenant: string;
|
|
98
106
|
}
|
|
107
|
+
export interface OnSettingsBeforeUpdateTopicParams {
|
|
108
|
+
input: Partial<FileManagerSettings>;
|
|
109
|
+
original: FileManagerSettings;
|
|
110
|
+
settings: FileManagerSettings;
|
|
111
|
+
}
|
|
112
|
+
export interface OnSettingsAfterUpdateTopicParams {
|
|
113
|
+
input: Partial<FileManagerSettings>;
|
|
114
|
+
original: FileManagerSettings;
|
|
115
|
+
settings: FileManagerSettings;
|
|
116
|
+
}
|
|
99
117
|
export declare type SettingsCRUD = {
|
|
100
118
|
getSettings(): Promise<FileManagerSettings | null>;
|
|
101
119
|
createSettings(data?: Partial<FileManagerSettings>): Promise<FileManagerSettings>;
|
|
102
120
|
updateSettings(data: Partial<FileManagerSettings>): Promise<FileManagerSettings>;
|
|
103
121
|
deleteSettings(): Promise<boolean>;
|
|
122
|
+
onSettingsBeforeUpdate: Topic<OnSettingsBeforeUpdateTopicParams>;
|
|
123
|
+
onSettingsAfterUpdate: Topic<OnSettingsAfterUpdateTopicParams>;
|
|
104
124
|
};
|
|
105
125
|
/********
|
|
106
126
|
* Storage operations
|
package/types.js
CHANGED
package/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { I18NContext } from \"@webiny/api-i18n/types\";\nimport { FileStorage } from \"./storage/FileStorage\";\nimport { TenancyContext } from \"@webiny/api-tenancy/types\";\nimport { SecurityContext, SecurityPermission } from \"@webiny/api-security/types\";\nimport { Context } from \"@webiny/api/types\";\nimport { FileLifecycleEvents } from \"./types/file.lifecycle\";\nimport { File } from \"./types/file\";\nimport { Topic } from \"@webiny/pubsub/types\";\nimport { CmsContext } from \"@webiny/api-headless-cms/types\";\nexport * from \"./types/file.lifecycle\";\nexport * from \"./types/file\";\n\nexport interface FileManagerContextObject extends FilesCRUD, SettingsCRUD, SystemCRUD {\n storage: FileStorage;\n}\n\nexport interface FileManagerContext\n extends Context,\n SecurityContext,\n TenancyContext,\n I18NContext,\n CmsContext {\n fileManager: FileManagerContextObject;\n}\n\nexport interface FilePermission extends SecurityPermission {\n name: \"fm.file\";\n rwd?: string;\n own?: boolean;\n}\n\nexport interface FileInput {\n id: string;\n key: string;\n name: string;\n size: number;\n type: string;\n meta: Record<string, any>;\n location?: {\n folderId: string;\n };\n tags: string[];\n aliases: string[];\n extensions?: Record<string, any>;\n}\n\nexport interface FileListWhereParams {\n AND?: FileListWhereParams[];\n OR?: FileListWhereParams[];\n [key: string]: any;\n}\nexport interface FilesListOpts {\n search?: string;\n limit?: number;\n after?: string;\n where?: FileListWhereParams;\n sort?: string[];\n}\n\nexport interface FileListMeta {\n cursor: string | null;\n totalCount: number;\n hasMoreItems: boolean;\n}\n\ninterface FilesCrudListTagsWhere {\n tag?: string;\n tag_contains?: string;\n tag_in?: string[];\n tag_not_startsWith?: string;\n tag_startsWith?: string;\n}\ninterface FilesCrudListTagsParams {\n where?: FilesCrudListTagsWhere;\n limit?: number;\n after?: string;\n}\n\nexport interface ListTagsResponse {\n tag: string;\n count: number;\n}\nexport interface FilesCRUD extends FileLifecycleEvents {\n getFile(id: string): Promise<File>;\n listFiles(opts?: FilesListOpts): Promise<[File[], FileListMeta]>;\n listTags(params: FilesCrudListTagsParams): Promise<ListTagsResponse[]>;\n createFile(data: FileInput, meta?: Record<string, any>): Promise<File>;\n updateFile(id: string, data: Partial<FileInput>): Promise<File>;\n deleteFile(id: string): Promise<boolean>;\n createFilesInBatch(data: FileInput[], meta?: Record<string, any>): Promise<File[]>;\n}\n\nexport interface SystemCRUD {\n onSystemBeforeInstall: Topic;\n onSystemAfterInstall: Topic;\n getVersion(): Promise<string | null>;\n setVersion(version: string): Promise<void>;\n install(args: { srcPrefix: string }): Promise<boolean>;\n}\n\nexport interface FileManagerSettings {\n tenant: string;\n key: string;\n uploadMinFileSize: number;\n uploadMaxFileSize: number;\n srcPrefix: string;\n}\n\nexport interface FileManagerSystem {\n version: string;\n tenant: string;\n}\n\nexport type SettingsCRUD = {\n getSettings(): Promise<FileManagerSettings | null>;\n createSettings(data?: Partial<FileManagerSettings>): Promise<FileManagerSettings>;\n updateSettings(data: Partial<FileManagerSettings>): Promise<FileManagerSettings>;\n deleteSettings(): Promise<boolean>;\n};\n/********\n * Storage operations\n *******/\n\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n * @category SystemStorageOperationsParams\n */\nexport interface FileManagerSystemStorageOperationsUpdateParams {\n /**\n * The system data to be updated.\n */\n original: FileManagerSystem;\n /**\n * The system data with the updated fields.\n */\n data: FileManagerSystem;\n}\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n * @category SystemStorageOperationsParams\n */\nexport interface FileManagerSystemStorageOperationsCreateParams {\n /**\n * The system fields.\n */\n data: FileManagerSystem;\n}\n\nexport interface FileManagerSystemStorageOperationsGetParams {\n tenant: string;\n}\n\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n */\nexport interface FileManagerSystemStorageOperations {\n /**\n * Get the FileManager system data.\n */\n get: (params: FileManagerSystemStorageOperationsGetParams) => Promise<FileManagerSystem | null>;\n /**\n * Update the FileManager system data..\n */\n update: (params: FileManagerSystemStorageOperationsUpdateParams) => Promise<FileManagerSystem>;\n /**\n * Create the FileManagerSystemData\n */\n create: (params: FileManagerSystemStorageOperationsCreateParams) => Promise<FileManagerSystem>;\n}\n\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n * @category SettingsStorageOperationsParams\n */\nexport interface FileManagerSettingsStorageOperationsUpdateParams {\n /**\n * Original settings to be updated.\n */\n original: FileManagerSettings;\n /**\n * The settings with the updated fields.\n */\n data: FileManagerSettings;\n}\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n * @category SettingsStorageOperationsParams\n */\nexport interface FileManagerSettingsStorageOperationsCreateParams {\n /**\n * The settings fields.\n */\n data: FileManagerSettings;\n}\n\nexport interface FileManagerStorageOperationsGetSettingsParams {\n tenant: string;\n}\n\nexport interface FileManagerStorageOperationsDeleteSettings {\n tenant: string;\n}\n\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n */\nexport interface FileManagerSettingsStorageOperations {\n /**\n * Get the FileManager system data.\n */\n get: (\n params: FileManagerStorageOperationsGetSettingsParams\n ) => Promise<FileManagerSettings | null>;\n /**\n * Create the FileManagerSettingsData\n */\n create: (\n params: FileManagerSettingsStorageOperationsCreateParams\n ) => Promise<FileManagerSettings>;\n /**\n * Update the FileManager system data..\n */\n update: (\n params: FileManagerSettingsStorageOperationsUpdateParams\n ) => Promise<FileManagerSettings>;\n /**\n * Delete the existing settings.\n */\n delete: (params: FileManagerStorageOperationsDeleteSettings) => Promise<void>;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsGetParams {\n where: {\n id: string;\n tenant: string;\n locale: string;\n };\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsCreateParams {\n file: File;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsUpdateParams {\n original: File;\n file: File;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsDeleteParams {\n file: File;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsCreateBatchParams {\n files: File[];\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListParamsWhere {\n [key: string]: any;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListParams {\n where: FileManagerFilesStorageOperationsListParamsWhere;\n sort: string[];\n limit: number;\n after: string | null;\n search?: string;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListResponseMeta {\n hasMoreItems: boolean;\n totalCount: number;\n cursor: string | null;\n}\nexport type FileManagerFilesStorageOperationsListResponse = [\n File[],\n FileManagerFilesStorageOperationsListResponseMeta\n];\n\nexport interface FileManagerFilesStorageOperationsTagsResponse {\n tag: string;\n count: number;\n}\n\nexport interface FileManagerFilesStorageOperationsTagsParamsWhere extends FilesCrudListTagsWhere {\n locale: string;\n tenant: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsTagsParams {\n where: FileManagerFilesStorageOperationsTagsParamsWhere;\n limit: number;\n after?: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n */\nexport interface FileManagerFilesStorageOperations {\n /**\n * Get a single file with given ID from the storage.\n */\n get: (params: FileManagerFilesStorageOperationsGetParams) => Promise<File | null>;\n /**\n * Insert the file data into the database.\n */\n create: (params: FileManagerFilesStorageOperationsCreateParams) => Promise<File>;\n /**\n * Update the file data in the database.\n */\n update: (params: FileManagerFilesStorageOperationsUpdateParams) => Promise<File>;\n /**\n * Delete the file from the database.\n */\n delete: (params: FileManagerFilesStorageOperationsDeleteParams) => Promise<void>;\n /**\n * Store multiple files at once to the database.\n */\n createBatch: (params: FileManagerFilesStorageOperationsCreateBatchParams) => Promise<File[]>;\n /**\n * Get a list of files filtered by given parameters.\n */\n list: (\n params: FileManagerFilesStorageOperationsListParams\n ) => Promise<FileManagerFilesStorageOperationsListResponse>;\n /**\n * Get a list of all file tags filtered by given parameters.\n */\n tags: (\n params: FileManagerFilesStorageOperationsTagsParams\n ) => Promise<FileManagerFilesStorageOperationsTagsResponse[]>;\n}\n\nexport interface FileManagerAliasesStorageOperations {\n storeAliases(file: File): Promise<void>;\n deleteAliases(file: File): Promise<void>;\n}\n\nexport interface FileManagerStorageOperations<TContext = FileManagerContext> {\n beforeInit?: (context: TContext) => Promise<void>;\n files: FileManagerFilesStorageOperations;\n aliases: FileManagerAliasesStorageOperations;\n settings: FileManagerSettingsStorageOperations;\n system: FileManagerSystemStorageOperations;\n}\n"],"mappings":";;;;;AASA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
|
1
|
+
{"version":3,"names":["_file","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_file2"],"sources":["types.ts"],"sourcesContent":["import { I18NContext } from \"@webiny/api-i18n/types\";\nimport { FileStorage } from \"./storage/FileStorage\";\nimport { TenancyContext } from \"@webiny/api-tenancy/types\";\nimport { SecurityContext, SecurityPermission } from \"@webiny/api-security/types\";\nimport { Context } from \"@webiny/api/types\";\nimport { FileLifecycleEvents } from \"./types/file.lifecycle\";\nimport { CreatedBy, File } from \"./types/file\";\nimport { Topic } from \"@webiny/pubsub/types\";\nimport { CmsContext } from \"@webiny/api-headless-cms/types\";\nimport { Context as TasksContext } from \"@webiny/tasks/types\";\n\nexport * from \"./types/file.lifecycle\";\nexport * from \"./types/file\";\nexport * from \"./types/file\";\n\nexport interface FileManagerContextObject extends FilesCRUD, SettingsCRUD, SystemCRUD {\n storage: FileStorage;\n}\n\nexport interface FileManagerContext\n extends Context,\n SecurityContext,\n TenancyContext,\n I18NContext,\n CmsContext,\n TasksContext {\n fileManager: FileManagerContextObject;\n}\n\nexport interface FilePermission extends SecurityPermission {\n name: \"fm.file\";\n rwd?: string;\n own?: boolean;\n}\n\nexport interface FileInput {\n id: string;\n\n // In the background, we're actually mapping these to entry-level fields.\n // This is fine since we don't use revisions for files.\n createdOn?: string | Date | null;\n modifiedOn?: string | Date | null;\n savedOn?: string | Date | null;\n createdBy?: CreatedBy | null;\n modifiedBy?: CreatedBy | null;\n savedBy?: CreatedBy | null;\n\n key: string;\n name: string;\n size: number;\n type: string;\n meta: Record<string, any>;\n location?: {\n folderId: string;\n };\n tags: string[];\n aliases: string[];\n extensions?: Record<string, any>;\n}\n\nexport interface FileListWhereParams {\n AND?: FileListWhereParams[];\n OR?: FileListWhereParams[];\n [key: string]: any;\n}\nexport interface FilesListOpts {\n search?: string;\n limit?: number;\n after?: string;\n where?: FileListWhereParams;\n sort?: string[];\n}\n\nexport interface FileListMeta {\n cursor: string | null;\n totalCount: number;\n hasMoreItems: boolean;\n}\n\ninterface FilesCrudListTagsWhere {\n tag?: string;\n tag_contains?: string;\n tag_in?: string[];\n tag_not_startsWith?: string;\n tag_startsWith?: string;\n}\ninterface FilesCrudListTagsParams {\n where?: FilesCrudListTagsWhere;\n limit?: number;\n after?: string;\n}\n\nexport interface ListTagsResponse {\n tag: string;\n count: number;\n}\nexport interface FilesCRUD extends FileLifecycleEvents {\n getFile(id: string): Promise<File>;\n listFiles(opts?: FilesListOpts): Promise<[File[], FileListMeta]>;\n listTags(params: FilesCrudListTagsParams): Promise<ListTagsResponse[]>;\n createFile(data: FileInput, meta?: Record<string, any>): Promise<File>;\n updateFile(id: string, data: Partial<FileInput>): Promise<File>;\n deleteFile(id: string): Promise<boolean>;\n createFilesInBatch(data: FileInput[], meta?: Record<string, any>): Promise<File[]>;\n}\n\nexport interface SystemCRUD {\n onSystemBeforeInstall: Topic;\n onSystemAfterInstall: Topic;\n getVersion(): Promise<string | null>;\n setVersion(version: string): Promise<void>;\n install(args: { srcPrefix: string }): Promise<boolean>;\n}\n\nexport interface FileManagerSettings {\n tenant: string;\n key: string;\n uploadMinFileSize: number;\n uploadMaxFileSize: number;\n srcPrefix: string;\n}\n\nexport interface FileManagerSystem {\n version: string;\n tenant: string;\n}\n\nexport interface OnSettingsBeforeUpdateTopicParams {\n input: Partial<FileManagerSettings>;\n original: FileManagerSettings;\n settings: FileManagerSettings;\n}\n\nexport interface OnSettingsAfterUpdateTopicParams {\n input: Partial<FileManagerSettings>;\n original: FileManagerSettings;\n settings: FileManagerSettings;\n}\n\nexport type SettingsCRUD = {\n getSettings(): Promise<FileManagerSettings | null>;\n createSettings(data?: Partial<FileManagerSettings>): Promise<FileManagerSettings>;\n updateSettings(data: Partial<FileManagerSettings>): Promise<FileManagerSettings>;\n deleteSettings(): Promise<boolean>;\n\n onSettingsBeforeUpdate: Topic<OnSettingsBeforeUpdateTopicParams>;\n onSettingsAfterUpdate: Topic<OnSettingsAfterUpdateTopicParams>;\n};\n/********\n * Storage operations\n *******/\n\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n * @category SystemStorageOperationsParams\n */\nexport interface FileManagerSystemStorageOperationsUpdateParams {\n /**\n * The system data to be updated.\n */\n original: FileManagerSystem;\n /**\n * The system data with the updated fields.\n */\n data: FileManagerSystem;\n}\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n * @category SystemStorageOperationsParams\n */\nexport interface FileManagerSystemStorageOperationsCreateParams {\n /**\n * The system fields.\n */\n data: FileManagerSystem;\n}\n\nexport interface FileManagerSystemStorageOperationsGetParams {\n tenant: string;\n}\n\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n */\nexport interface FileManagerSystemStorageOperations {\n /**\n * Get the FileManager system data.\n */\n get: (params: FileManagerSystemStorageOperationsGetParams) => Promise<FileManagerSystem | null>;\n /**\n * Update the FileManager system data..\n */\n update: (params: FileManagerSystemStorageOperationsUpdateParams) => Promise<FileManagerSystem>;\n /**\n * Create the FileManagerSystemData\n */\n create: (params: FileManagerSystemStorageOperationsCreateParams) => Promise<FileManagerSystem>;\n}\n\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n * @category SettingsStorageOperationsParams\n */\nexport interface FileManagerSettingsStorageOperationsUpdateParams {\n /**\n * Original settings to be updated.\n */\n original: FileManagerSettings;\n /**\n * The settings with the updated fields.\n */\n data: FileManagerSettings;\n}\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n * @category SettingsStorageOperationsParams\n */\nexport interface FileManagerSettingsStorageOperationsCreateParams {\n /**\n * The settings fields.\n */\n data: FileManagerSettings;\n}\n\nexport interface FileManagerStorageOperationsGetSettingsParams {\n tenant: string;\n}\n\nexport interface FileManagerStorageOperationsDeleteSettings {\n tenant: string;\n}\n\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n */\nexport interface FileManagerSettingsStorageOperations {\n /**\n * Get the FileManager system data.\n */\n get: (\n params: FileManagerStorageOperationsGetSettingsParams\n ) => Promise<FileManagerSettings | null>;\n /**\n * Create the FileManagerSettingsData\n */\n create: (\n params: FileManagerSettingsStorageOperationsCreateParams\n ) => Promise<FileManagerSettings>;\n /**\n * Update the FileManager system data..\n */\n update: (\n params: FileManagerSettingsStorageOperationsUpdateParams\n ) => Promise<FileManagerSettings>;\n /**\n * Delete the existing settings.\n */\n delete: (params: FileManagerStorageOperationsDeleteSettings) => Promise<void>;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsGetParams {\n where: {\n id: string;\n tenant: string;\n locale: string;\n };\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsCreateParams {\n file: File;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsUpdateParams {\n original: File;\n file: File;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsDeleteParams {\n file: File;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsCreateBatchParams {\n files: File[];\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListParamsWhere {\n [key: string]: any;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListParams {\n where: FileManagerFilesStorageOperationsListParamsWhere;\n sort: string[];\n limit: number;\n after: string | null;\n search?: string;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListResponseMeta {\n hasMoreItems: boolean;\n totalCount: number;\n cursor: string | null;\n}\nexport type FileManagerFilesStorageOperationsListResponse = [\n File[],\n FileManagerFilesStorageOperationsListResponseMeta\n];\n\nexport interface FileManagerFilesStorageOperationsTagsResponse {\n tag: string;\n count: number;\n}\n\nexport interface FileManagerFilesStorageOperationsTagsParamsWhere extends FilesCrudListTagsWhere {\n locale: string;\n tenant: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsTagsParams {\n where: FileManagerFilesStorageOperationsTagsParamsWhere;\n limit: number;\n after?: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n */\nexport interface FileManagerFilesStorageOperations {\n /**\n * Get a single file with given ID from the storage.\n */\n get: (params: FileManagerFilesStorageOperationsGetParams) => Promise<File | null>;\n /**\n * Insert the file data into the database.\n */\n create: (params: FileManagerFilesStorageOperationsCreateParams) => Promise<File>;\n /**\n * Update the file data in the database.\n */\n update: (params: FileManagerFilesStorageOperationsUpdateParams) => Promise<File>;\n /**\n * Delete the file from the database.\n */\n delete: (params: FileManagerFilesStorageOperationsDeleteParams) => Promise<void>;\n /**\n * Store multiple files at once to the database.\n */\n createBatch: (params: FileManagerFilesStorageOperationsCreateBatchParams) => Promise<File[]>;\n /**\n * Get a list of files filtered by given parameters.\n */\n list: (\n params: FileManagerFilesStorageOperationsListParams\n ) => Promise<FileManagerFilesStorageOperationsListResponse>;\n /**\n * Get a list of all file tags filtered by given parameters.\n */\n tags: (\n params: FileManagerFilesStorageOperationsTagsParams\n ) => Promise<FileManagerFilesStorageOperationsTagsResponse[]>;\n}\n\nexport interface FileManagerAliasesStorageOperations {\n storeAliases(file: File): Promise<void>;\n deleteAliases(file: File): Promise<void>;\n}\n\nexport interface FileManagerStorageOperations<TContext = FileManagerContext> {\n beforeInit?: (context: TContext) => Promise<void>;\n files: FileManagerFilesStorageOperations;\n aliases: FileManagerAliasesStorageOperations;\n settings: FileManagerSettingsStorageOperations;\n system: FileManagerSystemStorageOperations;\n}\n"],"mappings":";;;;;AAWA,IAAAA,KAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,KAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,KAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,KAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,MAAA,GAAAT,OAAA;AACAC,MAAA,CAAAC,IAAA,CAAAO,MAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,MAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,MAAA,CAAAL,GAAA;IAAA;EAAA;AAAA"}
|
|
File without changes
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
// /**
|
|
2
|
-
// * Package @commodo/fields does not have types
|
|
3
|
-
// */
|
|
4
|
-
// // @ts-ignore
|
|
5
|
-
// import { withFields, string, number, onSet } from "@commodo/fields";
|
|
6
|
-
// /**
|
|
7
|
-
// * Package commodo-fields-object does not have types
|
|
8
|
-
// */
|
|
9
|
-
// // @ts-ignore
|
|
10
|
-
// import { object } from "commodo-fields-object";
|
|
11
|
-
// import { validation } from "@webiny/validation";
|
|
12
|
-
//
|
|
13
|
-
// export default (create = true) => {
|
|
14
|
-
// return withFields({
|
|
15
|
-
// key: string({
|
|
16
|
-
// validation: validation.create(`${create ? "required," : ""}maxLength:1000`)
|
|
17
|
-
// }),
|
|
18
|
-
// name: string({ validation: validation.create("maxLength:1000") }),
|
|
19
|
-
// size: number(),
|
|
20
|
-
// type: string({ validation: validation.create("maxLength:255") }),
|
|
21
|
-
// meta: object({ value: { private: false } }),
|
|
22
|
-
// tags: onSet((value: string[]) => {
|
|
23
|
-
// if (!Array.isArray(value)) {
|
|
24
|
-
// return null;
|
|
25
|
-
// }
|
|
26
|
-
//
|
|
27
|
-
// return value.map(item => item.toLowerCase());
|
|
28
|
-
// })(
|
|
29
|
-
// string({
|
|
30
|
-
// list: true,
|
|
31
|
-
// validation: (tags: string[]) => {
|
|
32
|
-
// if (!Array.isArray(tags)) {
|
|
33
|
-
// return;
|
|
34
|
-
// }
|
|
35
|
-
//
|
|
36
|
-
// if (tags.length > 15) {
|
|
37
|
-
// throw Error("You cannot set more than 15 tags.");
|
|
38
|
-
// }
|
|
39
|
-
//
|
|
40
|
-
// for (let i = 0; i < tags.length; i++) {
|
|
41
|
-
// const tag = tags[i];
|
|
42
|
-
// if (typeof tag !== "string") {
|
|
43
|
-
// throw Error("Tag must be typeof string.");
|
|
44
|
-
// }
|
|
45
|
-
//
|
|
46
|
-
// if (tag.length > 50) {
|
|
47
|
-
// throw Error(`Tag ${tag} is more than 50 characters long.`);
|
|
48
|
-
// }
|
|
49
|
-
// }
|
|
50
|
-
// }
|
|
51
|
-
// })
|
|
52
|
-
// )
|
|
53
|
-
// })();
|
|
54
|
-
// };
|
|
55
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["filevalidation.disabled.ts"],"sourcesContent":["// /**\n// * Package @commodo/fields does not have types\n// */\n// // @ts-ignore\n// import { withFields, string, number, onSet } from \"@commodo/fields\";\n// /**\n// * Package commodo-fields-object does not have types\n// */\n// // @ts-ignore\n// import { object } from \"commodo-fields-object\";\n// import { validation } from \"@webiny/validation\";\n//\n// export default (create = true) => {\n// return withFields({\n// key: string({\n// validation: validation.create(`${create ? \"required,\" : \"\"}maxLength:1000`)\n// }),\n// name: string({ validation: validation.create(\"maxLength:1000\") }),\n// size: number(),\n// type: string({ validation: validation.create(\"maxLength:255\") }),\n// meta: object({ value: { private: false } }),\n// tags: onSet((value: string[]) => {\n// if (!Array.isArray(value)) {\n// return null;\n// }\n//\n// return value.map(item => item.toLowerCase());\n// })(\n// string({\n// list: true,\n// validation: (tags: string[]) => {\n// if (!Array.isArray(tags)) {\n// return;\n// }\n//\n// if (tags.length > 15) {\n// throw Error(\"You cannot set more than 15 tags.\");\n// }\n//\n// for (let i = 0; i < tags.length; i++) {\n// const tag = tags[i];\n// if (typeof tag !== \"string\") {\n// throw Error(\"Tag must be typeof string.\");\n// }\n//\n// if (tag.length > 50) {\n// throw Error(`Tag ${tag} is more than 50 characters long.`);\n// }\n// }\n// }\n// })\n// )\n// })();\n// };\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { DocumentClient } from "aws-sdk/clients/dynamodb";
|
|
2
|
-
import { RoutePlugin } from "@webiny/handler-aws/gateway";
|
|
3
|
-
export interface DownloadByFileAliasConfig {
|
|
4
|
-
documentClient: DocumentClient;
|
|
5
|
-
}
|
|
6
|
-
export declare const createDownloadFileByAliasPlugins: ({ documentClient }: DownloadByFileAliasConfig) => RoutePlugin<import("@webiny/handler/types").Context>[];
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.createDownloadFileByAliasPlugins = void 0;
|
|
8
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
-
var _s = _interopRequireDefault(require("aws-sdk/clients/s3"));
|
|
10
|
-
var _utils = require("../utils");
|
|
11
|
-
var _gateway = require("@webiny/handler-aws/gateway");
|
|
12
|
-
var _extractFileInformation = require("./extractFileInformation");
|
|
13
|
-
var _getS3Object = require("./getS3Object");
|
|
14
|
-
const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
|
|
15
|
-
const PRESIGNED_URL_EXPIRATION = 900; // 15 minutes
|
|
16
|
-
|
|
17
|
-
const {
|
|
18
|
-
region
|
|
19
|
-
} = (0, _utils.getEnvironment)();
|
|
20
|
-
const s3 = new _s.default({
|
|
21
|
-
region
|
|
22
|
-
});
|
|
23
|
-
const createDownloadFileByAliasPlugins = ({
|
|
24
|
-
documentClient
|
|
25
|
-
}) => {
|
|
26
|
-
async function getFileByAlias(tenant, alias) {
|
|
27
|
-
const {
|
|
28
|
-
Items,
|
|
29
|
-
Count
|
|
30
|
-
} = await documentClient.query({
|
|
31
|
-
TableName: String(process.env.DB_TABLE),
|
|
32
|
-
IndexName: "GSI1",
|
|
33
|
-
Limit: 1,
|
|
34
|
-
KeyConditionExpression: "GSI1_PK = :GSI1_PK AND GSI1_SK = :GSI1_SK",
|
|
35
|
-
ExpressionAttributeValues: {
|
|
36
|
-
":GSI1_PK": `T#${tenant}#FM#FILE_ALIASES`,
|
|
37
|
-
":GSI1_SK": `/${alias}`
|
|
38
|
-
}
|
|
39
|
-
}).promise();
|
|
40
|
-
if (!Items || Count === 0) {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
return Items[0].data.key ?? null;
|
|
44
|
-
}
|
|
45
|
-
return [new _gateway.RoutePlugin(({
|
|
46
|
-
onGet,
|
|
47
|
-
context
|
|
48
|
-
}) => {
|
|
49
|
-
onGet("/*", async (request, reply) => {
|
|
50
|
-
const fileInfo = (0, _extractFileInformation.extractFileInformation)(request);
|
|
51
|
-
|
|
52
|
-
// TODO: `root` tenant is hardcoded for now, to satisfy the basic use case.
|
|
53
|
-
// We need to find a way to send tenant via `x-tenant` header, when images are being requested from
|
|
54
|
-
// the frontend (website, admin, etc.) by alias.
|
|
55
|
-
const realFilename = await getFileByAlias("root", fileInfo.filename);
|
|
56
|
-
if (!realFilename) {
|
|
57
|
-
return reply.code(404).type("text/html").send("Not Found");
|
|
58
|
-
}
|
|
59
|
-
const {
|
|
60
|
-
params,
|
|
61
|
-
object
|
|
62
|
-
} = await (0, _getS3Object.getS3Object)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, fileInfo), {}, {
|
|
63
|
-
filename: realFilename
|
|
64
|
-
}), s3, context);
|
|
65
|
-
if (object && (0, _getS3Object.isSmallObject)(object)) {
|
|
66
|
-
console.log("This is a small file; responding with object body.");
|
|
67
|
-
return reply.headers({
|
|
68
|
-
"Content-Type": object.ContentType,
|
|
69
|
-
"Cache-Control": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`,
|
|
70
|
-
"x-webiny-base64-encoded": true
|
|
71
|
-
}).send(object.Body || "");
|
|
72
|
-
}
|
|
73
|
-
console.log("This is a large object; redirecting to a presigned URL.");
|
|
74
|
-
const presignedUrl = s3.getSignedUrl("getObject", {
|
|
75
|
-
Bucket: params.Bucket,
|
|
76
|
-
Key: params.Key,
|
|
77
|
-
Expires: PRESIGNED_URL_EXPIRATION
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
// Lambda can return max 6MB of content, so if our object's size is larger, we are sending
|
|
81
|
-
// a 301 Redirect, redirecting the user to the public URL of the object in S3.
|
|
82
|
-
return reply.code(301).headers({
|
|
83
|
-
Location: presignedUrl,
|
|
84
|
-
"Cache-Control": "public, max-age=" + PRESIGNED_URL_EXPIRATION
|
|
85
|
-
}).send("");
|
|
86
|
-
});
|
|
87
|
-
})];
|
|
88
|
-
};
|
|
89
|
-
exports.createDownloadFileByAliasPlugins = createDownloadFileByAliasPlugins;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["DEFAULT_CACHE_MAX_AGE","PRESIGNED_URL_EXPIRATION","region","getEnvironment","s3","S3","createDownloadFileByAliasPlugins","documentClient","getFileByAlias","tenant","alias","Items","Count","query","TableName","String","process","env","DB_TABLE","IndexName","Limit","KeyConditionExpression","ExpressionAttributeValues","promise","data","key","RoutePlugin","onGet","context","request","reply","fileInfo","extractFileInformation","realFilename","filename","code","type","send","params","object","getS3Object","isSmallObject","console","log","headers","ContentType","Body","presignedUrl","getSignedUrl","Bucket","Key","Expires","Location"],"sources":["byAlias.ts"],"sourcesContent":["import S3 from \"aws-sdk/clients/s3\";\nimport { DocumentClient } from \"aws-sdk/clients/dynamodb\";\nimport { getEnvironment } from \"../utils\";\nimport { RoutePlugin } from \"@webiny/handler-aws/gateway\";\nimport { extractFileInformation } from \"./extractFileInformation\";\nimport { getS3Object, isSmallObject } from \"./getS3Object\";\n\nconst DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year\nconst PRESIGNED_URL_EXPIRATION = 900; // 15 minutes\n\nconst { region } = getEnvironment();\nconst s3 = new S3({ region });\n\nexport interface DownloadByFileAliasConfig {\n documentClient: DocumentClient;\n}\n\nexport const createDownloadFileByAliasPlugins = ({ documentClient }: DownloadByFileAliasConfig) => {\n async function getFileByAlias(tenant: string, alias: string): Promise<string | null> {\n const { Items, Count } = await documentClient\n .query({\n TableName: String(process.env.DB_TABLE),\n IndexName: \"GSI1\",\n Limit: 1,\n KeyConditionExpression: \"GSI1_PK = :GSI1_PK AND GSI1_SK = :GSI1_SK\",\n ExpressionAttributeValues: {\n \":GSI1_PK\": `T#${tenant}#FM#FILE_ALIASES`,\n \":GSI1_SK\": `/${alias}`\n }\n })\n .promise();\n\n if (!Items || Count === 0) {\n return null;\n }\n\n return Items[0].data.key ?? null;\n }\n\n return [\n new RoutePlugin(({ onGet, context }) => {\n onGet(\"/*\", async (request, reply) => {\n const fileInfo = extractFileInformation(request);\n\n // TODO: `root` tenant is hardcoded for now, to satisfy the basic use case.\n // We need to find a way to send tenant via `x-tenant` header, when images are being requested from\n // the frontend (website, admin, etc.) by alias.\n const realFilename = await getFileByAlias(\"root\", fileInfo.filename);\n\n if (!realFilename) {\n return reply.code(404).type(\"text/html\").send(\"Not Found\");\n }\n\n const { params, object } = await getS3Object(\n { ...fileInfo, filename: realFilename },\n s3,\n context\n );\n\n if (object && isSmallObject(object)) {\n console.log(\"This is a small file; responding with object body.\");\n\n return reply\n .headers({\n \"Content-Type\": object.ContentType,\n \"Cache-Control\": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`,\n \"x-webiny-base64-encoded\": true\n })\n .send(object.Body || \"\");\n }\n\n console.log(\"This is a large object; redirecting to a presigned URL.\");\n\n const presignedUrl = s3.getSignedUrl(\"getObject\", {\n Bucket: params.Bucket,\n Key: params.Key,\n Expires: PRESIGNED_URL_EXPIRATION\n });\n\n // Lambda can return max 6MB of content, so if our object's size is larger, we are sending\n // a 301 Redirect, redirecting the user to the public URL of the object in S3.\n return reply\n .code(301)\n .headers({\n Location: presignedUrl,\n \"Cache-Control\": \"public, max-age=\" + PRESIGNED_URL_EXPIRATION\n })\n .send(\"\");\n });\n })\n ];\n};\n"],"mappings":";;;;;;;;AAAA;AAEA;AACA;AACA;AACA;AAEA,MAAMA,qBAAqB,GAAG,QAAQ,CAAC,CAAC;AACxC,MAAMC,wBAAwB,GAAG,GAAG,CAAC,CAAC;;AAEtC,MAAM;EAAEC;AAAO,CAAC,GAAG,IAAAC,qBAAc,GAAE;AACnC,MAAMC,EAAE,GAAG,IAAIC,UAAE,CAAC;EAAEH;AAAO,CAAC,CAAC;AAMtB,MAAMI,gCAAgC,GAAG,CAAC;EAAEC;AAA0C,CAAC,KAAK;EAC/F,eAAeC,cAAc,CAACC,MAAc,EAAEC,KAAa,EAA0B;IACjF,MAAM;MAAEC,KAAK;MAAEC;IAAM,CAAC,GAAG,MAAML,cAAc,CACxCM,KAAK,CAAC;MACHC,SAAS,EAAEC,MAAM,CAACC,OAAO,CAACC,GAAG,CAACC,QAAQ,CAAC;MACvCC,SAAS,EAAE,MAAM;MACjBC,KAAK,EAAE,CAAC;MACRC,sBAAsB,EAAE,2CAA2C;MACnEC,yBAAyB,EAAE;QACvB,UAAU,EAAG,KAAIb,MAAO,kBAAiB;QACzC,UAAU,EAAG,IAAGC,KAAM;MAC1B;IACJ,CAAC,CAAC,CACDa,OAAO,EAAE;IAEd,IAAI,CAACZ,KAAK,IAAIC,KAAK,KAAK,CAAC,EAAE;MACvB,OAAO,IAAI;IACf;IAEA,OAAOD,KAAK,CAAC,CAAC,CAAC,CAACa,IAAI,CAACC,GAAG,IAAI,IAAI;EACpC;EAEA,OAAO,CACH,IAAIC,oBAAW,CAAC,CAAC;IAAEC,KAAK;IAAEC;EAAQ,CAAC,KAAK;IACpCD,KAAK,CAAC,IAAI,EAAE,OAAOE,OAAO,EAAEC,KAAK,KAAK;MAClC,MAAMC,QAAQ,GAAG,IAAAC,8CAAsB,EAACH,OAAO,CAAC;;MAEhD;MACA;MACA;MACA,MAAMI,YAAY,GAAG,MAAMzB,cAAc,CAAC,MAAM,EAAEuB,QAAQ,CAACG,QAAQ,CAAC;MAEpE,IAAI,CAACD,YAAY,EAAE;QACf,OAAOH,KAAK,CAACK,IAAI,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC,WAAW,CAAC,CAACC,IAAI,CAAC,WAAW,CAAC;MAC9D;MAEA,MAAM;QAAEC,MAAM;QAAEC;MAAO,CAAC,GAAG,MAAM,IAAAC,wBAAW,8DACnCT,QAAQ;QAAEG,QAAQ,EAAED;MAAY,IACrC7B,EAAE,EACFwB,OAAO,CACV;MAED,IAAIW,MAAM,IAAI,IAAAE,0BAAa,EAACF,MAAM,CAAC,EAAE;QACjCG,OAAO,CAACC,GAAG,CAAC,oDAAoD,CAAC;QAEjE,OAAOb,KAAK,CACPc,OAAO,CAAC;UACL,cAAc,EAAEL,MAAM,CAACM,WAAW;UAClC,eAAe,EAAG,mBAAkB7C,qBAAsB,EAAC;UAC3D,yBAAyB,EAAE;QAC/B,CAAC,CAAC,CACDqC,IAAI,CAACE,MAAM,CAACO,IAAI,IAAI,EAAE,CAAC;MAChC;MAEAJ,OAAO,CAACC,GAAG,CAAC,yDAAyD,CAAC;MAEtE,MAAMI,YAAY,GAAG3C,EAAE,CAAC4C,YAAY,CAAC,WAAW,EAAE;QAC9CC,MAAM,EAAEX,MAAM,CAACW,MAAM;QACrBC,GAAG,EAAEZ,MAAM,CAACY,GAAG;QACfC,OAAO,EAAElD;MACb,CAAC,CAAC;;MAEF;MACA;MACA,OAAO6B,KAAK,CACPK,IAAI,CAAC,GAAG,CAAC,CACTS,OAAO,CAAC;QACLQ,QAAQ,EAAEL,YAAY;QACtB,eAAe,EAAE,kBAAkB,GAAG9C;MAC1C,CAAC,CAAC,CACDoC,IAAI,CAAC,EAAE,CAAC;IACjB,CAAC,CAAC;EACN,CAAC,CAAC,CACL;AACL,CAAC;AAAC"}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.createDownloadFileByExactKeyPlugins = void 0;
|
|
8
|
-
var _s = _interopRequireDefault(require("aws-sdk/clients/s3"));
|
|
9
|
-
var _utils = require("../utils");
|
|
10
|
-
var _gateway = require("@webiny/handler-aws/gateway");
|
|
11
|
-
var _getS3Object = require("./getS3Object");
|
|
12
|
-
var _extractFileInformation = require("./extractFileInformation");
|
|
13
|
-
const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
|
|
14
|
-
const PRESIGNED_URL_EXPIRATION = 900; // 15 minutes
|
|
15
|
-
|
|
16
|
-
const {
|
|
17
|
-
region
|
|
18
|
-
} = (0, _utils.getEnvironment)();
|
|
19
|
-
const s3 = new _s.default({
|
|
20
|
-
region
|
|
21
|
-
});
|
|
22
|
-
const createDownloadFileByExactKeyPlugins = () => {
|
|
23
|
-
return [new _gateway.RoutePlugin(({
|
|
24
|
-
onGet,
|
|
25
|
-
context
|
|
26
|
-
}) => {
|
|
27
|
-
onGet("/files/*", async (request, reply) => {
|
|
28
|
-
const fileInfo = (0, _extractFileInformation.extractFileInformation)(request);
|
|
29
|
-
const {
|
|
30
|
-
params,
|
|
31
|
-
object
|
|
32
|
-
} = await (0, _getS3Object.getS3Object)(fileInfo, s3, context);
|
|
33
|
-
if (object && (0, _getS3Object.isSmallObject)(object)) {
|
|
34
|
-
console.log("This is a small file; responding with object body.");
|
|
35
|
-
return reply.headers({
|
|
36
|
-
"Content-Type": object.ContentType,
|
|
37
|
-
"Cache-Control": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`,
|
|
38
|
-
"x-webiny-base64-encoded": true
|
|
39
|
-
}).send(object.Body || "");
|
|
40
|
-
}
|
|
41
|
-
console.log("This is a large object; redirecting to a presigned URL.");
|
|
42
|
-
const presignedUrl = s3.getSignedUrl("getObject", {
|
|
43
|
-
Bucket: params.Bucket,
|
|
44
|
-
Key: params.Key,
|
|
45
|
-
Expires: PRESIGNED_URL_EXPIRATION
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
// Lambda can return max 6MB of content, so if our object's size is larger, we are sending
|
|
49
|
-
// a 301 Redirect, redirecting the user to the public URL of the object in S3.
|
|
50
|
-
return reply.code(301).headers({
|
|
51
|
-
Location: presignedUrl,
|
|
52
|
-
"Cache-Control": "public, max-age=" + PRESIGNED_URL_EXPIRATION
|
|
53
|
-
}).send("");
|
|
54
|
-
});
|
|
55
|
-
})];
|
|
56
|
-
};
|
|
57
|
-
exports.createDownloadFileByExactKeyPlugins = createDownloadFileByExactKeyPlugins;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["DEFAULT_CACHE_MAX_AGE","PRESIGNED_URL_EXPIRATION","region","getEnvironment","s3","S3","createDownloadFileByExactKeyPlugins","RoutePlugin","onGet","context","request","reply","fileInfo","extractFileInformation","params","object","getS3Object","isSmallObject","console","log","headers","ContentType","send","Body","presignedUrl","getSignedUrl","Bucket","Key","Expires","code","Location"],"sources":["byExactKey.ts"],"sourcesContent":["import S3 from \"aws-sdk/clients/s3\";\nimport { getEnvironment } from \"../utils\";\nimport { RoutePlugin } from \"@webiny/handler-aws/gateway\";\nimport { getS3Object, isSmallObject } from \"~/handlers/download/getS3Object\";\nimport { extractFileInformation } from \"~/handlers/download/extractFileInformation\";\n\nconst DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year\nconst PRESIGNED_URL_EXPIRATION = 900; // 15 minutes\n\nconst { region } = getEnvironment();\nconst s3 = new S3({ region });\n\nexport const createDownloadFileByExactKeyPlugins = () => {\n return [\n new RoutePlugin(({ onGet, context }) => {\n onGet(\"/files/*\", async (request, reply) => {\n const fileInfo = extractFileInformation(request);\n const { params, object } = await getS3Object(fileInfo, s3, context);\n\n if (object && isSmallObject(object)) {\n console.log(\"This is a small file; responding with object body.\");\n return reply\n .headers({\n \"Content-Type\": object.ContentType,\n \"Cache-Control\": `public, max-age=${DEFAULT_CACHE_MAX_AGE}`,\n \"x-webiny-base64-encoded\": true\n })\n .send(object.Body || \"\");\n }\n\n console.log(\"This is a large object; redirecting to a presigned URL.\");\n\n const presignedUrl = s3.getSignedUrl(\"getObject\", {\n Bucket: params.Bucket,\n Key: params.Key,\n Expires: PRESIGNED_URL_EXPIRATION\n });\n\n // Lambda can return max 6MB of content, so if our object's size is larger, we are sending\n // a 301 Redirect, redirecting the user to the public URL of the object in S3.\n return reply\n .code(301)\n .headers({\n Location: presignedUrl,\n \"Cache-Control\": \"public, max-age=\" + PRESIGNED_URL_EXPIRATION\n })\n .send(\"\");\n });\n })\n ];\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AAEA,MAAMA,qBAAqB,GAAG,QAAQ,CAAC,CAAC;AACxC,MAAMC,wBAAwB,GAAG,GAAG,CAAC,CAAC;;AAEtC,MAAM;EAAEC;AAAO,CAAC,GAAG,IAAAC,qBAAc,GAAE;AACnC,MAAMC,EAAE,GAAG,IAAIC,UAAE,CAAC;EAAEH;AAAO,CAAC,CAAC;AAEtB,MAAMI,mCAAmC,GAAG,MAAM;EACrD,OAAO,CACH,IAAIC,oBAAW,CAAC,CAAC;IAAEC,KAAK;IAAEC;EAAQ,CAAC,KAAK;IACpCD,KAAK,CAAC,UAAU,EAAE,OAAOE,OAAO,EAAEC,KAAK,KAAK;MACxC,MAAMC,QAAQ,GAAG,IAAAC,8CAAsB,EAACH,OAAO,CAAC;MAChD,MAAM;QAAEI,MAAM;QAAEC;MAAO,CAAC,GAAG,MAAM,IAAAC,wBAAW,EAACJ,QAAQ,EAAER,EAAE,EAAEK,OAAO,CAAC;MAEnE,IAAIM,MAAM,IAAI,IAAAE,0BAAa,EAACF,MAAM,CAAC,EAAE;QACjCG,OAAO,CAACC,GAAG,CAAC,oDAAoD,CAAC;QACjE,OAAOR,KAAK,CACPS,OAAO,CAAC;UACL,cAAc,EAAEL,MAAM,CAACM,WAAW;UAClC,eAAe,EAAG,mBAAkBrB,qBAAsB,EAAC;UAC3D,yBAAyB,EAAE;QAC/B,CAAC,CAAC,CACDsB,IAAI,CAACP,MAAM,CAACQ,IAAI,IAAI,EAAE,CAAC;MAChC;MAEAL,OAAO,CAACC,GAAG,CAAC,yDAAyD,CAAC;MAEtE,MAAMK,YAAY,GAAGpB,EAAE,CAACqB,YAAY,CAAC,WAAW,EAAE;QAC9CC,MAAM,EAAEZ,MAAM,CAACY,MAAM;QACrBC,GAAG,EAAEb,MAAM,CAACa,GAAG;QACfC,OAAO,EAAE3B;MACb,CAAC,CAAC;;MAEF;MACA;MACA,OAAOU,KAAK,CACPkB,IAAI,CAAC,GAAG,CAAC,CACTT,OAAO,CAAC;QACLU,QAAQ,EAAEN,YAAY;QACtB,eAAe,EAAE,kBAAkB,GAAGvB;MAC1C,CAAC,CAAC,CACDqB,IAAI,CAAC,EAAE,CAAC;IACjB,CAAC,CAAC;EACN,CAAC,CAAC,CACL;AACL,CAAC;AAAC"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Request } from "@webiny/handler/types";
|
|
2
|
-
/**
|
|
3
|
-
* Based on given request path, extracts file key and additional options sent via query params.
|
|
4
|
-
*/
|
|
5
|
-
export declare const extractFileInformation: (request: Request) => {
|
|
6
|
-
filename: string;
|
|
7
|
-
options: any;
|
|
8
|
-
extension: string;
|
|
9
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.extractFileInformation = void 0;
|
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
/**
|
|
10
|
-
* Based on given request path, extracts file key and additional options sent via query params.
|
|
11
|
-
*/
|
|
12
|
-
const extractFileInformation = request => {
|
|
13
|
-
const path = request.params["*"];
|
|
14
|
-
return {
|
|
15
|
-
filename: decodeURI(path),
|
|
16
|
-
options: request.query,
|
|
17
|
-
extension: _path.default.extname(path)
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
exports.extractFileInformation = extractFileInformation;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["extractFileInformation","request","path","params","filename","decodeURI","options","query","extension","pathLib","extname"],"sources":["extractFileInformation.ts"],"sourcesContent":["import pathLib from \"path\";\nimport { Request } from \"@webiny/handler/types\";\n\n/**\n * Based on given request path, extracts file key and additional options sent via query params.\n */\nexport const extractFileInformation = (request: Request) => {\n const path = (request.params as any)[\"*\"];\n return {\n filename: decodeURI(path),\n options: request.query as any,\n extension: pathLib.extname(path)\n };\n};\n"],"mappings":";;;;;;;AAAA;AAGA;AACA;AACA;AACO,MAAMA,sBAAsB,GAAIC,OAAgB,IAAK;EACxD,MAAMC,IAAI,GAAID,OAAO,CAACE,MAAM,CAAS,GAAG,CAAC;EACzC,OAAO;IACHC,QAAQ,EAAEC,SAAS,CAACH,IAAI,CAAC;IACzBI,OAAO,EAAEL,OAAO,CAACM,KAAY;IAC7BC,SAAS,EAAEC,aAAO,CAACC,OAAO,CAACR,IAAI;EACnC,CAAC;AACL,CAAC;AAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import S3 from "aws-sdk/clients/s3";
|
|
2
|
-
import { Context } from "@webiny/handler/types";
|
|
3
|
-
import { ObjectParamsResponse } from "../utils/getObjectParams";
|
|
4
|
-
import { extractFileInformation } from "./extractFileInformation";
|
|
5
|
-
export declare function isSmallObject(object: S3.Types.GetObjectOutput): boolean;
|
|
6
|
-
interface S3Object {
|
|
7
|
-
object?: S3.Types.GetObjectOutput;
|
|
8
|
-
params: ObjectParamsResponse;
|
|
9
|
-
}
|
|
10
|
-
export declare const MAX_RETURN_CONTENT_LENGTH = 5000000;
|
|
11
|
-
export declare const getS3Object: (fileInfo: ReturnType<typeof extractFileInformation>, s3: S3, context: Context) => Promise<S3Object>;
|
|
12
|
-
export {};
|