@webiny/api-file-manager 0.0.0-mt-3 → 0.0.0-unstable.06b2ede40f
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.d.ts +13 -0
- package/FileManagerContextSetup.js +115 -0
- package/FileManagerContextSetup.js.map +1 -0
- package/README.md +1 -1
- package/cmsFileStorage/CmsFilesStorage.d.ts +27 -0
- package/cmsFileStorage/CmsFilesStorage.js +164 -0
- package/cmsFileStorage/CmsFilesStorage.js.map +1 -0
- package/cmsFileStorage/ListFilesWhereProcessor.d.ts +7 -0
- package/cmsFileStorage/ListFilesWhereProcessor.js +33 -0
- package/cmsFileStorage/ListFilesWhereProcessor.js.map +1 -0
- package/cmsFileStorage/ListTagsWhereProcessor.d.ts +7 -0
- package/cmsFileStorage/ListTagsWhereProcessor.js +33 -0
- package/cmsFileStorage/ListTagsWhereProcessor.js.map +1 -0
- package/cmsFileStorage/file.model.d.ts +6 -0
- package/cmsFileStorage/file.model.js +158 -0
- package/cmsFileStorage/file.model.js.map +1 -0
- package/contants.d.ts +1 -0
- package/contants.js +9 -0
- package/contants.js.map +1 -0
- package/createFileManager/files.crud.d.ts +3 -0
- package/createFileManager/files.crud.js +328 -0
- package/createFileManager/files.crud.js.map +1 -0
- package/createFileManager/index.d.ts +3 -0
- package/createFileManager/index.js +23 -0
- package/createFileManager/index.js.map +1 -0
- package/createFileManager/permissions/FilesPermissions.d.ts +4 -0
- package/createFileManager/permissions/FilesPermissions.js +11 -0
- package/createFileManager/permissions/FilesPermissions.js.map +1 -0
- package/createFileManager/permissions/SettingsPermissions.d.ts +4 -0
- package/createFileManager/permissions/SettingsPermissions.js +11 -0
- package/createFileManager/permissions/SettingsPermissions.js.map +1 -0
- package/createFileManager/settings.crud.d.ts +3 -0
- package/createFileManager/settings.crud.js +117 -0
- package/createFileManager/settings.crud.js.map +1 -0
- package/createFileManager/system.crud.d.ts +3 -0
- package/createFileManager/system.crud.js +88 -0
- package/createFileManager/system.crud.js.map +1 -0
- package/createFileManager/types.d.ts +16 -0
- package/createFileManager/types.js +7 -0
- package/createFileManager/types.js.map +1 -0
- package/delivery/AssetDelivery/AliasAssetRequestResolver.d.ts +11 -0
- package/delivery/AssetDelivery/AliasAssetRequestResolver.js +74 -0
- package/delivery/AssetDelivery/AliasAssetRequestResolver.js.map +1 -0
- package/delivery/AssetDelivery/Asset.d.ts +32 -0
- package/delivery/AssetDelivery/Asset.js +69 -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 +25 -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 +37 -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 +6 -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 +6 -0
- package/delivery/AssetDelivery/privateFiles/PrivateCache.js +28 -0
- package/delivery/AssetDelivery/privateFiles/PrivateCache.js.map +1 -0
- package/delivery/AssetDelivery/privateFiles/PrivateFileAssetRequestResolver.d.ts +8 -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 +63 -0
- package/delivery/AssetDelivery/privateFiles/PrivateFilesAssetProcessor.js.map +1 -0
- package/delivery/AssetDelivery/privateFiles/PublicCache.d.ts +6 -0
- package/delivery/AssetDelivery/privateFiles/PublicCache.js +28 -0
- package/delivery/AssetDelivery/privateFiles/PublicCache.js.map +1 -0
- package/delivery/AssetDelivery/privateFiles/RedirectToPrivateUrlOutputStrategy.d.ts +7 -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 +7 -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 +18 -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 +26 -0
- package/delivery/AssetDelivery/transformation/TransformationAssetProcessor.js.map +1 -0
- package/delivery/index.d.ts +17 -0
- package/delivery/index.js +194 -0
- package/delivery/index.js.map +1 -0
- package/delivery/setupAssetDelivery.d.ts +6 -0
- package/delivery/setupAssetDelivery.js +128 -0
- package/delivery/setupAssetDelivery.js.map +1 -0
- package/enterprise/applyThreatScanning.d.ts +2 -0
- package/enterprise/applyThreatScanning.js +20 -0
- package/enterprise/applyThreatScanning.js.map +1 -0
- package/graphql/baseSchema.d.ts +3 -0
- package/graphql/baseSchema.js +121 -0
- package/graphql/baseSchema.js.map +1 -0
- package/graphql/createFilesTypeDefs.d.ts +7 -0
- package/graphql/createFilesTypeDefs.js +184 -0
- package/graphql/createFilesTypeDefs.js.map +1 -0
- package/graphql/filesSchema.d.ts +4 -0
- package/graphql/filesSchema.js +89 -0
- package/graphql/filesSchema.js.map +1 -0
- 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 +4 -0
- package/graphql/index.js +55 -0
- package/graphql/index.js.map +1 -0
- package/graphql/utils.d.ts +11 -0
- package/graphql/utils.js +24 -0
- package/graphql/utils.js.map +1 -0
- package/handlers/manage/imageManager.d.ts +14 -0
- package/handlers/manage/imageManager.js +75 -0
- package/handlers/manage/imageManager.js.map +1 -0
- package/handlers/manage/index.d.ts +5 -3
- package/handlers/manage/index.js +48 -59
- package/handlers/manage/index.js.map +1 -0
- package/handlers/{transform/utils.d.ts → manage/legacyUtils.d.ts} +2 -2
- package/handlers/{transform/utils.js → manage/legacyUtils.js} +7 -19
- package/handlers/manage/legacyUtils.js.map +1 -0
- package/handlers/manage/utils.d.ts +12 -0
- package/handlers/manage/utils.js +34 -0
- package/handlers/manage/utils.js.map +1 -0
- package/handlers/types.d.ts +8 -0
- package/handlers/types.js +7 -0
- package/handlers/types.js.map +1 -0
- package/handlers/utils/getEnvironment.js +2 -2
- package/handlers/utils/getEnvironment.js.map +1 -0
- package/handlers/utils/getObjectParams.d.ts +3 -4
- package/handlers/utils/getObjectParams.js +3 -7
- package/handlers/utils/getObjectParams.js.map +1 -0
- package/handlers/utils/index.d.ts +0 -1
- package/handlers/utils/index.js +3 -12
- package/handlers/utils/index.js.map +1 -0
- package/index.d.ts +10 -0
- package/index.js +76 -0
- package/index.js.map +1 -0
- package/modelModifier/CmsModelModifier.d.ts +26 -0
- package/modelModifier/CmsModelModifier.js +62 -0
- package/modelModifier/CmsModelModifier.js.map +1 -0
- package/package.json +26 -36
- package/plugins/FilePhysicalStoragePlugin.d.ts +22 -0
- package/plugins/{definitions/FilePhysicalStoragePlugin.js → FilePhysicalStoragePlugin.js} +4 -15
- package/plugins/FilePhysicalStoragePlugin.js.map +1 -0
- package/plugins/{definitions/FileStorageTransformPlugin.d.ts → FileStorageTransformPlugin.d.ts} +10 -10
- package/plugins/{definitions/FileStorageTransformPlugin.js → FileStorageTransformPlugin.js} +4 -16
- package/plugins/FileStorageTransformPlugin.js.map +1 -0
- package/plugins/index.d.ts +2 -2
- package/plugins/index.js +23 -18
- package/plugins/index.js.map +1 -0
- package/storage/FileStorage.d.ts +34 -0
- package/storage/FileStorage.js +90 -0
- package/storage/FileStorage.js.map +1 -0
- package/types/file.d.ts +49 -0
- package/types/file.js +7 -0
- package/types/file.js.map +1 -0
- package/types/file.lifecycle.d.ts +44 -0
- package/types/file.lifecycle.js +7 -0
- package/types/file.lifecycle.js.map +1 -0
- package/types.d.ts +104 -89
- package/types.js +25 -1
- package/types.js.map +1 -0
- package/handlers/download/index.d.ts +0 -3
- package/handlers/download/index.js +0 -125
- package/handlers/transform/index.d.ts +0 -3
- package/handlers/transform/index.js +0 -96
- package/handlers/transform/loaders/imageLoader.d.ts +0 -13
- package/handlers/transform/loaders/imageLoader.js +0 -106
- package/handlers/transform/loaders/index.d.ts +0 -13
- package/handlers/transform/loaders/index.js +0 -13
- package/handlers/transform/loaders/sanitizeImageTransformations.d.ts +0 -7
- package/handlers/transform/loaders/sanitizeImageTransformations.js +0 -51
- package/handlers/transform/managers/imageManager.d.ts +0 -9
- package/handlers/transform/managers/imageManager.js +0 -55
- package/handlers/transform/managers/index.d.ts +0 -9
- package/handlers/transform/managers/index.js +0 -13
- package/handlers/transform/optimizeImage.d.ts +0 -2
- package/handlers/transform/optimizeImage.js +0 -45
- package/handlers/transform/transformImage.d.ts +0 -9
- package/handlers/transform/transformImage.js +0 -30
- package/handlers/utils/createHandler.d.ts +0 -24
- package/handlers/utils/createHandler.js +0 -68
- package/plugins/crud/files/validation.d.ts +0 -3
- package/plugins/crud/files/validation.js +0 -41
- package/plugins/crud/files.crud.d.ts +0 -4
- package/plugins/crud/files.crud.js +0 -427
- package/plugins/crud/settings.crud.d.ts +0 -5
- package/plugins/crud/settings.crud.js +0 -115
- package/plugins/crud/system.crud.d.ts +0 -4
- package/plugins/crud/system.crud.js +0 -145
- package/plugins/crud/utils/checkBasePermissions.d.ts +0 -5
- package/plugins/crud/utils/checkBasePermissions.js +0 -33
- package/plugins/crud/utils/createFileModel.d.ts +0 -2
- package/plugins/crud/utils/createFileModel.js +0 -64
- package/plugins/crud/utils/lifecycleEvents.d.ts +0 -6
- package/plugins/crud/utils/lifecycleEvents.js +0 -33
- package/plugins/definitions/FilePhysicalStoragePlugin.d.ts +0 -22
- package/plugins/definitions/FilePlugin.d.ts +0 -133
- package/plugins/definitions/FilePlugin.js +0 -64
- package/plugins/definitions/FilesStorageOperationsProviderPlugin.d.ts +0 -9
- package/plugins/definitions/FilesStorageOperationsProviderPlugin.js +0 -17
- package/plugins/definitions/InstallationPlugin.d.ts +0 -19
- package/plugins/definitions/InstallationPlugin.js +0 -40
- package/plugins/definitions/SettingsStorageOperationsProviderPlugin.d.ts +0 -9
- package/plugins/definitions/SettingsStorageOperationsProviderPlugin.js +0 -17
- package/plugins/definitions/SystemStorageOperationsProviderPlugin.d.ts +0 -9
- package/plugins/definitions/SystemStorageOperationsProviderPlugin.js +0 -17
- package/plugins/graphql.d.ts +0 -4
- package/plugins/graphql.js +0 -274
- package/plugins/storage/FileStorage.d.ts +0 -31
- package/plugins/storage/FileStorage.js +0 -95
- package/plugins/storage/index.d.ts +0 -4
- package/plugins/storage/index.js +0 -22
- package/utils.d.ts +0 -4
- package/utils.js +0 -16
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createSystemCrud = void 0;
|
|
8
|
+
var _pubsub = require("@webiny/pubsub");
|
|
9
|
+
var _apiSecurity = require("@webiny/api-security");
|
|
10
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
+
const createSystemCrud = ({
|
|
12
|
+
storageOperations,
|
|
13
|
+
getTenantId,
|
|
14
|
+
getIdentity,
|
|
15
|
+
WEBINY_VERSION
|
|
16
|
+
}) => {
|
|
17
|
+
return {
|
|
18
|
+
onSystemBeforeInstall: (0, _pubsub.createTopic)("fileManager.onSystemBeforeInstall"),
|
|
19
|
+
onSystemAfterInstall: (0, _pubsub.createTopic)("fileManager.onSystemAfterInstall"),
|
|
20
|
+
async getVersion() {
|
|
21
|
+
const system = await storageOperations.system.get({
|
|
22
|
+
tenant: getTenantId()
|
|
23
|
+
});
|
|
24
|
+
return system ? system.version : null;
|
|
25
|
+
},
|
|
26
|
+
async setVersion(version) {
|
|
27
|
+
const system = await storageOperations.system.get({
|
|
28
|
+
tenant: getTenantId()
|
|
29
|
+
});
|
|
30
|
+
if (system) {
|
|
31
|
+
const data = {
|
|
32
|
+
...system,
|
|
33
|
+
tenant: system.tenant || getTenantId(),
|
|
34
|
+
version
|
|
35
|
+
};
|
|
36
|
+
try {
|
|
37
|
+
await storageOperations.system.update({
|
|
38
|
+
original: system,
|
|
39
|
+
data
|
|
40
|
+
});
|
|
41
|
+
return;
|
|
42
|
+
} catch (ex) {
|
|
43
|
+
throw new _error.default("Could not update the system data.", "SYSTEM_UPDATE_ERROR", {
|
|
44
|
+
data
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const data = {
|
|
49
|
+
version,
|
|
50
|
+
tenant: getTenantId()
|
|
51
|
+
};
|
|
52
|
+
try {
|
|
53
|
+
await storageOperations.system.create({
|
|
54
|
+
data
|
|
55
|
+
});
|
|
56
|
+
return;
|
|
57
|
+
} catch (ex) {
|
|
58
|
+
throw new _error.default("Could not create the system data.", "SYSTEM_CREATE_ERROR", {
|
|
59
|
+
data
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
async install({
|
|
64
|
+
srcPrefix
|
|
65
|
+
}) {
|
|
66
|
+
const identity = getIdentity();
|
|
67
|
+
if (!identity) {
|
|
68
|
+
throw new _apiSecurity.NotAuthorizedError();
|
|
69
|
+
}
|
|
70
|
+
const version = await this.getVersion();
|
|
71
|
+
if (version) {
|
|
72
|
+
throw new _error.default("File Manager is already installed.", "FILES_INSTALL_ABORTED");
|
|
73
|
+
}
|
|
74
|
+
const data = {};
|
|
75
|
+
if (srcPrefix) {
|
|
76
|
+
data.srcPrefix = srcPrefix;
|
|
77
|
+
}
|
|
78
|
+
await this.onSystemBeforeInstall.publish({});
|
|
79
|
+
await this.createSettings(data);
|
|
80
|
+
await this.setVersion(WEBINY_VERSION);
|
|
81
|
+
await this.onSystemAfterInstall.publish({});
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
exports.createSystemCrud = createSystemCrud;
|
|
87
|
+
|
|
88
|
+
//# sourceMappingURL=system.crud.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_pubsub","require","_apiSecurity","_error","_interopRequireDefault","createSystemCrud","storageOperations","getTenantId","getIdentity","WEBINY_VERSION","onSystemBeforeInstall","createTopic","onSystemAfterInstall","getVersion","system","get","tenant","version","setVersion","data","update","original","ex","WebinyError","create","install","srcPrefix","identity","NotAuthorizedError","publish","createSettings","exports"],"sources":["system.crud.ts"],"sourcesContent":["import { createTopic } from \"@webiny/pubsub\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\nimport type {\n FileManagerContextObject,\n FileManagerSettings,\n FileManagerSystem,\n SystemCRUD\n} from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport type { FileManagerConfig } from \"~/createFileManager/types\";\n\nexport const createSystemCrud = ({\n storageOperations,\n getTenantId,\n getIdentity,\n WEBINY_VERSION\n}: Pick<\n FileManagerConfig,\n \"storageOperations\" | \"getTenantId\" | \"getIdentity\" | \"WEBINY_VERSION\"\n>): SystemCRUD => {\n return {\n onSystemBeforeInstall: createTopic(\"fileManager.onSystemBeforeInstall\"),\n onSystemAfterInstall: createTopic(\"fileManager.onSystemAfterInstall\"),\n async getVersion() {\n const system = await storageOperations.system.get({ tenant: getTenantId() });\n\n return system ? system.version : null;\n },\n async setVersion(version: string) {\n const system = await storageOperations.system.get({ tenant: getTenantId() });\n\n if (system) {\n const data: FileManagerSystem = {\n ...system,\n tenant: system.tenant || getTenantId(),\n version\n };\n try {\n await storageOperations.system.update({\n original: system,\n data\n });\n return;\n } catch (ex) {\n throw new WebinyError(\n \"Could not update the system data.\",\n \"SYSTEM_UPDATE_ERROR\",\n {\n data\n }\n );\n }\n }\n\n const data: FileManagerSystem = {\n version,\n tenant: getTenantId()\n };\n try {\n await storageOperations.system.create({\n data\n });\n return;\n } catch (ex) {\n throw new WebinyError(\"Could not create the system data.\", \"SYSTEM_CREATE_ERROR\", {\n data\n });\n }\n },\n async install(this: FileManagerContextObject, { srcPrefix }) {\n const identity = getIdentity();\n\n if (!identity) {\n throw new NotAuthorizedError();\n }\n\n const version = await this.getVersion();\n\n if (version) {\n throw new WebinyError(\n \"File Manager is already installed.\",\n \"FILES_INSTALL_ABORTED\"\n );\n }\n\n const data: Partial<FileManagerSettings> = {};\n\n if (srcPrefix) {\n data.srcPrefix = srcPrefix;\n }\n\n await this.onSystemBeforeInstall.publish({});\n\n await this.createSettings(data);\n await this.setVersion(WEBINY_VERSION);\n\n await this.onSystemAfterInstall.publish({});\n\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAOA,IAAAE,MAAA,GAAAC,sBAAA,CAAA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AE;QACT,MAAM,IAAIC,cAAW,CAAC,mCAAmC,EAAE,qBAAqB,EAAE;UAC9EJ;QACJ,CAAC,CAAC;MACN;IACJ,CAAC;IACD,MAAMM,OAAOA,CAAiC;MAAEC;IAAU,CAAC,EAAE;MACzD,MAAMC,QAAQ,GAAGnB,WAAW,CAAC,CAAC;MAE9B,IAAI,CAACmB,QAAQ,EAAE;QACX,MAAM,IAAIC,+BAAkB,CAAC,CAAC;MAClC;MAEA,MAAMX,OAAO,GAAG,MAAM,IAAI,CAACJ,UAAU,CAAC,CAAC;MAEvC,IAAII,OAAO,EAAE;QACT,MAAM,IAAIM,cAAW,CACjB,oCAAoC,EACpC,uBACJ,CAAC;MACL;MAEA,MAAMJ,IAAkC,GAAG,CAAC,CAAC;MAE7C,IAAIO,SAAS,EAAE;QACXP,IAAI,CAACO,SAAS,GAAGA,SAAS;MAC9B;MAEA,MAAM,IAAI,CAAChB,qBAAqB,CAACmB,OAAO,CAAC,CAAC,CAAC,CAAC;MAE5C,MAAM,IAAI,CAACC,cAAc,CAACX,IAAI,CAAC;MAC/B,MAAM,IAAI,CAACD,UAAU,CAACT,cAAc,CAAC;MAErC,MAAM,IAAI,CAACG,oBAAoB,CAACiB,OAAO,CAAC,CAAC,CAAC,CAAC;MAE3C,OAAO,IAAI;IACf;EACJ,CAAC;AACL,CAAC;AAACE,OAAA,CAAA1B,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FileManagerStorageOperations } from "../types";
|
|
2
|
+
import type { FilesPermissions } from "./permissions/FilesPermissions";
|
|
3
|
+
import type { GetPermissions, SecurityIdentity } from "@webiny/api-security/types";
|
|
4
|
+
import type { FileStorage } from "../storage/FileStorage";
|
|
5
|
+
import type { SettingsPermissions } from "./permissions/SettingsPermissions";
|
|
6
|
+
export interface FileManagerConfig {
|
|
7
|
+
storageOperations: FileManagerStorageOperations;
|
|
8
|
+
filesPermissions: FilesPermissions;
|
|
9
|
+
settingsPermissions: SettingsPermissions;
|
|
10
|
+
getTenantId: () => string;
|
|
11
|
+
getLocaleCode: () => string;
|
|
12
|
+
getIdentity: () => SecurityIdentity;
|
|
13
|
+
getPermissions: GetPermissions;
|
|
14
|
+
storage: FileStorage;
|
|
15
|
+
WEBINY_VERSION: string;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { FileManagerStorageOperations } from \"~/types\";\nimport type { FilesPermissions } from \"./permissions/FilesPermissions\";\nimport type { GetPermissions, SecurityIdentity } from \"@webiny/api-security/types\";\nimport type { FileStorage } from \"~/storage/FileStorage\";\nimport type { SettingsPermissions } from \"./permissions/SettingsPermissions\";\n\nexport interface FileManagerConfig {\n storageOperations: FileManagerStorageOperations;\n filesPermissions: FilesPermissions;\n settingsPermissions: SettingsPermissions;\n getTenantId: () => string;\n getLocaleCode: () => string;\n getIdentity: () => SecurityIdentity;\n getPermissions: GetPermissions;\n storage: FileStorage;\n WEBINY_VERSION: string;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Request } from "@webiny/handler/types";
|
|
2
|
+
import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb";
|
|
3
|
+
import type { AssetRequestResolver } from "..";
|
|
4
|
+
import { AssetRequest } from "..";
|
|
5
|
+
export declare class AliasAssetRequestResolver implements AssetRequestResolver {
|
|
6
|
+
private documentClient;
|
|
7
|
+
private resolver;
|
|
8
|
+
constructor(documentClient: DynamoDBDocument, resolver: AssetRequestResolver);
|
|
9
|
+
resolve(request: Request): Promise<AssetRequest | undefined>;
|
|
10
|
+
private getFileByAlias;
|
|
11
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.AliasAssetRequestResolver = void 0;
|
|
7
|
+
var _clientDynamodb = require("@webiny/aws-sdk/client-dynamodb");
|
|
8
|
+
var _ = require("./..");
|
|
9
|
+
class AliasAssetRequestResolver {
|
|
10
|
+
constructor(documentClient, resolver) {
|
|
11
|
+
this.documentClient = documentClient;
|
|
12
|
+
this.resolver = resolver;
|
|
13
|
+
}
|
|
14
|
+
async resolve(request) {
|
|
15
|
+
const resolvedAsset = await this.resolver.resolve(request);
|
|
16
|
+
if (resolvedAsset) {
|
|
17
|
+
return resolvedAsset;
|
|
18
|
+
}
|
|
19
|
+
const params = request.params ?? {};
|
|
20
|
+
const query = request.query ?? {};
|
|
21
|
+
const path = decodeURI(params["*"]);
|
|
22
|
+
const tenant = query.tenant || "root";
|
|
23
|
+
const fileKey = await this.getFileByAlias(tenant, path);
|
|
24
|
+
if (!fileKey) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
const {
|
|
28
|
+
original,
|
|
29
|
+
...options
|
|
30
|
+
} = query;
|
|
31
|
+
return new _.AssetRequest({
|
|
32
|
+
key: fileKey,
|
|
33
|
+
context: {
|
|
34
|
+
url: request.url
|
|
35
|
+
},
|
|
36
|
+
options: {
|
|
37
|
+
original: original !== undefined,
|
|
38
|
+
...options
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async getFileByAlias(tenant, alias) {
|
|
43
|
+
const {
|
|
44
|
+
Items
|
|
45
|
+
} = await this.documentClient.send(new _clientDynamodb.QueryCommand({
|
|
46
|
+
TableName: String(process.env.DB_TABLE),
|
|
47
|
+
IndexName: "GSI1",
|
|
48
|
+
Limit: 1,
|
|
49
|
+
KeyConditionExpression: "GSI1_PK = :GSI1_PK AND GSI1_SK = :GSI1_SK",
|
|
50
|
+
ExpressionAttributeValues: {
|
|
51
|
+
":GSI1_PK": {
|
|
52
|
+
S: `T#${tenant}#FM#FILE_ALIASES`
|
|
53
|
+
},
|
|
54
|
+
":GSI1_SK": {
|
|
55
|
+
S: alias
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}));
|
|
59
|
+
if (!Array.isArray(Items)) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const [item] = Items;
|
|
63
|
+
if (!item) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const {
|
|
67
|
+
data
|
|
68
|
+
} = (0, _clientDynamodb.unmarshall)(item);
|
|
69
|
+
return data?.key ?? null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.AliasAssetRequestResolver = AliasAssetRequestResolver;
|
|
73
|
+
|
|
74
|
+
//# sourceMappingURL=AliasAssetRequestResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_clientDynamodb","require","_","AliasAssetRequestResolver","constructor","documentClient","resolver","resolve","request","resolvedAsset","params","query","path","decodeURI","tenant","fileKey","getFileByAlias","undefined","original","options","AssetRequest","key","context","url","alias","Items","send","QueryCommand","TableName","String","process","env","DB_TABLE","IndexName","Limit","KeyConditionExpression","ExpressionAttributeValues","S","Array","isArray","item","data","unmarshall","exports"],"sources":["AliasAssetRequestResolver.ts"],"sourcesContent":["import type { Request } from \"@webiny/handler/types\";\nimport type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb\";\nimport { QueryCommand, unmarshall } from \"@webiny/aws-sdk/client-dynamodb\";\nimport type { AssetRequestResolver } from \"~/delivery\";\nimport { AssetRequest } from \"~/delivery\";\n\nexport class AliasAssetRequestResolver implements AssetRequestResolver {\n private documentClient: DynamoDBDocument;\n private resolver: AssetRequestResolver;\n\n constructor(documentClient: DynamoDBDocument, resolver: AssetRequestResolver) {\n this.documentClient = documentClient;\n this.resolver = resolver;\n }\n\n async resolve(request: Request): Promise<AssetRequest | undefined> {\n const resolvedAsset = await this.resolver.resolve(request);\n\n if (resolvedAsset) {\n return resolvedAsset;\n }\n\n const params = (request.params as Record<string, any>) ?? {};\n const query = (request.query as Record<string, any>) ?? {};\n const path = decodeURI(params[\"*\"]);\n\n const tenant = query.tenant || \"root\";\n const fileKey = await this.getFileByAlias(tenant, path);\n\n if (!fileKey) {\n return undefined;\n }\n\n const { original, ...options } = query;\n\n return new AssetRequest({\n key: fileKey,\n context: {\n url: request.url\n },\n options: {\n original: original !== undefined,\n ...options\n }\n });\n }\n\n private async getFileByAlias(tenant: string, alias: string): Promise<string | null> {\n const { Items } = await this.documentClient.send(\n new QueryCommand({\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\": { S: `T#${tenant}#FM#FILE_ALIASES` },\n \":GSI1_SK\": { S: alias }\n }\n })\n );\n\n if (!Array.isArray(Items)) {\n return null;\n }\n const [item] = Items;\n if (!item) {\n return null;\n }\n const { data } = unmarshall(item);\n\n return data?.key ?? null;\n }\n}\n"],"mappings":";;;;;;AAEA,IAAAA,eAAA,GAAAC,OAAA;AAEA,IAAAC,CAAA,GAAAD,OAAA;AAEO,MAAME,yBAAyB,CAAiC;EAInEC,WAAWA,CAACC,cAAgC,EAAEC,QAA8B,EAAE;IAC1E,IAAI,CAACD,cAAc,GAAGA,cAAc;IACpC,IAAI,CAACC,QAAQ,GAAGA,QAAQ;EAC5B;EAEA,MAAMC,OAAOA,CAACC,OAAgB,EAAqC;IAC/D,MAAMC,aAAa,GAAG,MAAM,IAAI,CAACH,QAAQ,CAACC,OAAO,CAACC,OAAO,CAAC;IAE1D,IAAIC,aAAa,EAAE;MACf,OAAOA,aAAa;IACxB;IAEA,MAAMC,MAAM,GAAIF,OAAO,CAACE,MAAM,IAA4B,CAAC,CAAC;IAC5D,MAAMC,KAAK,GAAIH,OAAO,CAACG,KAAK,IAA4B,CAAC,CAAC;IAC1D,MAAMC,IAAI,GAAGC,SAAS,CAACH,MAAM,CAAC,GAAG,CAAC,CAAC;IAEnC,MAAMI,MA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J;AAACsB,OAAA,CAAAxC,yBAAA,GAAAA,yBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import type { AssetContentsReader, AssetOutputStrategy } from "..";
|
|
4
|
+
type Setter<T> = (arg: T | undefined) => T;
|
|
5
|
+
export interface AssetData {
|
|
6
|
+
id: string;
|
|
7
|
+
tenant: string;
|
|
8
|
+
locale: string;
|
|
9
|
+
key: string;
|
|
10
|
+
size: number;
|
|
11
|
+
contentType: string;
|
|
12
|
+
}
|
|
13
|
+
export declare class Asset {
|
|
14
|
+
protected readonly props: AssetData;
|
|
15
|
+
private outputStrategy;
|
|
16
|
+
private contentsReader;
|
|
17
|
+
constructor(props: AssetData);
|
|
18
|
+
clone(): Asset;
|
|
19
|
+
withProps(props: Partial<AssetData>): Asset;
|
|
20
|
+
getId(): string;
|
|
21
|
+
getTenant(): string;
|
|
22
|
+
getLocale(): string;
|
|
23
|
+
getKey(): string;
|
|
24
|
+
getSize(): number;
|
|
25
|
+
getContentType(): string;
|
|
26
|
+
getExtension(): string;
|
|
27
|
+
getContents(): Promise<Buffer>;
|
|
28
|
+
setContentsReader(reader: AssetContentsReader): void;
|
|
29
|
+
output(): Promise<import("..").AssetReply>;
|
|
30
|
+
setOutputStrategy(setter: Setter<AssetOutputStrategy> | AssetOutputStrategy): void;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Asset = void 0;
|
|
7
|
+
class Asset {
|
|
8
|
+
constructor(props) {
|
|
9
|
+
this.props = props;
|
|
10
|
+
}
|
|
11
|
+
clone() {
|
|
12
|
+
return this.withProps(structuredClone(this.props));
|
|
13
|
+
}
|
|
14
|
+
withProps(props) {
|
|
15
|
+
const newAsset = new Asset({
|
|
16
|
+
...this.props,
|
|
17
|
+
...props
|
|
18
|
+
});
|
|
19
|
+
newAsset.contentsReader = this.contentsReader;
|
|
20
|
+
newAsset.outputStrategy = this.outputStrategy;
|
|
21
|
+
return newAsset;
|
|
22
|
+
}
|
|
23
|
+
getId() {
|
|
24
|
+
return this.props.id;
|
|
25
|
+
}
|
|
26
|
+
getTenant() {
|
|
27
|
+
return this.props.tenant;
|
|
28
|
+
}
|
|
29
|
+
getLocale() {
|
|
30
|
+
return this.props.locale;
|
|
31
|
+
}
|
|
32
|
+
getKey() {
|
|
33
|
+
return this.props.key;
|
|
34
|
+
}
|
|
35
|
+
getSize() {
|
|
36
|
+
return this.props.size;
|
|
37
|
+
}
|
|
38
|
+
getContentType() {
|
|
39
|
+
return this.props.contentType;
|
|
40
|
+
}
|
|
41
|
+
getExtension() {
|
|
42
|
+
return this.getKey().split(".").pop() ?? "";
|
|
43
|
+
}
|
|
44
|
+
getContents() {
|
|
45
|
+
if (!this.contentsReader) {
|
|
46
|
+
throw Error(`Asset contents reader was not configured!`);
|
|
47
|
+
}
|
|
48
|
+
return this.contentsReader.read(this);
|
|
49
|
+
}
|
|
50
|
+
setContentsReader(reader) {
|
|
51
|
+
this.contentsReader = reader;
|
|
52
|
+
}
|
|
53
|
+
output() {
|
|
54
|
+
if (!this.outputStrategy) {
|
|
55
|
+
throw Error(`Asset output strategy was not configured!`);
|
|
56
|
+
}
|
|
57
|
+
return this.outputStrategy.output(this);
|
|
58
|
+
}
|
|
59
|
+
setOutputStrategy(setter) {
|
|
60
|
+
if (typeof setter === "function") {
|
|
61
|
+
this.outputStrategy = setter(this.outputStrategy);
|
|
62
|
+
} else {
|
|
63
|
+
this.outputStrategy = setter;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.Asset = Asset;
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=Asset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Asset","constructor","props","clone","withProps","structuredClone","newAsset","contentsReader","outputStrategy","getId","id","getTenant","tenant","getLocale","locale","getKey","key","getSize","size","getContentType","contentType","getExtension","split","pop","getContents","Error","read","setContentsReader","reader","output","setOutputStrategy","setter","exports"],"sources":["Asset.ts"],"sourcesContent":["import type { AssetContentsReader, AssetOutputStrategy } from \"~/delivery\";\n\ntype Setter<T> = (arg: T | undefined) => T;\n\nexport interface AssetData {\n id: string;\n tenant: string;\n locale: string;\n key: string;\n size: number;\n contentType: string;\n}\n\nexport class Asset {\n protected readonly props: AssetData;\n private outputStrategy: AssetOutputStrategy | undefined;\n private contentsReader: AssetContentsReader | undefined;\n\n constructor(props: AssetData) {\n this.props = props;\n }\n\n clone() {\n return this.withProps(structuredClone(this.props));\n }\n\n withProps(props: Partial<AssetData>) {\n const newAsset = new Asset({ ...this.props, ...props });\n newAsset.contentsReader = this.contentsReader;\n newAsset.outputStrategy = this.outputStrategy;\n return newAsset;\n }\n\n getId() {\n return this.props.id;\n }\n getTenant() {\n return this.props.tenant;\n }\n getLocale() {\n return this.props.locale;\n }\n getKey() {\n return this.props.key;\n }\n getSize() {\n return this.props.size;\n }\n getContentType() {\n return this.props.contentType;\n }\n getExtension() {\n return this.getKey().split(\".\").pop() ?? \"\";\n }\n\n getContents() {\n if (!this.contentsReader) {\n throw Error(`Asset contents reader was not configured!`);\n }\n return this.contentsReader.read(this);\n }\n\n setContentsReader(reader: AssetContentsReader) {\n this.contentsReader = reader;\n }\n\n output() {\n if (!this.outputStrategy) {\n throw Error(`Asset output strategy was not configured!`);\n }\n\n return this.outputStrategy.output(this);\n }\n\n setOutputStrategy(setter: Setter<AssetOutputStrategy> | AssetOutputStrategy) {\n if (typeof setter === \"function\") {\n this.outputStrategy = setter(this.outputStrategy);\n } else {\n this.outputStrategy = setter;\n }\n }\n}\n"],"mappings":";;;;;;AAaO,MAAMA,KAAK,CAAC;EAKfC,WAAWA,CAACC,KAAgB,EAAE;IAC1B,IAA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rB,cAAc,GAAGqB,MAAM;EAChC;EAEAC,MAAMA,CAAA,EAAG;IACL,IAAI,CAAC,IAAI,CAACrB,cAAc,EAAE;MACtB,MAAMiB,KAAK,CAAC,2CAA2C,CAAC;IAC5D;IAEA,OAAO,IAAI,CAACjB,cAAc,CAACqB,MAAM,CAAC,IAAI,CAAC;EAC3C;EAEAC,iBAAiBA,CAACC,MAAyD,EAAE;IACzE,IAAI,OAAOA,MAAM,KAAK,UAAU,EAAE;MAC9B,IAAI,CAACvB,cAAc,GAAGuB,MAAM,CAAC,IAAI,CAACvB,cAAc,CAAC;IACrD,CAAC,MAAM;MACH,IAAI,CAACA,cAAc,GAAGuB,MAAM;IAChC;EACJ;AACJ;AAACC,OAAA,CAAAhC,KAAA,GAAAA,KAAA","ignoreList":[]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
import type { AssetRequestResolver, AssetResolver, AssetProcessor, AssetOutputStrategy, AssetRequest, Asset, AssetTransformationStrategy, ResponseHeadersSetter } from "..";
|
|
3
|
+
import type { FileManagerContext } from "../../types";
|
|
4
|
+
type Setter<TParams, TReturn> = (params: TParams) => TReturn;
|
|
5
|
+
export type AssetRequestResolverDecorator = Setter<{
|
|
6
|
+
assetRequestResolver: AssetRequestResolver;
|
|
7
|
+
}, AssetRequestResolver>;
|
|
8
|
+
export type AssetResolverDecorator = Setter<{
|
|
9
|
+
assetResolver: AssetResolver;
|
|
10
|
+
}, AssetResolver>;
|
|
11
|
+
export type AssetProcessorDecorator = Setter<{
|
|
12
|
+
context: FileManagerContext;
|
|
13
|
+
assetProcessor: AssetProcessor;
|
|
14
|
+
}, AssetProcessor>;
|
|
15
|
+
export type AssetTransformationDecorator = Setter<{
|
|
16
|
+
context: FileManagerContext;
|
|
17
|
+
assetTransformationStrategy: AssetTransformationStrategy;
|
|
18
|
+
}, AssetTransformationStrategy>;
|
|
19
|
+
export interface AssetOutputStrategyDecoratorParams {
|
|
20
|
+
context: FileManagerContext;
|
|
21
|
+
assetRequest: AssetRequest;
|
|
22
|
+
asset: Asset;
|
|
23
|
+
assetOutputStrategy: AssetOutputStrategy;
|
|
24
|
+
}
|
|
25
|
+
export type AssetOutputStrategyDecorator = Setter<AssetOutputStrategyDecoratorParams, AssetOutputStrategy>;
|
|
26
|
+
export declare class AssetDeliveryConfigBuilder {
|
|
27
|
+
private assetRequestResolverDecorators;
|
|
28
|
+
private assetResolverDecorators;
|
|
29
|
+
private assetProcessorDecorators;
|
|
30
|
+
private assetTransformationStrategyDecorators;
|
|
31
|
+
private assetOutputStrategyDecorators;
|
|
32
|
+
setResponseHeaders(setter: ResponseHeadersSetter): void;
|
|
33
|
+
decorateAssetRequestResolver(decorator: AssetRequestResolverDecorator): void;
|
|
34
|
+
decorateAssetResolver(decorator: AssetResolverDecorator): void;
|
|
35
|
+
decorateAssetProcessor(decorator: AssetProcessorDecorator): void;
|
|
36
|
+
decorateAssetTransformationStrategy(decorator: AssetTransformationDecorator): void;
|
|
37
|
+
decorateAssetOutputStrategy(decorator: AssetOutputStrategyDecorator): void;
|
|
38
|
+
/**
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
getAssetRequestResolver(): AssetRequestResolver;
|
|
42
|
+
/**
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
getAssetResolver(): AssetResolver;
|
|
46
|
+
/**
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
getAssetProcessor(context: FileManagerContext): AssetProcessor;
|
|
50
|
+
getAssetOutputStrategy(context: FileManagerContext, assetRequest: AssetRequest, asset: Asset): AssetOutputStrategy;
|
|
51
|
+
getAssetTransformationStrategy(context: FileManagerContext): AssetTransformationStrategy;
|
|
52
|
+
}
|
|
53
|
+
export interface AssetDeliveryConfigModifier {
|
|
54
|
+
(config: AssetDeliveryConfigBuilder): Promise<void> | void;
|
|
55
|
+
}
|
|
56
|
+
export declare class AssetDeliveryConfigModifierPlugin extends Plugin {
|
|
57
|
+
static type: string;
|
|
58
|
+
private readonly cb;
|
|
59
|
+
constructor(cb: AssetDeliveryConfigModifier);
|
|
60
|
+
buildConfig(configBuilder: AssetDeliveryConfigBuilder): Promise<void>;
|
|
61
|
+
}
|
|
62
|
+
export declare const createAssetDeliveryConfig: (cb: AssetDeliveryConfigModifier) => AssetDeliveryConfigModifierPlugin;
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createAssetDeliveryConfig = exports.AssetDeliveryConfigModifierPlugin = exports.AssetDeliveryConfigBuilder = void 0;
|
|
7
|
+
var _plugins = require("@webiny/plugins");
|
|
8
|
+
var _ = require("./..");
|
|
9
|
+
var _NullRequestResolver = require("./NullRequestResolver");
|
|
10
|
+
var _NullAssetResolver = require("./NullAssetResolver");
|
|
11
|
+
var _NullAssetOutputStrategy = require("./NullAssetOutputStrategy");
|
|
12
|
+
var _TransformationAssetProcessor = require("./transformation/TransformationAssetProcessor");
|
|
13
|
+
var _PassthroughAssetTransformationStrategy = require("./transformation/PassthroughAssetTransformationStrategy");
|
|
14
|
+
class AssetDeliveryConfigBuilder {
|
|
15
|
+
assetRequestResolverDecorators = [];
|
|
16
|
+
assetResolverDecorators = [];
|
|
17
|
+
assetProcessorDecorators = [];
|
|
18
|
+
assetTransformationStrategyDecorators = [];
|
|
19
|
+
assetOutputStrategyDecorators = [];
|
|
20
|
+
setResponseHeaders(setter) {
|
|
21
|
+
this.decorateAssetOutputStrategy(params => {
|
|
22
|
+
return new _.SetResponseHeaders(setter, params);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
decorateAssetRequestResolver(decorator) {
|
|
26
|
+
this.assetRequestResolverDecorators.push(decorator);
|
|
27
|
+
}
|
|
28
|
+
decorateAssetResolver(decorator) {
|
|
29
|
+
this.assetResolverDecorators.push(decorator);
|
|
30
|
+
}
|
|
31
|
+
decorateAssetProcessor(decorator) {
|
|
32
|
+
this.assetProcessorDecorators.push(decorator);
|
|
33
|
+
}
|
|
34
|
+
decorateAssetTransformationStrategy(decorator) {
|
|
35
|
+
this.assetTransformationStrategyDecorators.push(decorator);
|
|
36
|
+
}
|
|
37
|
+
decorateAssetOutputStrategy(decorator) {
|
|
38
|
+
this.assetOutputStrategyDecorators.push(decorator);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
getAssetRequestResolver() {
|
|
45
|
+
return this.assetRequestResolverDecorators.reduce((value, decorator) => decorator({
|
|
46
|
+
assetRequestResolver: value
|
|
47
|
+
}), new _NullRequestResolver.NullRequestResolver());
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
getAssetResolver() {
|
|
54
|
+
return this.assetResolverDecorators.reduce((value, decorator) => decorator({
|
|
55
|
+
assetResolver: value
|
|
56
|
+
}), new _NullAssetResolver.NullAssetResolver());
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @internal
|
|
61
|
+
*/
|
|
62
|
+
getAssetProcessor(context) {
|
|
63
|
+
return this.assetProcessorDecorators.reduce((value, decorator) => decorator({
|
|
64
|
+
assetProcessor: value,
|
|
65
|
+
context
|
|
66
|
+
}), new _TransformationAssetProcessor.TransformationAssetProcessor(this.getAssetTransformationStrategy(context)));
|
|
67
|
+
}
|
|
68
|
+
getAssetOutputStrategy(context, assetRequest, asset) {
|
|
69
|
+
return this.assetOutputStrategyDecorators.reduce((value, decorator) => {
|
|
70
|
+
return decorator({
|
|
71
|
+
context,
|
|
72
|
+
assetRequest,
|
|
73
|
+
asset,
|
|
74
|
+
assetOutputStrategy: value
|
|
75
|
+
});
|
|
76
|
+
}, new _NullAssetOutputStrategy.NullAssetOutputStrategy());
|
|
77
|
+
}
|
|
78
|
+
getAssetTransformationStrategy(context) {
|
|
79
|
+
return this.assetTransformationStrategyDecorators.reduce((value, decorator) => decorator({
|
|
80
|
+
context,
|
|
81
|
+
assetTransformationStrategy: value
|
|
82
|
+
}), new _PassthroughAssetTransformationStrategy.PassthroughAssetTransformationStrategy());
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.AssetDeliveryConfigBuilder = AssetDeliveryConfigBuilder;
|
|
86
|
+
class AssetDeliveryConfigModifierPlugin extends _plugins.Plugin {
|
|
87
|
+
static type = "fm.config-modifier";
|
|
88
|
+
constructor(cb) {
|
|
89
|
+
super();
|
|
90
|
+
this.cb = cb;
|
|
91
|
+
}
|
|
92
|
+
async buildConfig(configBuilder) {
|
|
93
|
+
await this.cb(configBuilder);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.AssetDeliveryConfigModifierPlugin = AssetDeliveryConfigModifierPlugin;
|
|
97
|
+
const createAssetDeliveryConfig = cb => {
|
|
98
|
+
return new AssetDeliveryConfigModifierPlugin(cb);
|
|
99
|
+
};
|
|
100
|
+
exports.createAssetDeliveryConfig = createAssetDeliveryConfig;
|
|
101
|
+
|
|
102
|
+
//# sourceMappingURL=AssetDeliveryConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_plugins","require","_","_NullRequestResolver","_NullAssetResolver","_NullAssetOutputStrategy","_TransformationAssetProcessor","_PassthroughAssetTransformationStrategy","AssetDeliveryConfigBuilder","assetRequestResolverDecorators","assetResolverDecorators","assetProcessorDecorators","assetTransformationStrategyDecorators","assetOutputStrategyDecorators","setResponseHeaders","setter","decorateAssetOutputStrategy","params","SetResponseHeaders","decorateAssetRequestResolver","decorator","push","decorateAssetResolver","decorateAssetProcessor","decorateAssetTransformationStrategy","getAssetRequestResolver","reduce","value","assetRequestResolver","NullRequestResolver","getAssetResolver","assetResolver","NullAssetResolver","getAssetProcessor","context","assetProcessor","TransformationAssetProcessor","getAssetTransformationStrategy","getAssetOutputStrategy","assetRequest","asset","assetOutputStrategy","NullAssetOutputStrategy","assetTransformationStrategy","PassthroughAssetTransformationStrategy","exports","AssetDeliveryConfigModifierPlugin","Plugin","type","constructor","cb","buildConfig","configBuilder","createAssetDeliveryConfig"],"sources":["AssetDeliveryConfig.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport type {\n AssetRequestResolver,\n AssetResolver,\n AssetProcessor,\n AssetOutputStrategy,\n AssetRequest,\n Asset,\n AssetTransformationStrategy,\n ResponseHeadersSetter\n} from \"~/delivery\";\nimport { SetResponseHeaders } from \"~/delivery\";\nimport type { FileManagerContext } from \"~/types\";\nimport { NullRequestResolver } from \"~/delivery/AssetDelivery/NullRequestResolver\";\nimport { NullAssetResolver } from \"~/delivery/AssetDelivery/NullAssetResolver\";\nimport { NullAssetOutputStrategy } from \"./NullAssetOutputStrategy\";\nimport { TransformationAssetProcessor } from \"./transformation/TransformationAssetProcessor\";\nimport { PassthroughAssetTransformationStrategy } from \"./transformation/PassthroughAssetTransformationStrategy\";\n\ntype Setter<TParams, TReturn> = (params: TParams) => TReturn;\n\nexport type AssetRequestResolverDecorator = Setter<\n { assetRequestResolver: AssetRequestResolver },\n AssetRequestResolver\n>;\n\nexport type AssetResolverDecorator = Setter<{ assetResolver: AssetResolver }, AssetResolver>;\n\nexport type AssetProcessorDecorator = Setter<\n { context: FileManagerContext; assetProcessor: AssetProcessor },\n AssetProcessor\n>;\n\nexport type AssetTransformationDecorator = Setter<\n { context: FileManagerContext; assetTransformationStrategy: AssetTransformationStrategy },\n AssetTransformationStrategy\n>;\n\nexport interface AssetOutputStrategyDecoratorParams {\n context: FileManagerContext;\n assetRequest: AssetRequest;\n asset: Asset;\n assetOutputStrategy: AssetOutputStrategy;\n}\n\nexport type AssetOutputStrategyDecorator = Setter<\n AssetOutputStrategyDecoratorParams,\n AssetOutputStrategy\n>;\n\nexport class AssetDeliveryConfigBuilder {\n private assetRequestResolverDecorators: AssetRequestResolverDecorator[] = [];\n private assetResolverDecorators: AssetResolverDecorator[] = [];\n private assetProcessorDecorators: AssetProcessorDecorator[] = [];\n private assetTransformationStrategyDecorators: AssetTransformationDecorator[] = [];\n private assetOutputStrategyDecorators: AssetOutputStrategyDecorator[] = [];\n\n setResponseHeaders(setter: ResponseHeadersSetter) {\n this.decorateAssetOutputStrategy(params => {\n return new SetResponseHeaders(setter, params);\n });\n }\n\n decorateAssetRequestResolver(decorator: AssetRequestResolverDecorator) {\n this.assetRequestResolverDecorators.push(decorator);\n }\n\n decorateAssetResolver(decorator: AssetResolverDecorator) {\n this.assetResolverDecorators.push(decorator);\n }\n\n decorateAssetProcessor(decorator: AssetProcessorDecorator) {\n this.assetProcessorDecorators.push(decorator);\n }\n\n decorateAssetTransformationStrategy(decorator: AssetTransformationDecorator) {\n this.assetTransformationStrategyDecorators.push(decorator);\n }\n\n decorateAssetOutputStrategy(decorator: AssetOutputStrategyDecorator) {\n this.assetOutputStrategyDecorators.push(decorator);\n }\n\n /**\n * @internal\n */\n getAssetRequestResolver() {\n return this.assetRequestResolverDecorators.reduce<AssetRequestResolver>(\n (value, decorator) => decorator({ assetRequestResolver: value }),\n new NullRequestResolver()\n );\n }\n\n /**\n * @internal\n */\n getAssetResolver() {\n return this.assetResolverDecorators.reduce<AssetResolver>(\n (value, decorator) => decorator({ assetResolver: value }),\n new NullAssetResolver()\n );\n }\n\n /**\n * @internal\n */\n getAssetProcessor(context: FileManagerContext) {\n return this.assetProcessorDecorators.reduce<AssetProcessor>(\n (value, decorator) => decorator({ assetProcessor: value, context }),\n new TransformationAssetProcessor(this.getAssetTransformationStrategy(context))\n );\n }\n\n getAssetOutputStrategy(context: FileManagerContext, assetRequest: AssetRequest, asset: Asset) {\n return this.assetOutputStrategyDecorators.reduce<AssetOutputStrategy>(\n (value, decorator) => {\n return decorator({ context, assetRequest, asset, assetOutputStrategy: value });\n },\n new NullAssetOutputStrategy()\n );\n }\n\n getAssetTransformationStrategy(context: FileManagerContext) {\n return this.assetTransformationStrategyDecorators.reduce<AssetTransformationStrategy>(\n (value, decorator) => decorator({ context, assetTransformationStrategy: value }),\n new PassthroughAssetTransformationStrategy()\n );\n }\n}\n\nexport interface AssetDeliveryConfigModifier {\n (config: AssetDeliveryConfigBuilder): Promise<void> | void;\n}\n\nexport class AssetDeliveryConfigModifierPlugin extends Plugin {\n public static override type = \"fm.config-modifier\";\n private readonly cb: AssetDeliveryConfigModifier;\n\n constructor(cb: AssetDeliveryConfigModifier) {\n super();\n this.cb = cb;\n }\n\n async buildConfig(configBuilder: AssetDeliveryConfigBuilder): Promise<void> {\n await this.cb(configBuilder);\n }\n}\n\nexport const createAssetDeliveryConfig = (cb: AssetDeliveryConfigModifier) => {\n return new AssetDeliveryConfigModifierPlugin(cb);\n};\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAWA,IAAAC,CAAA,GAAAD,OAAA;AAEA,IAAAE,oBAAA,GAAAF,OAAA;AACA,IAAAG,kBAAA,GAAAH,OAAA;AACA,IAAAI,wBAAA,GAAAJ,OAAA;AACA,IAAAK,6BAAA,GAAAL,OAAA;AACA,IAAAM,uCAAA,GAAAN,OAAA;AAiCO,MAAMO,0BAA0B,CAAC;EAC5BC,8BAA8B,GAAoC,EAAE;EACpEC,uBAAuB,GAA6B,EAAE;EACtDC,wBAAwB,GAA8B,EAAE;EACxDC,qCAAqC,GAAmC,EAAE;EAC1EC,6BAA6B,GAAmC,EAAE;EAE1EC,kBAAkBA,CAACC,MAA6B,EAAE;IAC9C,IAAI,CAACC,2BAA2B,CAACC,MAAM,IAAI;MACvC,OAAO,IAAIC,oBAAkB,CAACH,MAAM,EAAEE,MAAM,CAAC;IACjD,CAAC,CAAC;EACN;EAEAE,4BAA4BA,CAACC,SAAwC,EAAE;IACnE,IAAI,CAACX,8BAA8B,CAACY,IAAI,CAACD,SAAS,CAAC;EACvD;EAEAE,qBAAqBA,CAACF,SAAiC,EAAE;IACrD,IAAI,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P,SAAS,KAAK;MAClB,OAAOA,SAAS,CAAC;QAAEc,OAAO;QAAEK,YAAY;QAAEC,KAAK;QAAEC,mBAAmB,EAAEd;MAAM,CAAC,CAAC;IAClF,CAAC,EACD,IAAIe,gDAAuB,CAAC,CAChC,CAAC;EACL;EAEAL,8BAA8BA,CAACH,OAA2B,EAAE;IACxD,OAAO,IAAI,CAACtB,qCAAqC,CAACc,MAAM,CACpD,CAACC,KAAK,EAAEP,SAAS,KAAKA,SAAS,CAAC;MAAEc,OAAO;MAAES,2BAA2B,EAAEhB;IAAM,CAAC,CAAC,EAChF,IAAIiB,8EAAsC,CAAC,CAC/C,CAAC;EACL;AACJ;AAACC,OAAA,CAAArC,0BAAA,GAAAA,0BAAA;AAMM,MAAMsC,iCAAiC,SAASC,eAAM,CAAC;EAC1D,OAAuBC,IAAI,GAAG,oBAAoB;EAGlDC,WAAWA,CAACC,EAA+B,EAAE;IACzC,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;EAEA,MAAMC,WAAWA,CAACC,aAAyC,EAAiB;IACxE,MAAM,IAAI,CAACF,EAAE,CAACE,aAAa,CAAC;EAChC;AACJ;AAACP,OAAA,CAAAC,iCAAA,GAAAA,iCAAA;AAEM,MAAMO,yBAAyB,GAAIH,EAA+B,IAAK;EAC1E,OAAO,IAAIJ,iCAAiC,CAACI,EAAE,CAAC;AACpD,CAAC;AAACL,OAAA,CAAAQ,yBAAA,GAAAA,yBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { GenericRecord } from "@webiny/api/types";
|
|
2
|
+
export interface AssetRequestOptions {
|
|
3
|
+
original?: boolean;
|
|
4
|
+
width?: number;
|
|
5
|
+
}
|
|
6
|
+
export type AssetRequestContext<T extends GenericRecord = GenericRecord> = T & {
|
|
7
|
+
/**
|
|
8
|
+
* Asset request URL.
|
|
9
|
+
*/
|
|
10
|
+
url: string;
|
|
11
|
+
};
|
|
12
|
+
export interface AssetRequestData<TOptions> {
|
|
13
|
+
key: string;
|
|
14
|
+
context: AssetRequestContext;
|
|
15
|
+
options: TOptions;
|
|
16
|
+
}
|
|
17
|
+
export declare class AssetRequest<TOptions extends AssetRequestOptions = AssetRequestOptions> {
|
|
18
|
+
private data;
|
|
19
|
+
constructor(data: AssetRequestData<TOptions>);
|
|
20
|
+
getKey(): string;
|
|
21
|
+
getOptions(): TOptions;
|
|
22
|
+
setOptions(options: TOptions): void;
|
|
23
|
+
getContext<T extends GenericRecord = GenericRecord>(): AssetRequestContext<T>;
|
|
24
|
+
getExtension(): string | undefined;
|
|
25
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.AssetRequest = void 0;
|
|
7
|
+
class AssetRequest {
|
|
8
|
+
constructor(data) {
|
|
9
|
+
this.data = data;
|
|
10
|
+
}
|
|
11
|
+
getKey() {
|
|
12
|
+
return this.data.key;
|
|
13
|
+
}
|
|
14
|
+
getOptions() {
|
|
15
|
+
return this.data.options;
|
|
16
|
+
}
|
|
17
|
+
setOptions(options) {
|
|
18
|
+
this.data.options = options;
|
|
19
|
+
}
|
|
20
|
+
getContext() {
|
|
21
|
+
return this.data.context;
|
|
22
|
+
}
|
|
23
|
+
getExtension() {
|
|
24
|
+
return this.data.key.split(".").pop();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.AssetRequest = AssetRequest;
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=AssetRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["AssetRequest","constructor","data","getKey","key","getOptions","options","setOptions","getContext","context","getExtension","split","pop","exports"],"sources":["AssetRequest.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types\";\n\nexport interface AssetRequestOptions {\n original?: boolean;\n width?: number;\n}\n\nexport type AssetRequestContext<T extends GenericRecord = GenericRecord> = T & {\n /**\n * Asset request URL.\n */\n url: string;\n};\n\nexport interface AssetRequestData<TOptions> {\n key: string;\n context: AssetRequestContext;\n options: TOptions;\n}\n\nexport class AssetRequest<TOptions extends AssetRequestOptions = AssetRequestOptions> {\n private data: AssetRequestData<TOptions>;\n\n constructor(data: AssetRequestData<TOptions>) {\n this.data = data;\n }\n\n getKey() {\n return this.data.key;\n }\n\n getOptions(): TOptions {\n return this.data.options;\n }\n\n setOptions(options: TOptions) {\n this.data.options = options;\n }\n\n getContext<T extends GenericRecord = GenericRecord>() {\n return this.data.context as AssetRequestContext<T>;\n }\n\n getExtension() {\n return this.data.key.split(\".\").pop();\n }\n}\n"],"mappings":";;;;;;AAoBO,MAAMA,YAAY,CAA6D;EAGlFC,WAAWA,CAACC,IAAgC,EAAE;IAC1C,IAAI,CAACA,IAAI,GAAGA,IAAI;EACpB;EAEAC,MAAMA,CAAA,EAAG;IACL,OAAO,IAAI,CAACD,IAAI,CAACE,GAAG;EACxB;EAEAC,UAAUA,CAAA,EAAa;IACnB,OAAO,IAAI,CAACH,IAAI,CAACI,OAAO;EAC5B;EAEAC,UAAUA,CAACD,OAAiB,EAAE;IAC1B,IAAI,CAACJ,IAAI,CAACI,OAAO,GAAGA,OAAO;EAC/B;EAEAE,UAAUA,CAAA,EAA4C;IAClD,OAAO,IAAI,CAACN,IAAI,CAACO,OAAO;EAC5B;EAEAC,YAAYA,CAAA,EAAG;IACX,OAAO,IAAI,CAACR,IAAI,CAACE,GAAG,CAACO,KAAK,CAAC,GAAG,CAAC,CAACC,GAAG,CAAC,CAAC;EACzC;AACJ;AAACC,OAAA,CAAAb,YAAA,GAAAA,YAAA","ignoreList":[]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Request } from "@webiny/handler/types";
|
|
2
|
+
import type { AssetRequestResolver } from "./abstractions/AssetRequestResolver";
|
|
3
|
+
import { AssetRequest } from "./AssetRequest";
|
|
4
|
+
export declare class FilesAssetRequestResolver implements AssetRequestResolver {
|
|
5
|
+
resolve(request: Request): Promise<AssetRequest | undefined>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.FilesAssetRequestResolver = void 0;
|
|
7
|
+
var _AssetRequest = require("./AssetRequest");
|
|
8
|
+
class FilesAssetRequestResolver {
|
|
9
|
+
async resolve(request) {
|
|
10
|
+
// Example: /files/65722cb5c7824a0008d05963/image-48.jpg?width=300
|
|
11
|
+
if (!request.url.startsWith("/files/")) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
const params = request.params ?? {};
|
|
15
|
+
const query = request.query ?? {};
|
|
16
|
+
|
|
17
|
+
// Example: { '*': '/files/65722cb5c7824a0008d05963/image-48.jpg' },
|
|
18
|
+
const path = params["*"];
|
|
19
|
+
const options = {
|
|
20
|
+
...query,
|
|
21
|
+
original: "original" in query
|
|
22
|
+
};
|
|
23
|
+
if (query.width) {
|
|
24
|
+
options.width = parseInt(query.width);
|
|
25
|
+
}
|
|
26
|
+
return new _AssetRequest.AssetRequest({
|
|
27
|
+
key: decodeURI(path).replace("/files/", ""),
|
|
28
|
+
context: {
|
|
29
|
+
url: request.url
|
|
30
|
+
},
|
|
31
|
+
options
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.FilesAssetRequestResolver = FilesAssetRequestResolver;
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=FilesAssetRequestResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_AssetRequest","require","FilesAssetRequestResolver","resolve","request","url","startsWith","undefined","params","query","path","options","original","width","parseInt","AssetRequest","key","decodeURI","replace","context","exports"],"sources":["FilesAssetRequestResolver.ts"],"sourcesContent":["import type { Request } from \"@webiny/handler/types\";\nimport type { AssetRequestResolver } from \"./abstractions/AssetRequestResolver\";\nimport type { AssetRequestOptions } from \"./AssetRequest\";\nimport { AssetRequest } from \"./AssetRequest\";\n\nexport class FilesAssetRequestResolver implements AssetRequestResolver {\n async resolve(request: Request): Promise<AssetRequest | undefined> {\n // Example: /files/65722cb5c7824a0008d05963/image-48.jpg?width=300\n if (!request.url.startsWith(\"/files/\")) {\n return undefined;\n }\n\n const params = (request.params as Record<string, any>) ?? {};\n const query = (request.query as Record<string, any>) ?? {};\n\n // Example: { '*': '/files/65722cb5c7824a0008d05963/image-48.jpg' },\n const path = params[\"*\"];\n\n const options: AssetRequestOptions = {\n ...query,\n original: \"original\" in query\n };\n\n if (query.width) {\n options.width = parseInt(query.width);\n }\n\n return new AssetRequest({\n key: decodeURI(path).replace(\"/files/\", \"\"),\n context: {\n url: request.url\n },\n options\n });\n }\n}\n"],"mappings":";;;;;;AAGA,IAAAA,aAAA,GAAAC,OAAA;AAEO,MAAMC,yBAAyB,CAAiC;EACnE,MAAMC,OAAOA,CAACC,OAAgB,EAAqC;IAC/D;IACA,IAAI,CAACA,OAAO,CAACC,GAAG,CAACC,UAAU,CAAC,SAAS,CAAC,EAAE;MACpC,OAAOC,SAAS;IACpB;IAEA,MAAMC,MAAM,GAAIJ,OAAO,CAACI,MAAM,IAA4B,CAAC,CAAC;IAC5D,MAAMC,KAAK,GAAIL,OAAO,CAACK,KAAK,IAA4B,CAAC,CAAC;;IAE1D;IACA,MAAMC,IAAI,GAAGF,MAAM,CAAC,GAAG,CAAC;IAExB,MAAMG,OAA4B,GAAG;MACjC,GAAGF,KAAK;MACRG,QAAQ,EAAE,UAAU,IAAIH;IAC5B,CAAC;IAED,IAAIA,KAAK,CAACI,KAAK,EAAE;MACbF,OAAO,CAACE,KAAK,GAAGC,QAAQ,CAACL,KAAK,CAACI,KAAK,CAAC;IACzC;IAEA,OAAO,IAAIE,0BAAY,CAAC;MACpBC,GAAG,EAAEC,SAAS,CAACP,IAAI,CAAC,CAACQ,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;MAC3CC,OAAO,EAAE;QACLd,GAAG,EAAED,OAAO,CAACC;MACjB,CAAC;MACDM;IACJ,CAAC,CAAC;EACN;AACJ;AAACS,OAAA,CAAAlB,yBAAA,GAAAA,yBAAA","ignoreList":[]}
|