@webiny/api-file-manager 6.3.0-beta.4 → 6.4.0-beta.0
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/contants.js +2 -1
- package/contants.js.map +1 -1
- package/delivery/AssetDelivery/Asset.js +50 -56
- package/delivery/AssetDelivery/Asset.js.map +1 -1
- package/delivery/AssetDelivery/AssetDeliveryConfig.js +70 -83
- package/delivery/AssetDelivery/AssetDeliveryConfig.js.map +1 -1
- package/delivery/AssetDelivery/AssetRequest.js +20 -19
- package/delivery/AssetDelivery/AssetRequest.js.map +1 -1
- package/delivery/AssetDelivery/FilesAssetRequestResolver.js +19 -25
- package/delivery/AssetDelivery/FilesAssetRequestResolver.js.map +1 -1
- package/delivery/AssetDelivery/NullAssetOutputStrategy.js +5 -4
- package/delivery/AssetDelivery/NullAssetOutputStrategy.js.map +1 -1
- package/delivery/AssetDelivery/NullAssetReply.js +10 -9
- package/delivery/AssetDelivery/NullAssetReply.js.map +1 -1
- package/delivery/AssetDelivery/NullAssetResolver.js +5 -4
- package/delivery/AssetDelivery/NullAssetResolver.js.map +1 -1
- package/delivery/AssetDelivery/NullRequestResolver.js +5 -4
- package/delivery/AssetDelivery/NullRequestResolver.js.map +1 -1
- package/delivery/AssetDelivery/SetCacheControlHeaders.js +11 -14
- package/delivery/AssetDelivery/SetCacheControlHeaders.js.map +1 -1
- package/delivery/AssetDelivery/SetResponseHeaders.js +16 -15
- package/delivery/AssetDelivery/SetResponseHeaders.js.map +1 -1
- package/delivery/AssetDelivery/abstractions/AssetContentsReader.js +0 -3
- package/delivery/AssetDelivery/abstractions/AssetOutputStrategy.js +0 -3
- package/delivery/AssetDelivery/abstractions/AssetProcessor.js +0 -3
- package/delivery/AssetDelivery/abstractions/AssetReply.js +28 -27
- package/delivery/AssetDelivery/abstractions/AssetReply.js.map +1 -1
- package/delivery/AssetDelivery/abstractions/AssetRequestResolver.js +0 -3
- package/delivery/AssetDelivery/abstractions/AssetResolver.js +0 -3
- package/delivery/AssetDelivery/abstractions/AssetTransformationStrategy.js +0 -3
- package/delivery/AssetDelivery/createAssetDeliveryPluginLoader.js +4 -5
- package/delivery/AssetDelivery/createAssetDeliveryPluginLoader.js.map +1 -1
- package/delivery/AssetDelivery/privateFiles/AssetAuthorizer.js +0 -3
- package/delivery/AssetDelivery/privateFiles/NotAuthorizedAssetReply.js +15 -14
- package/delivery/AssetDelivery/privateFiles/NotAuthorizedAssetReply.js.map +1 -1
- package/delivery/AssetDelivery/privateFiles/NotAuthorizedOutputStrategy.js +5 -4
- package/delivery/AssetDelivery/privateFiles/NotAuthorizedOutputStrategy.js.map +1 -1
- package/delivery/AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.js +14 -16
- package/delivery/AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.js.map +1 -1
- package/delivery/AssetDelivery/privateFiles/PrivateCache.js +18 -17
- package/delivery/AssetDelivery/privateFiles/PrivateCache.js.map +1 -1
- package/delivery/AssetDelivery/privateFiles/PrivateFileAssetRequestResolver.js +21 -25
- package/delivery/AssetDelivery/privateFiles/PrivateFileAssetRequestResolver.js.map +1 -1
- package/delivery/AssetDelivery/privateFiles/PrivateFilesAssetProcessor.js +44 -51
- package/delivery/AssetDelivery/privateFiles/PrivateFilesAssetProcessor.js.map +1 -1
- package/delivery/AssetDelivery/privateFiles/PublicCache.js +18 -17
- package/delivery/AssetDelivery/privateFiles/PublicCache.js.map +1 -1
- package/delivery/AssetDelivery/privateFiles/RedirectToPrivateUrlOutputStrategy.js +16 -15
- package/delivery/AssetDelivery/privateFiles/RedirectToPrivateUrlOutputStrategy.js.map +1 -1
- package/delivery/AssetDelivery/privateFiles/RedirectToPublicUrlOutputStrategy.js +16 -15
- package/delivery/AssetDelivery/privateFiles/RedirectToPublicUrlOutputStrategy.js.map +1 -1
- package/delivery/AssetDelivery/transformation/PassthroughAssetProcessor.js +5 -4
- package/delivery/AssetDelivery/transformation/PassthroughAssetProcessor.js.map +1 -1
- package/delivery/AssetDelivery/transformation/PassthroughAssetTransformationStrategy.js +5 -4
- package/delivery/AssetDelivery/transformation/PassthroughAssetTransformationStrategy.js.map +1 -1
- package/delivery/AssetDelivery/transformation/TransformationAssetProcessor.js +12 -15
- package/delivery/AssetDelivery/transformation/TransformationAssetProcessor.js.map +1 -1
- package/delivery/index.js +0 -2
- package/delivery/setupAssetDelivery.js +70 -101
- package/delivery/setupAssetDelivery.js.map +1 -1
- package/domain/file/abstractions.js +2 -5
- package/domain/file/abstractions.js.map +1 -1
- package/domain/file/errors.js +67 -76
- package/domain/file/errors.js.map +1 -1
- package/domain/file/file.model.js +57 -49
- package/domain/file/file.model.js.map +1 -1
- package/domain/file/types.js +0 -3
- package/domain/identity/Identity.js +9 -8
- package/domain/identity/Identity.js.map +1 -1
- package/domain/permissionsSchema.js +26 -15
- package/domain/permissionsSchema.js.map +1 -1
- package/domain/settings/constants.js +2 -1
- package/domain/settings/constants.js.map +1 -1
- package/domain/settings/errors.js +22 -24
- package/domain/settings/errors.js.map +1 -1
- package/domain/settings/types.js +0 -3
- package/domain/settings/validation.js +18 -27
- package/domain/settings/validation.js.map +1 -1
- package/exports/api/file-manager/file.js +0 -2
- package/exports/api/file-manager/permissions.js +0 -2
- package/exports/api/file-manager/settings.js +0 -2
- package/features/FileManagerFeature.js +16 -15
- package/features/FileManagerFeature.js.map +1 -1
- package/features/file/CreateFile/CreateFileRepository.js +20 -18
- package/features/file/CreateFile/CreateFileRepository.js.map +1 -1
- package/features/file/CreateFile/CreateFileUseCase.js +68 -75
- package/features/file/CreateFile/CreateFileUseCase.js.map +1 -1
- package/features/file/CreateFile/abstractions.js +3 -14
- package/features/file/CreateFile/abstractions.js.map +1 -1
- package/features/file/CreateFile/events.js +17 -26
- package/features/file/CreateFile/events.js.map +1 -1
- package/features/file/CreateFile/feature.js +7 -6
- package/features/file/CreateFile/feature.js.map +1 -1
- package/features/file/CreateFile/index.js +0 -2
- package/features/file/CreateFilesInBatch/CreateFilesInBatchRepository.js +15 -17
- package/features/file/CreateFilesInBatch/CreateFilesInBatchRepository.js.map +1 -1
- package/features/file/CreateFilesInBatch/CreateFilesInBatchUseCase.js +59 -70
- package/features/file/CreateFilesInBatch/CreateFilesInBatchUseCase.js.map +1 -1
- package/features/file/CreateFilesInBatch/abstractions.js +3 -14
- package/features/file/CreateFilesInBatch/abstractions.js.map +1 -1
- package/features/file/CreateFilesInBatch/events.js +17 -26
- package/features/file/CreateFilesInBatch/events.js.map +1 -1
- package/features/file/CreateFilesInBatch/feature.js +7 -6
- package/features/file/CreateFilesInBatch/feature.js.map +1 -1
- package/features/file/CreateFilesInBatch/index.js +0 -2
- package/features/file/DeleteFile/DeleteFileRepository.js +21 -20
- package/features/file/DeleteFile/DeleteFileRepository.js.map +1 -1
- package/features/file/DeleteFile/DeleteFileUseCase.js +31 -33
- package/features/file/DeleteFile/DeleteFileUseCase.js.map +1 -1
- package/features/file/DeleteFile/abstractions.js +3 -14
- package/features/file/DeleteFile/abstractions.js.map +1 -1
- package/features/file/DeleteFile/events.js +17 -26
- package/features/file/DeleteFile/events.js.map +1 -1
- package/features/file/DeleteFile/feature.js +7 -6
- package/features/file/DeleteFile/feature.js.map +1 -1
- package/features/file/DeleteFile/index.js +1 -3
- package/features/file/FileUrlGenerator/abstractions.js +2 -2
- package/features/file/FileUrlGenerator/abstractions.js.map +1 -1
- package/features/file/GetFile/GetFileRepository.js +22 -22
- package/features/file/GetFile/GetFileRepository.js.map +1 -1
- package/features/file/GetFile/GetFileUseCase.js +19 -21
- package/features/file/GetFile/GetFileUseCase.js.map +1 -1
- package/features/file/GetFile/abstractions.js +3 -14
- package/features/file/GetFile/abstractions.js.map +1 -1
- package/features/file/GetFile/feature.js +7 -6
- package/features/file/GetFile/feature.js.map +1 -1
- package/features/file/GetFile/index.js +0 -2
- package/features/file/GetFileContentsById/abstractions.d.ts +20 -0
- package/features/file/GetFileContentsById/abstractions.js +5 -0
- package/features/file/GetFileContentsById/abstractions.js.map +1 -0
- package/features/file/GetFileContentsById/index.d.ts +1 -0
- package/features/file/GetFileContentsById/index.js +1 -0
- package/features/file/GetFileContentsByKey/abstractions.d.ts +17 -0
- package/features/file/GetFileContentsByKey/abstractions.js +5 -0
- package/features/file/GetFileContentsByKey/abstractions.js.map +1 -0
- package/features/file/GetFileContentsByKey/index.d.ts +1 -0
- package/features/file/GetFileContentsByKey/index.js +1 -0
- package/features/file/ListFiles/ListFilesRepository.js +42 -40
- package/features/file/ListFiles/ListFilesRepository.js.map +1 -1
- package/features/file/ListFiles/ListFilesUseCase.js +33 -34
- package/features/file/ListFiles/ListFilesUseCase.js.map +1 -1
- package/features/file/ListFiles/abstractions.js +3 -14
- package/features/file/ListFiles/abstractions.js.map +1 -1
- package/features/file/ListFiles/feature.js +7 -6
- package/features/file/ListFiles/feature.js.map +1 -1
- package/features/file/ListFiles/index.js +0 -2
- package/features/file/ListImagesByTagTool/ListImagesByTagTool.js +31 -28
- package/features/file/ListImagesByTagTool/ListImagesByTagTool.js.map +1 -1
- package/features/file/ListImagesByTagTool/feature.js +6 -5
- package/features/file/ListImagesByTagTool/feature.js.map +1 -1
- package/features/file/ListTags/ListTagsRepository.js +31 -36
- package/features/file/ListTags/ListTagsRepository.js.map +1 -1
- package/features/file/ListTags/ListTagsUseCase.js +21 -21
- package/features/file/ListTags/ListTagsUseCase.js.map +1 -1
- package/features/file/ListTags/abstractions.js +3 -14
- package/features/file/ListTags/abstractions.js.map +1 -1
- package/features/file/ListTags/feature.js +7 -6
- package/features/file/ListTags/feature.js.map +1 -1
- package/features/file/ListTags/index.js +0 -2
- package/features/file/UpdateFile/UpdateFileRepository.js +26 -28
- package/features/file/UpdateFile/UpdateFileRepository.js.map +1 -1
- package/features/file/UpdateFile/UpdateFileUseCase.js +57 -65
- package/features/file/UpdateFile/UpdateFileUseCase.js.map +1 -1
- package/features/file/UpdateFile/abstractions.js +3 -14
- package/features/file/UpdateFile/abstractions.js.map +1 -1
- package/features/file/UpdateFile/events.js +17 -26
- package/features/file/UpdateFile/events.js.map +1 -1
- package/features/file/UpdateFile/feature.js +7 -6
- package/features/file/UpdateFile/feature.js.map +1 -1
- package/features/file/UpdateFile/index.js +1 -3
- package/features/file/shared/EntryToFileMapper.js +25 -24
- package/features/file/shared/EntryToFileMapper.js.map +1 -1
- package/features/file/shared/FileInputToEntryInputMapper.js +29 -28
- package/features/file/shared/FileInputToEntryInputMapper.js.map +1 -1
- package/features/file/shared/FileToEntryMapper.js +28 -27
- package/features/file/shared/FileToEntryMapper.js.map +1 -1
- package/features/permissions/abstractions.js +2 -1
- package/features/permissions/abstractions.js.map +1 -1
- package/features/permissions/feature.js +2 -1
- package/features/permissions/feature.js.map +1 -1
- package/features/settings/GetSettings/GetSettingsUseCase.js +19 -19
- package/features/settings/GetSettings/GetSettingsUseCase.js.map +1 -1
- package/features/settings/GetSettings/abstractions.js +2 -7
- package/features/settings/GetSettings/abstractions.js.map +1 -1
- package/features/settings/GetSettings/feature.js +6 -5
- package/features/settings/GetSettings/feature.js.map +1 -1
- package/features/settings/SettingsInstaller/SettingsInstaller.js +25 -24
- package/features/settings/SettingsInstaller/SettingsInstaller.js.map +1 -1
- package/features/settings/SettingsInstaller/feature.js +6 -5
- package/features/settings/SettingsInstaller/feature.js.map +1 -1
- package/features/settings/UpdateSettings/UpdateSettingsUseCase.js +41 -48
- package/features/settings/UpdateSettings/UpdateSettingsUseCase.js.map +1 -1
- package/features/settings/UpdateSettings/abstractions.js +2 -7
- package/features/settings/UpdateSettings/abstractions.js.map +1 -1
- package/features/settings/UpdateSettings/events.js +17 -26
- package/features/settings/UpdateSettings/events.js.map +1 -1
- package/features/settings/UpdateSettings/feature.js +6 -5
- package/features/settings/UpdateSettings/feature.js.map +1 -1
- package/features/settings/UpdateSettings/index.js +0 -2
- package/features/shared/abstractions.js +0 -2
- package/graphql/baseSchema.js +30 -33
- package/graphql/baseSchema.js.map +1 -1
- package/graphql/createFilesTypeDefs.js +49 -57
- package/graphql/createFilesTypeDefs.js.map +1 -1
- package/graphql/filesSchema.js +79 -99
- package/graphql/filesSchema.js.map +1 -1
- package/graphql/getFileByUrl.js +45 -53
- package/graphql/getFileByUrl.js.map +1 -1
- package/graphql/index.js +35 -42
- package/graphql/index.js.map +1 -1
- package/graphql/utils.js +9 -14
- package/graphql/utils.js.map +1 -1
- package/index.js +19 -30
- package/index.js.map +1 -1
- package/modelModifier/CmsModelModifier.js +40 -43
- package/modelModifier/CmsModelModifier.js.map +1 -1
- package/package.json +17 -20
- package/types.js +0 -2
- package/delivery/AssetDelivery/abstractions/AssetContentsReader.js.map +0 -1
- package/delivery/AssetDelivery/abstractions/AssetOutputStrategy.js.map +0 -1
- package/delivery/AssetDelivery/abstractions/AssetProcessor.js.map +0 -1
- package/delivery/AssetDelivery/abstractions/AssetRequestResolver.js.map +0 -1
- package/delivery/AssetDelivery/abstractions/AssetResolver.js.map +0 -1
- package/delivery/AssetDelivery/abstractions/AssetTransformationStrategy.js.map +0 -1
- package/delivery/AssetDelivery/privateFiles/AssetAuthorizer.js.map +0 -1
- package/delivery/index.js.map +0 -1
- package/domain/file/types.js.map +0 -1
- package/domain/settings/types.js.map +0 -1
- package/exports/api/file-manager/file.js.map +0 -1
- package/exports/api/file-manager/permissions.js.map +0 -1
- package/exports/api/file-manager/settings.js.map +0 -1
- package/features/ai/AiImageEnrichmentAfterCreateHandler.d.ts +0 -11
- package/features/ai/AiImageEnrichmentAfterCreateHandler.js +0 -28
- package/features/ai/AiImageEnrichmentAfterCreateHandler.js.map +0 -1
- package/features/ai/AiImageEnrichmentFeature.d.ts +0 -4
- package/features/ai/AiImageEnrichmentFeature.js +0 -12
- package/features/ai/AiImageEnrichmentFeature.js.map +0 -1
- package/features/file/CreateFile/index.js.map +0 -1
- package/features/file/CreateFilesInBatch/index.js.map +0 -1
- package/features/file/DeleteFile/index.js.map +0 -1
- package/features/file/GetFile/index.js.map +0 -1
- package/features/file/ListFiles/index.js.map +0 -1
- package/features/file/ListTags/index.js.map +0 -1
- package/features/file/UpdateFile/index.js.map +0 -1
- package/features/settings/UpdateSettings/index.js.map +0 -1
- package/features/shared/abstractions.js.map +0 -1
- package/tasks/AiImageEnrichmentTask.d.ts +0 -35
- package/tasks/AiImageEnrichmentTask.js +0 -136
- package/tasks/AiImageEnrichmentTask.js.map +0 -1
- package/types.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"delivery/AssetDelivery/SetCacheControlHeaders.js","sources":["../../../src/delivery/AssetDelivery/SetCacheControlHeaders.ts"],"sourcesContent":["import type { ResponseHeaders } from \"@webiny/handler\";\nimport type { Asset, AssetOutputStrategy, AssetReply } from \"~/delivery/index.js\";\n\nexport class SetCacheControlHeaders implements AssetOutputStrategy {\n private readonly strategy: AssetOutputStrategy | undefined;\n private readonly headers: ResponseHeaders;\n\n constructor(headers: ResponseHeaders, strategy: AssetOutputStrategy | undefined) {\n this.headers = headers;\n this.strategy = strategy;\n }\n\n async output(asset: Asset): Promise<AssetReply> {\n if (!this.strategy) {\n throw Error(`No asset output strategy is configured!`);\n }\n\n const reply = await this.strategy.output(asset);\n\n reply.setHeaders(headers => {\n return headers.merge(this.headers);\n });\n\n return reply;\n }\n}\n"],"names":["SetCacheControlHeaders","headers","strategy","asset","Error","reply"],"mappings":"AAGO,MAAMA;IAIT,YAAYC,OAAwB,EAAEC,QAAyC,CAAE;QAC7E,IAAI,CAAC,OAAO,GAAGD;QACf,IAAI,CAAC,QAAQ,GAAGC;IACpB;IAEA,MAAM,OAAOC,KAAY,EAAuB;QAC5C,IAAI,CAAC,IAAI,CAAC,QAAQ,EACd,MAAMC,MAAM;QAGhB,MAAMC,QAAQ,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,CAACF;QAEzCE,MAAM,UAAU,CAACJ,CAAAA,UACNA,QAAQ,KAAK,CAAC,IAAI,CAAC,OAAO;QAGrC,OAAOI;IACX;AACJ"}
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
class SetResponseHeaders {
|
|
2
|
+
constructor(setter, strategyDecoratorParams){
|
|
3
|
+
this.strategyDecoratorParams = strategyDecoratorParams;
|
|
4
|
+
this.setter = setter;
|
|
5
|
+
}
|
|
6
|
+
async output(asset) {
|
|
7
|
+
const reply = await this.strategyDecoratorParams.assetOutputStrategy.output(asset);
|
|
8
|
+
await this.setter({
|
|
9
|
+
asset: this.strategyDecoratorParams.asset,
|
|
10
|
+
assetRequest: this.strategyDecoratorParams.assetRequest,
|
|
11
|
+
context: this.strategyDecoratorParams.context,
|
|
12
|
+
headers: reply.getHeaders()
|
|
13
|
+
});
|
|
14
|
+
return reply;
|
|
15
|
+
}
|
|
16
16
|
}
|
|
17
|
+
export { SetResponseHeaders };
|
|
17
18
|
|
|
18
19
|
//# sourceMappingURL=SetResponseHeaders.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"delivery/AssetDelivery/SetResponseHeaders.js","sources":["../../../src/delivery/AssetDelivery/SetResponseHeaders.ts"],"sourcesContent":["import type {\n AssetOutputStrategy,\n Asset,\n AssetReply,\n AssetRequest,\n AssetOutputStrategyDecoratorParams\n} from \"~/delivery/index.js\";\nimport type { ResponseHeaders } from \"@webiny/handler\";\nimport type { ApiCoreContext } from \"@webiny/api-core/types/core.js\";\n\nexport interface ResponseHeadersParams {\n headers: ResponseHeaders;\n context: ApiCoreContext;\n assetRequest: AssetRequest;\n asset: Asset;\n}\n\nexport interface ResponseHeadersSetter {\n (params: ResponseHeadersParams): Promise<void> | void;\n}\n\nexport class SetResponseHeaders implements AssetOutputStrategy {\n private readonly setter: ResponseHeadersSetter;\n private strategyDecoratorParams: AssetOutputStrategyDecoratorParams;\n\n constructor(\n setter: ResponseHeadersSetter,\n strategyDecoratorParams: AssetOutputStrategyDecoratorParams\n ) {\n this.strategyDecoratorParams = strategyDecoratorParams;\n this.setter = setter;\n }\n\n async output(asset: Asset): Promise<AssetReply> {\n const reply = await this.strategyDecoratorParams.assetOutputStrategy.output(asset);\n\n await this.setter({\n asset: this.strategyDecoratorParams.asset,\n assetRequest: this.strategyDecoratorParams.assetRequest,\n context: this.strategyDecoratorParams.context,\n headers: reply.getHeaders()\n });\n\n return reply;\n }\n}\n"],"names":["SetResponseHeaders","setter","strategyDecoratorParams","asset","reply"],"mappings":"AAqBO,MAAMA;IAIT,YACIC,MAA6B,EAC7BC,uBAA2D,CAC7D;QACE,IAAI,CAAC,uBAAuB,GAAGA;QAC/B,IAAI,CAAC,MAAM,GAAGD;IAClB;IAEA,MAAM,OAAOE,KAAY,EAAuB;QAC5C,MAAMC,QAAQ,MAAM,IAAI,CAAC,uBAAuB,CAAC,mBAAmB,CAAC,MAAM,CAACD;QAE5E,MAAM,IAAI,CAAC,MAAM,CAAC;YACd,OAAO,IAAI,CAAC,uBAAuB,CAAC,KAAK;YACzC,cAAc,IAAI,CAAC,uBAAuB,CAAC,YAAY;YACvD,SAAS,IAAI,CAAC,uBAAuB,CAAC,OAAO;YAC7C,SAASC,MAAM,UAAU;QAC7B;QAEA,OAAOA;IACX;AACJ"}
|
|
@@ -1,31 +1,32 @@
|
|
|
1
1
|
import { ResponseHeaders } from "@webiny/handler";
|
|
2
|
-
const defaultBody = ()
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
2
|
+
const defaultBody = ()=>"";
|
|
3
|
+
class AssetReply {
|
|
4
|
+
constructor(params = {
|
|
5
|
+
code: 200
|
|
6
|
+
}){
|
|
7
|
+
this.code = params.code;
|
|
8
|
+
this.headers = params.headers || ResponseHeaders.create();
|
|
9
|
+
this.body = params.body || defaultBody;
|
|
10
|
+
}
|
|
11
|
+
setHeaders(cb) {
|
|
12
|
+
this.headers = cb(this.headers);
|
|
13
|
+
}
|
|
14
|
+
getHeaders() {
|
|
15
|
+
return this.headers;
|
|
16
|
+
}
|
|
17
|
+
setCode(code) {
|
|
18
|
+
this.code = code;
|
|
19
|
+
}
|
|
20
|
+
getCode() {
|
|
21
|
+
return this.code;
|
|
22
|
+
}
|
|
23
|
+
setBody(body) {
|
|
24
|
+
this.body = body;
|
|
25
|
+
}
|
|
26
|
+
getBody() {
|
|
27
|
+
return this.body();
|
|
28
|
+
}
|
|
29
29
|
}
|
|
30
|
+
export { AssetReply };
|
|
30
31
|
|
|
31
32
|
//# sourceMappingURL=AssetReply.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"delivery/AssetDelivery/abstractions/AssetReply.js","sources":["../../../../src/delivery/AssetDelivery/abstractions/AssetReply.ts"],"sourcesContent":["import { ResponseHeaders } from \"@webiny/handler\";\n\ninterface HeadersSetter {\n (headers: ResponseHeaders): ResponseHeaders;\n}\n\ninterface AssetReplyParams {\n code: number;\n headers?: ResponseHeaders;\n body?: AssetReplyBody;\n}\n\ninterface AssetReplyBody {\n (): Promise<unknown> | unknown;\n}\n\nconst defaultBody = () => \"\";\n\nexport class AssetReply {\n private headers: ResponseHeaders;\n private code: number;\n private body: AssetReplyBody;\n\n constructor(params: AssetReplyParams = { code: 200 }) {\n this.code = params.code;\n this.headers = params.headers || ResponseHeaders.create();\n this.body = params.body || defaultBody;\n }\n\n setHeaders(cb: HeadersSetter) {\n this.headers = cb(this.headers);\n }\n\n getHeaders() {\n return this.headers;\n }\n\n setCode(code: number) {\n this.code = code;\n }\n\n getCode() {\n return this.code;\n }\n\n setBody(body: AssetReplyBody) {\n this.body = body;\n }\n\n getBody() {\n return this.body();\n }\n}\n"],"names":["defaultBody","AssetReply","params","ResponseHeaders","cb","code","body"],"mappings":";AAgBA,MAAMA,cAAc,IAAM;AAEnB,MAAMC;IAKT,YAAYC,SAA2B;QAAE,MAAM;IAAI,CAAC,CAAE;QAClD,IAAI,CAAC,IAAI,GAAGA,OAAO,IAAI;QACvB,IAAI,CAAC,OAAO,GAAGA,OAAO,OAAO,IAAIC,gBAAgB,MAAM;QACvD,IAAI,CAAC,IAAI,GAAGD,OAAO,IAAI,IAAIF;IAC/B;IAEA,WAAWI,EAAiB,EAAE;QAC1B,IAAI,CAAC,OAAO,GAAGA,GAAG,IAAI,CAAC,OAAO;IAClC;IAEA,aAAa;QACT,OAAO,IAAI,CAAC,OAAO;IACvB;IAEA,QAAQC,IAAY,EAAE;QAClB,IAAI,CAAC,IAAI,GAAGA;IAChB;IAEA,UAAU;QACN,OAAO,IAAI,CAAC,IAAI;IACpB;IAEA,QAAQC,IAAoB,EAAE;QAC1B,IAAI,CAAC,IAAI,GAAGA;IAChB;IAEA,UAAU;QACN,OAAO,IAAI,CAAC,IAAI;IACpB;AACJ"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return ()
|
|
4
|
-
}
|
|
5
|
-
return () => Promise.resolve([]);
|
|
1
|
+
const createAssetDeliveryPluginLoader = (cb)=>{
|
|
2
|
+
if ("asset-delivery" === process.env.WEBINY_FUNCTION_TYPE) return ()=>cb();
|
|
3
|
+
return ()=>Promise.resolve([]);
|
|
6
4
|
};
|
|
5
|
+
export { createAssetDeliveryPluginLoader };
|
|
7
6
|
|
|
8
7
|
//# sourceMappingURL=createAssetDeliveryPluginLoader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"delivery/AssetDelivery/createAssetDeliveryPluginLoader.js","sources":["../../../src/delivery/AssetDelivery/createAssetDeliveryPluginLoader.ts"],"sourcesContent":["import type { PluginFactory } from \"@webiny/plugins/types.js\";\n\nexport const createAssetDeliveryPluginLoader = (cb: PluginFactory): PluginFactory => {\n if (process.env.WEBINY_FUNCTION_TYPE === \"asset-delivery\") {\n return () => cb();\n }\n\n return () => Promise.resolve([]);\n};\n"],"names":["createAssetDeliveryPluginLoader","cb","process","Promise"],"mappings":"AAEO,MAAMA,kCAAkC,CAACC;IAC5C,IAAIC,AAAqC,qBAArCA,QAAQ,GAAG,CAAC,oBAAoB,EAChC,OAAO,IAAMD;IAGjB,OAAO,IAAME,QAAQ,OAAO,CAAC,EAAE;AACnC"}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { ResponseHeaders } from "@webiny/handler";
|
|
2
2
|
import { AssetReply } from "../../index.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
3
|
+
class NotAuthorizedAssetReply extends AssetReply {
|
|
4
|
+
constructor(){
|
|
5
|
+
super({
|
|
6
|
+
code: 403,
|
|
7
|
+
headers: ResponseHeaders.create({
|
|
8
|
+
"cache-control": "no-store",
|
|
9
|
+
"content-type": "application/json; charset=utf-8"
|
|
10
|
+
}),
|
|
11
|
+
body: ()=>({
|
|
12
|
+
error: "Not authorized!",
|
|
13
|
+
code: "NOT_AUTHORIZED"
|
|
14
|
+
})
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
17
|
}
|
|
18
|
+
export { NotAuthorizedAssetReply };
|
|
18
19
|
|
|
19
20
|
//# sourceMappingURL=NotAuthorizedAssetReply.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"delivery/AssetDelivery/privateFiles/NotAuthorizedAssetReply.js","sources":["../../../../src/delivery/AssetDelivery/privateFiles/NotAuthorizedAssetReply.ts"],"sourcesContent":["import { ResponseHeaders } from \"@webiny/handler\";\nimport { AssetReply } from \"~/delivery/index.js\";\n\nexport class NotAuthorizedAssetReply extends AssetReply {\n constructor() {\n super({\n code: 403,\n headers: ResponseHeaders.create({\n \"cache-control\": \"no-store\",\n \"content-type\": \"application/json; charset=utf-8\"\n }),\n body: () => ({ error: \"Not authorized!\", code: \"NOT_AUTHORIZED\" })\n });\n }\n}\n"],"names":["NotAuthorizedAssetReply","AssetReply","ResponseHeaders"],"mappings":";;AAGO,MAAMA,gCAAgCC;IACzC,aAAc;QACV,KAAK,CAAC;YACF,MAAM;YACN,SAASC,gBAAgB,MAAM,CAAC;gBAC5B,iBAAiB;gBACjB,gBAAgB;YACpB;YACA,MAAM,IAAO;oBAAE,OAAO;oBAAmB,MAAM;gBAAiB;QACpE;IACJ;AACJ"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { NotAuthorizedAssetReply } from "./NotAuthorizedAssetReply.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
class NotAuthorizedOutputStrategy {
|
|
3
|
+
async output() {
|
|
4
|
+
return new NotAuthorizedAssetReply();
|
|
5
|
+
}
|
|
6
6
|
}
|
|
7
|
+
export { NotAuthorizedOutputStrategy };
|
|
7
8
|
|
|
8
9
|
//# sourceMappingURL=NotAuthorizedOutputStrategy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"delivery/AssetDelivery/privateFiles/NotAuthorizedOutputStrategy.js","sources":["../../../../src/delivery/AssetDelivery/privateFiles/NotAuthorizedOutputStrategy.ts"],"sourcesContent":["import type { AssetOutputStrategy, AssetReply } from \"~/delivery/index.js\";\nimport { NotAuthorizedAssetReply } from \"./NotAuthorizedAssetReply.js\";\n\nexport class NotAuthorizedOutputStrategy implements AssetOutputStrategy {\n async output(): Promise<AssetReply> {\n return new NotAuthorizedAssetReply();\n }\n}\n"],"names":["NotAuthorizedOutputStrategy","NotAuthorizedAssetReply"],"mappings":";AAGO,MAAMA;IACT,MAAM,SAA8B;QAChC,OAAO,IAAIC;IACf;AACJ"}
|
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
});
|
|
15
|
-
}
|
|
1
|
+
import error from "@webiny/error";
|
|
2
|
+
class PrivateAuthenticatedAuthorizer {
|
|
3
|
+
constructor(context){
|
|
4
|
+
this.context = context;
|
|
5
|
+
}
|
|
6
|
+
async authorize(file) {
|
|
7
|
+
if (file.accessControl && "private-authenticated" === file.accessControl.type) {
|
|
8
|
+
const identity = this.context.security.getIdentity();
|
|
9
|
+
if (!identity) throw new error({
|
|
10
|
+
code: "NOT_AUTHORIZED",
|
|
11
|
+
message: "You're not authorized to access this asset!"
|
|
12
|
+
});
|
|
13
|
+
}
|
|
16
14
|
}
|
|
17
|
-
}
|
|
18
15
|
}
|
|
16
|
+
export { PrivateAuthenticatedAuthorizer };
|
|
19
17
|
|
|
20
18
|
//# sourceMappingURL=PrivateAuthenticatedAuthorizer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"delivery/AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.js","sources":["../../../../src/delivery/AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.ts"],"sourcesContent":["import Error from \"@webiny/error\";\nimport type { File } from \"~/domain/file/types.js\";\nimport type { AssetAuthorizer } from \"./AssetAuthorizer.js\";\nimport type { ApiCoreContext } from \"@webiny/api-core/types/core.js\";\n\nexport class PrivateAuthenticatedAuthorizer implements AssetAuthorizer {\n private context: ApiCoreContext;\n\n constructor(context: ApiCoreContext) {\n this.context = context;\n }\n\n async authorize(file: File) {\n if (file.accessControl && file.accessControl.type === \"private-authenticated\") {\n // Make sure there's a valid identity!\n const identity = this.context.security.getIdentity();\n\n if (!identity) {\n throw new Error({\n code: \"NOT_AUTHORIZED\",\n message: \"You're not authorized to access this asset!\"\n });\n }\n }\n }\n}\n"],"names":["PrivateAuthenticatedAuthorizer","context","file","identity","Error"],"mappings":";AAKO,MAAMA;IAGT,YAAYC,OAAuB,CAAE;QACjC,IAAI,CAAC,OAAO,GAAGA;IACnB;IAEA,MAAM,UAAUC,IAAU,EAAE;QACxB,IAAIA,KAAK,aAAa,IAAIA,AAA4B,4BAA5BA,KAAK,aAAa,CAAC,IAAI,EAA8B;YAE3E,MAAMC,WAAW,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,WAAW;YAElD,IAAI,CAACA,UACD,MAAM,IAAIC,MAAM;gBACZ,MAAM;gBACN,SAAS;YACb;QAER;IACJ;AACJ"}
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import { parse, stringify } from "cache-control-parser";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
2
|
+
class PrivateCache {
|
|
3
|
+
constructor(strategy){
|
|
4
|
+
this.strategy = strategy;
|
|
5
|
+
}
|
|
6
|
+
async output(asset) {
|
|
7
|
+
const reply = await this.strategy.output(asset);
|
|
8
|
+
reply.setHeaders((headers)=>{
|
|
9
|
+
headers.set("cache-control", (value = "")=>{
|
|
10
|
+
const cacheControl = parse(value);
|
|
11
|
+
cacheControl["private"] = true;
|
|
12
|
+
cacheControl["public"] = false;
|
|
13
|
+
return stringify(cacheControl);
|
|
14
|
+
});
|
|
15
|
+
return headers;
|
|
16
|
+
});
|
|
17
|
+
return reply;
|
|
18
|
+
}
|
|
19
19
|
}
|
|
20
|
+
export { PrivateCache };
|
|
20
21
|
|
|
21
22
|
//# sourceMappingURL=PrivateCache.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"delivery/AssetDelivery/privateFiles/PrivateCache.js","sources":["../../../../src/delivery/AssetDelivery/privateFiles/PrivateCache.ts"],"sourcesContent":["import { parse, stringify } from \"cache-control-parser\";\nimport type { Asset, AssetOutputStrategy, AssetReply } from \"~/delivery/index.js\";\n\nexport class PrivateCache implements AssetOutputStrategy {\n private strategy: AssetOutputStrategy;\n\n constructor(strategy: AssetOutputStrategy) {\n this.strategy = strategy;\n }\n\n async output(asset: Asset): Promise<AssetReply> {\n const reply = await this.strategy.output(asset);\n\n reply.setHeaders(headers => {\n headers.set(\"cache-control\", (value = \"\") => {\n const cacheControl = parse(value);\n cacheControl[\"private\"] = true;\n cacheControl[\"public\"] = false;\n return stringify(cacheControl);\n });\n return headers;\n });\n\n return reply;\n }\n}\n"],"names":["PrivateCache","strategy","asset","reply","headers","value","cacheControl","parse","stringify"],"mappings":";AAGO,MAAMA;IAGT,YAAYC,QAA6B,CAAE;QACvC,IAAI,CAAC,QAAQ,GAAGA;IACpB;IAEA,MAAM,OAAOC,KAAY,EAAuB;QAC5C,MAAMC,QAAQ,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,CAACD;QAEzCC,MAAM,UAAU,CAACC,CAAAA;YACbA,QAAQ,GAAG,CAAC,iBAAiB,CAACC,QAAQ,EAAE;gBACpC,MAAMC,eAAeC,MAAMF;gBAC3BC,YAAY,CAAC,UAAU,GAAG;gBAC1BA,YAAY,CAAC,SAAS,GAAG;gBACzB,OAAOE,UAAUF;YACrB;YACA,OAAOF;QACX;QAEA,OAAOD;IACX;AACJ"}
|
|
@@ -1,30 +1,26 @@
|
|
|
1
1
|
import { AssetRequest } from "../../index.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
class PrivateFileAssetRequestResolver {
|
|
3
|
+
constructor(resolver){
|
|
4
|
+
this.resolver = resolver;
|
|
5
|
+
}
|
|
6
|
+
async resolve(request) {
|
|
7
|
+
if (!request.url.startsWith("/private/")) return this.resolver.resolve(request);
|
|
8
|
+
const params = request.params ?? {};
|
|
9
|
+
const query = request.query ?? {};
|
|
10
|
+
const path = params["*"];
|
|
11
|
+
return new AssetRequest({
|
|
12
|
+
key: decodeURI(path).replace("/private/", ""),
|
|
13
|
+
context: {
|
|
14
|
+
url: request.url,
|
|
15
|
+
private: true
|
|
16
|
+
},
|
|
17
|
+
options: {
|
|
18
|
+
...query,
|
|
19
|
+
width: query.width ? parseInt(query.width) : void 0
|
|
20
|
+
}
|
|
21
|
+
});
|
|
10
22
|
}
|
|
11
|
-
const params = request.params ?? {};
|
|
12
|
-
const query = request.query ?? {};
|
|
13
|
-
|
|
14
|
-
// Example: { '*': '/private/65722cb5c7824a0008d05963/image-48.jpg' },
|
|
15
|
-
const path = params["*"];
|
|
16
|
-
return new AssetRequest({
|
|
17
|
-
key: decodeURI(path).replace("/private/", ""),
|
|
18
|
-
context: {
|
|
19
|
-
url: request.url,
|
|
20
|
-
private: true
|
|
21
|
-
},
|
|
22
|
-
options: {
|
|
23
|
-
...query,
|
|
24
|
-
width: query.width ? parseInt(query.width) : undefined
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
23
|
}
|
|
24
|
+
export { PrivateFileAssetRequestResolver };
|
|
29
25
|
|
|
30
26
|
//# sourceMappingURL=PrivateFileAssetRequestResolver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"delivery/AssetDelivery/privateFiles/PrivateFileAssetRequestResolver.js","sources":["../../../../src/delivery/AssetDelivery/privateFiles/PrivateFileAssetRequestResolver.ts"],"sourcesContent":["import type { AssetRequestResolver } from \"~/delivery/index.js\";\nimport { AssetRequest } from \"~/delivery/index.js\";\nimport type { Request } from \"@webiny/handler/types.js\";\n\nexport class PrivateFileAssetRequestResolver implements AssetRequestResolver {\n private readonly resolver: AssetRequestResolver;\n\n constructor(resolver: AssetRequestResolver) {\n this.resolver = resolver;\n }\n\n async resolve(request: Request): Promise<AssetRequest | undefined> {\n // Example: /private/65722cb5c7824a0008d05963/image-48.jpg?width=300\n if (!request.url.startsWith(\"/private/\")) {\n return this.resolver.resolve(request);\n }\n\n const params = (request.params ?? {}) as Record<string, any>;\n const query = (request.query ?? {}) as Record<string, any>;\n\n // Example: { '*': '/private/65722cb5c7824a0008d05963/image-48.jpg' },\n const path = params[\"*\"];\n\n return new AssetRequest({\n key: decodeURI(path).replace(\"/private/\", \"\"),\n context: {\n url: request.url,\n private: true\n },\n options: {\n ...query,\n width: query.width ? parseInt(query.width) : undefined\n }\n });\n }\n}\n"],"names":["PrivateFileAssetRequestResolver","resolver","request","params","query","path","AssetRequest","decodeURI","parseInt","undefined"],"mappings":";AAIO,MAAMA;IAGT,YAAYC,QAA8B,CAAE;QACxC,IAAI,CAAC,QAAQ,GAAGA;IACpB;IAEA,MAAM,QAAQC,OAAgB,EAAqC;QAE/D,IAAI,CAACA,QAAQ,GAAG,CAAC,UAAU,CAAC,cACxB,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAACA;QAGjC,MAAMC,SAAUD,QAAQ,MAAM,IAAI,CAAC;QACnC,MAAME,QAASF,QAAQ,KAAK,IAAI,CAAC;QAGjC,MAAMG,OAAOF,MAAM,CAAC,IAAI;QAExB,OAAO,IAAIG,aAAa;YACpB,KAAKC,UAAUF,MAAM,OAAO,CAAC,aAAa;YAC1C,SAAS;gBACL,KAAKH,QAAQ,GAAG;gBAChB,SAAS;YACb;YACA,SAAS;gBACL,GAAGE,KAAK;gBACR,OAAOA,MAAM,KAAK,GAAGI,SAASJ,MAAM,KAAK,IAAIK;YACjD;QACJ;IACJ;AACJ"}
|
|
@@ -4,60 +4,53 @@ import { RedirectToPrivateUrlOutputStrategy } from "./RedirectToPrivateUrlOutput
|
|
|
4
4
|
import { PrivateCache } from "./PrivateCache.js";
|
|
5
5
|
import { PublicCache } from "./PublicCache.js";
|
|
6
6
|
import { GetFileUseCase } from "../../../features/file/GetFile/index.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
7
|
+
class PrivateFilesAssetProcessor {
|
|
8
|
+
constructor(context, assetAuthorizer, assetProcessor){
|
|
9
|
+
this.assetAuthorizer = assetAuthorizer;
|
|
10
|
+
this.context = context;
|
|
11
|
+
this.assetProcessor = assetProcessor;
|
|
12
|
+
}
|
|
13
|
+
async process(assetRequest, asset) {
|
|
14
|
+
const id = asset.getId();
|
|
15
|
+
const { security } = this.context;
|
|
16
|
+
const getFile = this.context.container.resolve(GetFileUseCase);
|
|
17
|
+
const file = await security.withoutAuthorization(async ()=>{
|
|
18
|
+
const fileResult = await getFile.execute(id);
|
|
19
|
+
if (fileResult.isFail()) throw fileResult.error;
|
|
20
|
+
return fileResult.value;
|
|
21
|
+
});
|
|
22
|
+
const isPrivateFile = this.isPrivate(file);
|
|
23
|
+
if (!isPrivateFile && this.requestedViaPrivateEndpoint(assetRequest)) {
|
|
24
|
+
asset.setOutputStrategy(new RedirectToPublicUrlOutputStrategy(assetRequest));
|
|
25
|
+
return asset;
|
|
26
|
+
}
|
|
27
|
+
if (isPrivateFile && this.requestedViaPublicEndpoint(assetRequest)) {
|
|
28
|
+
asset.setOutputStrategy(new RedirectToPrivateUrlOutputStrategy(assetRequest));
|
|
29
|
+
return asset;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
await this.assetAuthorizer.authorize(file);
|
|
33
|
+
} catch {
|
|
34
|
+
asset.setOutputStrategy(new NotAuthorizedOutputStrategy());
|
|
35
|
+
return asset;
|
|
36
|
+
}
|
|
37
|
+
const processedAsset = await this.assetProcessor.process(assetRequest, asset);
|
|
38
|
+
processedAsset.setOutputStrategy((strategy)=>{
|
|
39
|
+
if (!strategy) throw Error("No asset output strategy is configured!");
|
|
40
|
+
return isPrivateFile ? new PrivateCache(strategy) : new PublicCache(strategy);
|
|
41
|
+
});
|
|
42
|
+
return processedAsset;
|
|
43
|
+
}
|
|
44
|
+
isPrivate(file) {
|
|
45
|
+
return file.accessControl && file.accessControl.type.startsWith("private-");
|
|
32
46
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return asset;
|
|
47
|
+
requestedViaPrivateEndpoint(assetRequest) {
|
|
48
|
+
return assetRequest.getContext().private;
|
|
36
49
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
} catch {
|
|
40
|
-
asset.setOutputStrategy(new NotAuthorizedOutputStrategy());
|
|
41
|
-
return asset;
|
|
50
|
+
requestedViaPublicEndpoint(assetRequest) {
|
|
51
|
+
return !this.requestedViaPrivateEndpoint(assetRequest);
|
|
42
52
|
}
|
|
43
|
-
const processedAsset = await this.assetProcessor.process(assetRequest, asset);
|
|
44
|
-
processedAsset.setOutputStrategy(strategy => {
|
|
45
|
-
if (!strategy) {
|
|
46
|
-
throw Error(`No asset output strategy is configured!`);
|
|
47
|
-
}
|
|
48
|
-
return isPrivateFile ? new PrivateCache(strategy) : new PublicCache(strategy);
|
|
49
|
-
});
|
|
50
|
-
return processedAsset;
|
|
51
|
-
}
|
|
52
|
-
isPrivate(file) {
|
|
53
|
-
return file.accessControl && file.accessControl.type.startsWith("private-");
|
|
54
|
-
}
|
|
55
|
-
requestedViaPrivateEndpoint(assetRequest) {
|
|
56
|
-
return assetRequest.getContext().private;
|
|
57
|
-
}
|
|
58
|
-
requestedViaPublicEndpoint(assetRequest) {
|
|
59
|
-
return !this.requestedViaPrivateEndpoint(assetRequest);
|
|
60
|
-
}
|
|
61
53
|
}
|
|
54
|
+
export { PrivateFilesAssetProcessor };
|
|
62
55
|
|
|
63
56
|
//# sourceMappingURL=PrivateFilesAssetProcessor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"delivery/AssetDelivery/privateFiles/PrivateFilesAssetProcessor.js","sources":["../../../../src/delivery/AssetDelivery/privateFiles/PrivateFilesAssetProcessor.ts"],"sourcesContent":["import type { ApiCoreContext } from \"@webiny/api-core/types/core.js\";\nimport type { File } from \"~/domain/file/types.js\";\nimport type { Asset, AssetProcessor, AssetRequest } from \"~/delivery/index.js\";\nimport type { AssetAuthorizer } from \"./AssetAuthorizer.js\";\nimport { NotAuthorizedOutputStrategy } from \"./NotAuthorizedOutputStrategy.js\";\nimport { RedirectToPublicUrlOutputStrategy } from \"./RedirectToPublicUrlOutputStrategy.js\";\nimport { RedirectToPrivateUrlOutputStrategy } from \"./RedirectToPrivateUrlOutputStrategy.js\";\nimport { PrivateCache } from \"./PrivateCache.js\";\nimport { PublicCache } from \"./PublicCache.js\";\nimport { GetFileUseCase } from \"~/features/file/GetFile/index.js\";\n\ninterface MaybePrivate {\n private?: boolean;\n}\n\nexport class PrivateFilesAssetProcessor implements AssetProcessor {\n private readonly context: ApiCoreContext;\n private assetProcessor: AssetProcessor;\n private assetAuthorizer: AssetAuthorizer;\n\n constructor(\n context: ApiCoreContext,\n assetAuthorizer: AssetAuthorizer,\n assetProcessor: AssetProcessor\n ) {\n this.assetAuthorizer = assetAuthorizer;\n this.context = context;\n this.assetProcessor = assetProcessor;\n }\n\n async process(assetRequest: AssetRequest, asset: Asset): Promise<Asset> {\n const id = asset.getId();\n const { security } = this.context;\n const getFile = this.context.container.resolve(GetFileUseCase);\n\n // Get file from File Manager by `id`.\n const file = await security.withoutAuthorization(async () => {\n const fileResult = await getFile.execute(id);\n if (fileResult.isFail()) {\n throw fileResult.error;\n }\n return fileResult.value;\n });\n\n const isPrivateFile = this.isPrivate(file);\n\n if (!isPrivateFile && this.requestedViaPrivateEndpoint(assetRequest)) {\n asset.setOutputStrategy(new RedirectToPublicUrlOutputStrategy(assetRequest));\n return asset;\n }\n\n if (isPrivateFile && this.requestedViaPublicEndpoint(assetRequest)) {\n asset.setOutputStrategy(new RedirectToPrivateUrlOutputStrategy(assetRequest));\n return asset;\n }\n\n try {\n await this.assetAuthorizer.authorize(file);\n } catch {\n asset.setOutputStrategy(new NotAuthorizedOutputStrategy());\n\n return asset;\n }\n\n const processedAsset = await this.assetProcessor.process(assetRequest, asset);\n\n processedAsset.setOutputStrategy(strategy => {\n if (!strategy) {\n throw Error(`No asset output strategy is configured!`);\n }\n return isPrivateFile ? new PrivateCache(strategy) : new PublicCache(strategy);\n });\n\n return processedAsset;\n }\n\n private isPrivate(file: File) {\n return file.accessControl && file.accessControl.type.startsWith(\"private-\");\n }\n\n private requestedViaPrivateEndpoint(assetRequest: AssetRequest) {\n return assetRequest.getContext<MaybePrivate>().private;\n }\n\n private requestedViaPublicEndpoint(assetRequest: AssetRequest) {\n return !this.requestedViaPrivateEndpoint(assetRequest);\n }\n}\n"],"names":["PrivateFilesAssetProcessor","context","assetAuthorizer","assetProcessor","assetRequest","asset","id","security","getFile","GetFileUseCase","file","fileResult","isPrivateFile","RedirectToPublicUrlOutputStrategy","RedirectToPrivateUrlOutputStrategy","NotAuthorizedOutputStrategy","processedAsset","strategy","Error","PrivateCache","PublicCache"],"mappings":";;;;;;AAeO,MAAMA;IAKT,YACIC,OAAuB,EACvBC,eAAgC,EAChCC,cAA8B,CAChC;QACE,IAAI,CAAC,eAAe,GAAGD;QACvB,IAAI,CAAC,OAAO,GAAGD;QACf,IAAI,CAAC,cAAc,GAAGE;IAC1B;IAEA,MAAM,QAAQC,YAA0B,EAAEC,KAAY,EAAkB;QACpE,MAAMC,KAAKD,MAAM,KAAK;QACtB,MAAM,EAAEE,QAAQ,EAAE,GAAG,IAAI,CAAC,OAAO;QACjC,MAAMC,UAAU,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAACC;QAG/C,MAAMC,OAAO,MAAMH,SAAS,oBAAoB,CAAC;YAC7C,MAAMI,aAAa,MAAMH,QAAQ,OAAO,CAACF;YACzC,IAAIK,WAAW,MAAM,IACjB,MAAMA,WAAW,KAAK;YAE1B,OAAOA,WAAW,KAAK;QAC3B;QAEA,MAAMC,gBAAgB,IAAI,CAAC,SAAS,CAACF;QAErC,IAAI,CAACE,iBAAiB,IAAI,CAAC,2BAA2B,CAACR,eAAe;YAClEC,MAAM,iBAAiB,CAAC,IAAIQ,kCAAkCT;YAC9D,OAAOC;QACX;QAEA,IAAIO,iBAAiB,IAAI,CAAC,0BAA0B,CAACR,eAAe;YAChEC,MAAM,iBAAiB,CAAC,IAAIS,mCAAmCV;YAC/D,OAAOC;QACX;QAEA,IAAI;YACA,MAAM,IAAI,CAAC,eAAe,CAAC,SAAS,CAACK;QACzC,EAAE,OAAM;YACJL,MAAM,iBAAiB,CAAC,IAAIU;YAE5B,OAAOV;QACX;QAEA,MAAMW,iBAAiB,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAACZ,cAAcC;QAEvEW,eAAe,iBAAiB,CAACC,CAAAA;YAC7B,IAAI,CAACA,UACD,MAAMC,MAAM;YAEhB,OAAON,gBAAgB,IAAIO,aAAaF,YAAY,IAAIG,YAAYH;QACxE;QAEA,OAAOD;IACX;IAEQ,UAAUN,IAAU,EAAE;QAC1B,OAAOA,KAAK,aAAa,IAAIA,KAAK,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC;IACpE;IAEQ,4BAA4BN,YAA0B,EAAE;QAC5D,OAAOA,aAAa,UAAU,GAAiB,OAAO;IAC1D;IAEQ,2BAA2BA,YAA0B,EAAE;QAC3D,OAAO,CAAC,IAAI,CAAC,2BAA2B,CAACA;IAC7C;AACJ"}
|