@webiny/api-file-manager 6.3.0 → 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,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 PublicCache {
|
|
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"] = false;
|
|
12
|
+
cacheControl["public"] = true;
|
|
13
|
+
return stringify(cacheControl);
|
|
14
|
+
});
|
|
15
|
+
return headers;
|
|
16
|
+
});
|
|
17
|
+
return reply;
|
|
18
|
+
}
|
|
19
19
|
}
|
|
20
|
+
export { PublicCache };
|
|
20
21
|
|
|
21
22
|
//# sourceMappingURL=PublicCache.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"delivery/AssetDelivery/privateFiles/PublicCache.js","sources":["../../../../src/delivery/AssetDelivery/privateFiles/PublicCache.ts"],"sourcesContent":["import { parse, stringify } from \"cache-control-parser\";\nimport type { Asset, AssetOutputStrategy, AssetReply } from \"~/delivery/index.js\";\n\nexport class PublicCache 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\"] = false;\n cacheControl[\"public\"] = true;\n return stringify(cacheControl);\n });\n return headers;\n });\n\n return reply;\n }\n}\n"],"names":["PublicCache","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,20 +1,21 @@
|
|
|
1
1
|
import { AssetReply } from "../../index.js";
|
|
2
2
|
import { ResponseHeaders } from "@webiny/handler";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
3
|
+
class RedirectToPrivateUrlOutputStrategy {
|
|
4
|
+
constructor(assetRequest){
|
|
5
|
+
this.assetRequest = assetRequest;
|
|
6
|
+
}
|
|
7
|
+
async output(asset) {
|
|
8
|
+
const requestUrl = this.assetRequest.getContext().url;
|
|
9
|
+
return new AssetReply({
|
|
10
|
+
code: 301,
|
|
11
|
+
headers: ResponseHeaders.create({
|
|
12
|
+
location: requestUrl.replace("/files/", "/private/"),
|
|
13
|
+
"content-type": asset.getContentType(),
|
|
14
|
+
"cache-control": "public, max-age=2592000"
|
|
15
|
+
})
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
18
|
}
|
|
19
|
+
export { RedirectToPrivateUrlOutputStrategy };
|
|
19
20
|
|
|
20
21
|
//# sourceMappingURL=RedirectToPrivateUrlOutputStrategy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"delivery/AssetDelivery/privateFiles/RedirectToPrivateUrlOutputStrategy.js","sources":["../../../../src/delivery/AssetDelivery/privateFiles/RedirectToPrivateUrlOutputStrategy.ts"],"sourcesContent":["import type { Asset, AssetOutputStrategy, AssetRequest } from \"~/delivery/index.js\";\nimport { AssetReply } from \"~/delivery/index.js\";\nimport { ResponseHeaders } from \"@webiny/handler\";\n\nexport class RedirectToPrivateUrlOutputStrategy implements AssetOutputStrategy {\n private assetRequest: AssetRequest;\n\n constructor(assetRequest: AssetRequest) {\n this.assetRequest = assetRequest;\n }\n\n async output(asset: Asset): Promise<AssetReply> {\n const requestUrl = this.assetRequest.getContext().url;\n\n return new AssetReply({\n code: 301,\n headers: ResponseHeaders.create({\n location: requestUrl.replace(\"/files/\", \"/private/\"),\n \"content-type\": asset.getContentType(),\n \"cache-control\": `public, max-age=${86400 * 30}`\n })\n });\n }\n}\n"],"names":["RedirectToPrivateUrlOutputStrategy","assetRequest","asset","requestUrl","AssetReply","ResponseHeaders"],"mappings":";;AAIO,MAAMA;IAGT,YAAYC,YAA0B,CAAE;QACpC,IAAI,CAAC,YAAY,GAAGA;IACxB;IAEA,MAAM,OAAOC,KAAY,EAAuB;QAC5C,MAAMC,aAAa,IAAI,CAAC,YAAY,CAAC,UAAU,GAAG,GAAG;QAErD,OAAO,IAAIC,WAAW;YAClB,MAAM;YACN,SAASC,gBAAgB,MAAM,CAAC;gBAC5B,UAAUF,WAAW,OAAO,CAAC,WAAW;gBACxC,gBAAgBD,MAAM,cAAc;gBACpC,iBAAiB;YACrB;QACJ;IACJ;AACJ"}
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { AssetReply } from "../../index.js";
|
|
2
2
|
import { ResponseHeaders } from "@webiny/handler";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
3
|
+
class RedirectToPublicUrlOutputStrategy {
|
|
4
|
+
constructor(assetRequest){
|
|
5
|
+
this.assetRequest = assetRequest;
|
|
6
|
+
}
|
|
7
|
+
async output(asset) {
|
|
8
|
+
const requestUrl = this.assetRequest.getContext().url;
|
|
9
|
+
return new AssetReply({
|
|
10
|
+
code: 301,
|
|
11
|
+
headers: ResponseHeaders.create({
|
|
12
|
+
location: requestUrl.replace("/private/", "/files/"),
|
|
13
|
+
"content-type": asset.getContentType(),
|
|
14
|
+
"cache-control": "public, max-age=2592000"
|
|
15
|
+
})
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
18
|
}
|
|
19
|
+
export { RedirectToPublicUrlOutputStrategy };
|
|
19
20
|
|
|
20
21
|
//# sourceMappingURL=RedirectToPublicUrlOutputStrategy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"delivery/AssetDelivery/privateFiles/RedirectToPublicUrlOutputStrategy.js","sources":["../../../../src/delivery/AssetDelivery/privateFiles/RedirectToPublicUrlOutputStrategy.ts"],"sourcesContent":["import type { Asset, AssetOutputStrategy, AssetRequest } from \"~/delivery/index.js\";\nimport { AssetReply } from \"~/delivery/index.js\";\nimport { ResponseHeaders } from \"@webiny/handler\";\n\nexport class RedirectToPublicUrlOutputStrategy implements AssetOutputStrategy {\n private assetRequest: AssetRequest;\n\n constructor(assetRequest: AssetRequest) {\n this.assetRequest = assetRequest;\n }\n\n async output(asset: Asset): Promise<AssetReply> {\n const requestUrl = this.assetRequest.getContext().url;\n\n return new AssetReply({\n code: 301,\n headers: ResponseHeaders.create({\n location: requestUrl.replace(\"/private/\", \"/files/\"),\n \"content-type\": asset.getContentType(),\n \"cache-control\": `public, max-age=${86400 * 30}`\n })\n });\n }\n}\n"],"names":["RedirectToPublicUrlOutputStrategy","assetRequest","asset","requestUrl","AssetReply","ResponseHeaders"],"mappings":";;AAIO,MAAMA;IAGT,YAAYC,YAA0B,CAAE;QACpC,IAAI,CAAC,YAAY,GAAGA;IACxB;IAEA,MAAM,OAAOC,KAAY,EAAuB;QAC5C,MAAMC,aAAa,IAAI,CAAC,YAAY,CAAC,UAAU,GAAG,GAAG;QAErD,OAAO,IAAIC,WAAW;YAClB,MAAM;YACN,SAASC,gBAAgB,MAAM,CAAC;gBAC5B,UAAUF,WAAW,OAAO,CAAC,aAAa;gBAC1C,gBAAgBD,MAAM,cAAc;gBACpC,iBAAiB;YACrB;QACJ;IACJ;AACJ"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
class PassthroughAssetProcessor {
|
|
2
|
+
process(assetRequest, asset) {
|
|
3
|
+
return Promise.resolve(asset);
|
|
4
|
+
}
|
|
5
5
|
}
|
|
6
|
+
export { PassthroughAssetProcessor };
|
|
6
7
|
|
|
7
8
|
//# sourceMappingURL=PassthroughAssetProcessor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"delivery/AssetDelivery/transformation/PassthroughAssetProcessor.js","sources":["../../../../src/delivery/AssetDelivery/transformation/PassthroughAssetProcessor.ts"],"sourcesContent":["import type { Asset, AssetProcessor, AssetRequest } from \"~/delivery/index.js\";\n\nexport class PassthroughAssetProcessor implements AssetProcessor {\n process(assetRequest: AssetRequest, asset: Asset): Promise<Asset> {\n return Promise.resolve(asset);\n }\n}\n"],"names":["PassthroughAssetProcessor","assetRequest","asset","Promise"],"mappings":"AAEO,MAAMA;IACT,QAAQC,YAA0B,EAAEC,KAAY,EAAkB;QAC9D,OAAOC,QAAQ,OAAO,CAACD;IAC3B;AACJ"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
class PassthroughAssetTransformationStrategy {
|
|
2
|
+
transform(assetRequest, asset) {
|
|
3
|
+
return Promise.resolve(asset);
|
|
4
|
+
}
|
|
5
5
|
}
|
|
6
|
+
export { PassthroughAssetTransformationStrategy };
|
|
6
7
|
|
|
7
8
|
//# sourceMappingURL=PassthroughAssetTransformationStrategy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"delivery/AssetDelivery/transformation/PassthroughAssetTransformationStrategy.js","sources":["../../../../src/delivery/AssetDelivery/transformation/PassthroughAssetTransformationStrategy.ts"],"sourcesContent":["import type { Asset, AssetTransformationStrategy, AssetRequest } from \"~/delivery/index.js\";\n\nexport class PassthroughAssetTransformationStrategy implements AssetTransformationStrategy {\n transform(assetRequest: AssetRequest, asset: Asset): Promise<Asset> {\n return Promise.resolve(asset);\n }\n}\n"],"names":["PassthroughAssetTransformationStrategy","assetRequest","asset","Promise"],"mappings":"AAEO,MAAMA;IACT,UAAUC,YAA0B,EAAEC,KAAY,EAAkB;QAChE,OAAOC,QAAQ,OAAO,CAACD;IAC3B;AACJ"}
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
console.log("Skip transformations; original asset was requested.");
|
|
13
|
-
return asset;
|
|
1
|
+
class TransformationAssetProcessor {
|
|
2
|
+
constructor(strategy){
|
|
3
|
+
this.strategy = strategy;
|
|
4
|
+
}
|
|
5
|
+
async process(assetRequest, asset) {
|
|
6
|
+
const { original } = assetRequest.getOptions();
|
|
7
|
+
if (original) {
|
|
8
|
+
console.log("Skip transformations; original asset was requested.");
|
|
9
|
+
return asset;
|
|
10
|
+
}
|
|
11
|
+
return this.strategy.transform(assetRequest, asset);
|
|
14
12
|
}
|
|
15
|
-
return this.strategy.transform(assetRequest, asset);
|
|
16
|
-
}
|
|
17
13
|
}
|
|
14
|
+
export { TransformationAssetProcessor };
|
|
18
15
|
|
|
19
16
|
//# sourceMappingURL=TransformationAssetProcessor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"delivery/AssetDelivery/transformation/TransformationAssetProcessor.js","sources":["../../../../src/delivery/AssetDelivery/transformation/TransformationAssetProcessor.ts"],"sourcesContent":["import type {\n Asset,\n AssetProcessor,\n AssetRequest,\n AssetTransformationStrategy\n} from \"~/delivery/index.js\";\n\nexport class TransformationAssetProcessor implements AssetProcessor {\n private strategy: AssetTransformationStrategy;\n\n constructor(strategy: AssetTransformationStrategy) {\n this.strategy = strategy;\n }\n\n async process(assetRequest: AssetRequest, asset: Asset): Promise<Asset> {\n const { original } = assetRequest.getOptions();\n\n // If the `original` image was requested, we skip all transformations.\n if (original) {\n console.log(\"Skip transformations; original asset was requested.\");\n return asset;\n }\n\n return this.strategy.transform(assetRequest, asset);\n }\n}\n"],"names":["TransformationAssetProcessor","strategy","assetRequest","asset","original","console"],"mappings":"AAOO,MAAMA;IAGT,YAAYC,QAAqC,CAAE;QAC/C,IAAI,CAAC,QAAQ,GAAGA;IACpB;IAEA,MAAM,QAAQC,YAA0B,EAAEC,KAAY,EAAkB;QACpE,MAAM,EAAEC,QAAQ,EAAE,GAAGF,aAAa,UAAU;QAG5C,IAAIE,UAAU;YACVC,QAAQ,GAAG,CAAC;YACZ,OAAOF;QACX;QAEA,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,CAACD,cAAcC;IACjD;AACJ"}
|
package/delivery/index.js
CHANGED
|
@@ -8,5 +8,3 @@ export * from "./AssetDelivery/SetCacheControlHeaders.js";
|
|
|
8
8
|
export * from "./AssetDelivery/SetResponseHeaders.js";
|
|
9
9
|
export * from "./AssetDelivery/privateFiles/PublicCache.js";
|
|
10
10
|
export * from "./AssetDelivery/privateFiles/PrivateCache.js";
|
|
11
|
-
|
|
12
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,114 +1,83 @@
|
|
|
1
|
-
import { createHandlerOnRequest, createModifyFastifyPlugin, createRoute
|
|
1
|
+
import { ResponseHeaders, createHandlerOnRequest, createModifyFastifyPlugin, createRoute } from "@webiny/handler";
|
|
2
2
|
import { PrivateFilesAssetProcessor } from "./AssetDelivery/privateFiles/PrivateFilesAssetProcessor.js";
|
|
3
3
|
import { PrivateAuthenticatedAuthorizer } from "./AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.js";
|
|
4
4
|
import { PrivateFileAssetRequestResolver } from "./AssetDelivery/privateFiles/PrivateFileAssetRequestResolver.js";
|
|
5
5
|
import { AssetDeliveryConfigBuilder, AssetDeliveryConfigModifierPlugin, FilesAssetRequestResolver, createAssetDeliveryConfig } from "./index.js";
|
|
6
6
|
const noCacheHeaders = ResponseHeaders.create({
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
"content-type": "application/json",
|
|
8
|
+
"cache-control": "no-cache, no-store, must-revalidate"
|
|
9
9
|
});
|
|
10
10
|
function assertAssetRequestWasResolved(request) {
|
|
11
|
-
|
|
12
|
-
throw new Error("Not an AssetRequest!");
|
|
13
|
-
}
|
|
11
|
+
if (void 0 === request) throw new Error("Not an AssetRequest!");
|
|
14
12
|
}
|
|
15
13
|
function assertAssetWasResolved(asset) {
|
|
16
|
-
|
|
17
|
-
throw new Error("Not an Asset!");
|
|
18
|
-
}
|
|
14
|
+
if (void 0 === asset) throw new Error("Not an Asset!");
|
|
19
15
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
const outputStrategy = configBuilder.getAssetOutputStrategy(context, resolvedRequest, resolvedAsset);
|
|
86
|
-
resolvedAsset.setOutputStrategy(outputStrategy);
|
|
87
|
-
const assetProcessor = configBuilder.getAssetProcessor(context);
|
|
88
|
-
const processedAsset = await assetProcessor.process(resolvedRequest, resolvedAsset);
|
|
89
|
-
|
|
90
|
-
// Get reply object (runs the output strategy under the hood).
|
|
91
|
-
console.log(`Output asset (size: ${processedAsset.getSize()} bytes).`);
|
|
92
|
-
return outputAsset(reply, processedAsset);
|
|
93
|
-
}, {
|
|
94
|
-
override: true
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
app.webiny.plugins.register(handlerOnRequest, deliveryRoute);
|
|
98
|
-
}),
|
|
99
|
-
// Create the default configuration
|
|
100
|
-
createAssetDeliveryConfig(config => {
|
|
101
|
-
config.decorateAssetRequestResolver(() => {
|
|
102
|
-
// This resolver works with `/files/*` requests.
|
|
103
|
-
return new FilesAssetRequestResolver();
|
|
104
|
-
});
|
|
105
|
-
config.decorateAssetRequestResolver(({
|
|
106
|
-
assetRequestResolver
|
|
107
|
-
}) => {
|
|
108
|
-
// This resolver works with `/private/*` requests.
|
|
109
|
-
return new PrivateFileAssetRequestResolver(assetRequestResolver);
|
|
110
|
-
});
|
|
111
|
-
})];
|
|
16
|
+
const setupAssetDelivery = ()=>{
|
|
17
|
+
const outputAsset = async (reply, asset)=>{
|
|
18
|
+
const assetReply = await asset.output();
|
|
19
|
+
const headers = assetReply.getHeaders();
|
|
20
|
+
headers.set("x-webiny-base64-encoded", "true");
|
|
21
|
+
reply.code(assetReply.getCode());
|
|
22
|
+
reply.headers(headers.getHeaders());
|
|
23
|
+
return reply.send(await assetReply.getBody());
|
|
24
|
+
};
|
|
25
|
+
return [
|
|
26
|
+
createModifyFastifyPlugin((app)=>{
|
|
27
|
+
const configBuilder = new AssetDeliveryConfigBuilder();
|
|
28
|
+
const configPlugins = app.webiny.plugins.byType(AssetDeliveryConfigModifierPlugin.type);
|
|
29
|
+
configPlugins.forEach((configPlugin)=>configPlugin.buildConfig(configBuilder));
|
|
30
|
+
let resolvedRequest;
|
|
31
|
+
let resolvedAsset;
|
|
32
|
+
const handlerOnRequest = createHandlerOnRequest(async (request, reply)=>{
|
|
33
|
+
const requestResolver = configBuilder.getAssetRequestResolver();
|
|
34
|
+
resolvedRequest = await requestResolver.resolve(request);
|
|
35
|
+
if (!resolvedRequest) {
|
|
36
|
+
reply.code(404).headers(noCacheHeaders.getHeaders()).send({
|
|
37
|
+
error: "Unable to resolve the request!"
|
|
38
|
+
}).hijack();
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
const container = app.webiny.container;
|
|
42
|
+
const assetResolver = configBuilder.getAssetResolver(container);
|
|
43
|
+
resolvedAsset = await assetResolver.resolve(resolvedRequest);
|
|
44
|
+
if (!resolvedAsset) {
|
|
45
|
+
reply.code(404).headers(noCacheHeaders.getHeaders()).send({
|
|
46
|
+
error: "Asset not found!"
|
|
47
|
+
}).hijack();
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
request.headers = {
|
|
51
|
+
...request.headers,
|
|
52
|
+
"x-tenant": resolvedAsset.getTenant()
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
const deliveryRoute = createRoute(({ onGet, context })=>{
|
|
56
|
+
onGet("*", async (_, reply)=>{
|
|
57
|
+
assertAssetRequestWasResolved(resolvedRequest);
|
|
58
|
+
assertAssetWasResolved(resolvedAsset);
|
|
59
|
+
if (context.wcp.canUsePrivateFiles()) configBuilder.decorateAssetProcessor(({ assetProcessor, context })=>{
|
|
60
|
+
const assetAuthorizer = new PrivateAuthenticatedAuthorizer(context);
|
|
61
|
+
return new PrivateFilesAssetProcessor(context, assetAuthorizer, assetProcessor);
|
|
62
|
+
});
|
|
63
|
+
const outputStrategy = configBuilder.getAssetOutputStrategy(context, resolvedRequest, resolvedAsset);
|
|
64
|
+
resolvedAsset.setOutputStrategy(outputStrategy);
|
|
65
|
+
const assetProcessor = configBuilder.getAssetProcessor(context);
|
|
66
|
+
const processedAsset = await assetProcessor.process(resolvedRequest, resolvedAsset);
|
|
67
|
+
console.log(`Output asset (size: ${processedAsset.getSize()} bytes).`);
|
|
68
|
+
return outputAsset(reply, processedAsset);
|
|
69
|
+
}, {
|
|
70
|
+
override: true
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
app.webiny.plugins.register(handlerOnRequest, deliveryRoute);
|
|
74
|
+
}),
|
|
75
|
+
createAssetDeliveryConfig((config)=>{
|
|
76
|
+
config.decorateAssetRequestResolver(()=>new FilesAssetRequestResolver());
|
|
77
|
+
config.decorateAssetRequestResolver(({ assetRequestResolver })=>new PrivateFileAssetRequestResolver(assetRequestResolver));
|
|
78
|
+
})
|
|
79
|
+
];
|
|
112
80
|
};
|
|
81
|
+
export { setupAssetDelivery };
|
|
113
82
|
|
|
114
83
|
//# sourceMappingURL=setupAssetDelivery.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createHandlerOnRequest","createModifyFastifyPlugin","createRoute","ResponseHeaders","PrivateFilesAssetProcessor","PrivateAuthenticatedAuthorizer","PrivateFileAssetRequestResolver","AssetDeliveryConfigBuilder","AssetDeliveryConfigModifierPlugin","FilesAssetRequestResolver","createAssetDeliveryConfig","noCacheHeaders","create","assertAssetRequestWasResolved","request","undefined","Error","assertAssetWasResolved","asset","setupAssetDelivery","outputAsset","reply","assetReply","output","headers","getHeaders","set","code","getCode","send","getBody","app","configBuilder","configPlugins","webiny","plugins","byType","type","forEach","configPlugin","buildConfig","resolvedRequest","resolvedAsset","handlerOnRequest","requestResolver","getAssetRequestResolver","resolve","error","hijack","container","assetResolver","getAssetResolver","getTenant","deliveryRoute","onGet","context","_","wcp","canUsePrivateFiles","decorateAssetProcessor","assetProcessor","assetAuthorizer","outputStrategy","getAssetOutputStrategy","setOutputStrategy","getAssetProcessor","processedAsset","process","console","log","getSize","override","register","config","decorateAssetRequestResolver","assetRequestResolver"],"sources":["setupAssetDelivery.ts"],"sourcesContent":["import {\n createHandlerOnRequest,\n createModifyFastifyPlugin,\n createRoute,\n ResponseHeaders\n} from \"@webiny/handler\";\nimport { PrivateFilesAssetProcessor } from \"./AssetDelivery/privateFiles/PrivateFilesAssetProcessor.js\";\nimport { PrivateAuthenticatedAuthorizer } from \"./AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.js\";\nimport { PrivateFileAssetRequestResolver } from \"./AssetDelivery/privateFiles/PrivateFileAssetRequestResolver.js\";\nimport type { Asset, AssetRequest } from \"./index.js\";\nimport {\n AssetDeliveryConfigBuilder,\n AssetDeliveryConfigModifierPlugin,\n FilesAssetRequestResolver,\n createAssetDeliveryConfig\n} from \"./index.js\";\nimport type { Reply } from \"@webiny/handler/types.js\";\nimport type { ApiCoreContext } from \"@webiny/api-core/types/core.js\";\n\nconst noCacheHeaders = ResponseHeaders.create({\n \"content-type\": \"application/json\",\n \"cache-control\": \"no-cache, no-store, must-revalidate\"\n});\n\nfunction assertAssetRequestWasResolved(request: any): asserts request is AssetRequest {\n if (request === undefined) {\n throw new Error(\"Not an AssetRequest!\");\n }\n}\n\nfunction assertAssetWasResolved(asset: Asset | undefined): asserts asset is Asset {\n if (asset === undefined) {\n throw new Error(\"Not an Asset!\");\n }\n}\n\nexport const setupAssetDelivery = () => {\n const outputAsset = async (reply: Reply, asset: Asset) => {\n const assetReply = await asset.output();\n const headers = assetReply.getHeaders();\n\n // Set default headers.\n headers.set(\"x-webiny-base64-encoded\", \"true\");\n\n reply.code(assetReply.getCode());\n reply.headers(headers.getHeaders());\n return reply.send(await assetReply.getBody());\n };\n\n return [\n createModifyFastifyPlugin(app => {\n // Config builder allows config modification via plugins.\n const configBuilder = new AssetDeliveryConfigBuilder();\n\n // Apply config modifications.\n const configPlugins = app.webiny.plugins.byType<AssetDeliveryConfigModifierPlugin>(\n AssetDeliveryConfigModifierPlugin.type\n );\n\n configPlugins.forEach(configPlugin => configPlugin.buildConfig(configBuilder));\n\n let resolvedRequest: AssetRequest | undefined;\n let resolvedAsset: Asset | undefined;\n\n // Create a `HandlerOnRequest` plugin to resolve `tenant`, and allow the system to bootstrap.\n const handlerOnRequest = createHandlerOnRequest(async (request, reply) => {\n const requestResolver = configBuilder.getAssetRequestResolver();\n resolvedRequest = await requestResolver.resolve(request);\n\n if (!resolvedRequest) {\n reply\n .code(404)\n .headers(noCacheHeaders.getHeaders())\n .send({ error: \"Unable to resolve the request!\" })\n .hijack();\n\n return false;\n }\n\n const container = app.webiny.container;\n const assetResolver = configBuilder.getAssetResolver(container);\n\n resolvedAsset = await assetResolver.resolve(resolvedRequest);\n\n if (!resolvedAsset) {\n reply\n .code(404)\n .headers(noCacheHeaders.getHeaders())\n .send({ error: \"Asset not found!\" })\n .hijack();\n\n return false;\n }\n\n request.headers = {\n ...request.headers,\n \"x-tenant\": resolvedAsset.getTenant()\n };\n\n return;\n });\n\n // Create the `Route` plugin, to handle all GET requests, and output the resolved asset.\n const deliveryRoute = createRoute<ApiCoreContext>(({ onGet, context }) => {\n onGet(\n \"*\",\n async (_, reply) => {\n assertAssetRequestWasResolved(resolvedRequest);\n assertAssetWasResolved(resolvedAsset);\n\n if (context.wcp.canUsePrivateFiles()) {\n configBuilder.decorateAssetProcessor(({ assetProcessor, context }) => {\n // Currently, we only have one authorizer.\n const assetAuthorizer = new PrivateAuthenticatedAuthorizer(context);\n\n return new PrivateFilesAssetProcessor(\n context,\n assetAuthorizer,\n assetProcessor\n );\n });\n }\n\n const outputStrategy = configBuilder.getAssetOutputStrategy(\n context,\n resolvedRequest,\n resolvedAsset\n );\n\n resolvedAsset.setOutputStrategy(outputStrategy);\n\n const assetProcessor = configBuilder.getAssetProcessor(context);\n\n const processedAsset = await assetProcessor.process(\n resolvedRequest,\n resolvedAsset\n );\n\n // Get reply object (runs the output strategy under the hood).\n console.log(`Output asset (size: ${processedAsset.getSize()} bytes).`);\n return outputAsset(reply, processedAsset);\n },\n { override: true }\n );\n });\n\n app.webiny.plugins.register(handlerOnRequest, deliveryRoute);\n }),\n // Create the default configuration\n createAssetDeliveryConfig(config => {\n config.decorateAssetRequestResolver(() => {\n // This resolver works with `/files/*` requests.\n return new FilesAssetRequestResolver();\n });\n\n config.decorateAssetRequestResolver(({ assetRequestResolver }) => {\n // This resolver works with `/private/*` requests.\n return new PrivateFileAssetRequestResolver(assetRequestResolver);\n });\n })\n ];\n};\n"],"mappings":"AAAA,SACIA,sBAAsB,EACtBC,yBAAyB,EACzBC,WAAW,EACXC,eAAe,QACZ,iBAAiB;AACxB,SAASC,0BAA0B;AACnC,SAASC,8BAA8B;AACvC,SAASC,+BAA+B;AAExC,SACIC,0BAA0B,EAC1BC,iCAAiC,EACjCC,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A,OAAO,IAAIrE,+BAA+B,CAACqE,oBAAoB,CAAC;IACpE,CAAC,CAAC;EACN,CAAC,CAAC,CACL;AACL,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"delivery/setupAssetDelivery.js","sources":["../../src/delivery/setupAssetDelivery.ts"],"sourcesContent":["import {\n createHandlerOnRequest,\n createModifyFastifyPlugin,\n createRoute,\n ResponseHeaders\n} from \"@webiny/handler\";\nimport { PrivateFilesAssetProcessor } from \"./AssetDelivery/privateFiles/PrivateFilesAssetProcessor.js\";\nimport { PrivateAuthenticatedAuthorizer } from \"./AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.js\";\nimport { PrivateFileAssetRequestResolver } from \"./AssetDelivery/privateFiles/PrivateFileAssetRequestResolver.js\";\nimport type { Asset, AssetRequest } from \"./index.js\";\nimport {\n AssetDeliveryConfigBuilder,\n AssetDeliveryConfigModifierPlugin,\n FilesAssetRequestResolver,\n createAssetDeliveryConfig\n} from \"./index.js\";\nimport type { Reply } from \"@webiny/handler/types.js\";\nimport type { ApiCoreContext } from \"@webiny/api-core/types/core.js\";\n\nconst noCacheHeaders = ResponseHeaders.create({\n \"content-type\": \"application/json\",\n \"cache-control\": \"no-cache, no-store, must-revalidate\"\n});\n\nfunction assertAssetRequestWasResolved(request: any): asserts request is AssetRequest {\n if (request === undefined) {\n throw new Error(\"Not an AssetRequest!\");\n }\n}\n\nfunction assertAssetWasResolved(asset: Asset | undefined): asserts asset is Asset {\n if (asset === undefined) {\n throw new Error(\"Not an Asset!\");\n }\n}\n\nexport const setupAssetDelivery = () => {\n const outputAsset = async (reply: Reply, asset: Asset) => {\n const assetReply = await asset.output();\n const headers = assetReply.getHeaders();\n\n // Set default headers.\n headers.set(\"x-webiny-base64-encoded\", \"true\");\n\n reply.code(assetReply.getCode());\n reply.headers(headers.getHeaders());\n return reply.send(await assetReply.getBody());\n };\n\n return [\n createModifyFastifyPlugin(app => {\n // Config builder allows config modification via plugins.\n const configBuilder = new AssetDeliveryConfigBuilder();\n\n // Apply config modifications.\n const configPlugins = app.webiny.plugins.byType<AssetDeliveryConfigModifierPlugin>(\n AssetDeliveryConfigModifierPlugin.type\n );\n\n configPlugins.forEach(configPlugin => configPlugin.buildConfig(configBuilder));\n\n let resolvedRequest: AssetRequest | undefined;\n let resolvedAsset: Asset | undefined;\n\n // Create a `HandlerOnRequest` plugin to resolve `tenant`, and allow the system to bootstrap.\n const handlerOnRequest = createHandlerOnRequest(async (request, reply) => {\n const requestResolver = configBuilder.getAssetRequestResolver();\n resolvedRequest = await requestResolver.resolve(request);\n\n if (!resolvedRequest) {\n reply\n .code(404)\n .headers(noCacheHeaders.getHeaders())\n .send({ error: \"Unable to resolve the request!\" })\n .hijack();\n\n return false;\n }\n\n const container = app.webiny.container;\n const assetResolver = configBuilder.getAssetResolver(container);\n\n resolvedAsset = await assetResolver.resolve(resolvedRequest);\n\n if (!resolvedAsset) {\n reply\n .code(404)\n .headers(noCacheHeaders.getHeaders())\n .send({ error: \"Asset not found!\" })\n .hijack();\n\n return false;\n }\n\n request.headers = {\n ...request.headers,\n \"x-tenant\": resolvedAsset.getTenant()\n };\n\n return;\n });\n\n // Create the `Route` plugin, to handle all GET requests, and output the resolved asset.\n const deliveryRoute = createRoute<ApiCoreContext>(({ onGet, context }) => {\n onGet(\n \"*\",\n async (_, reply) => {\n assertAssetRequestWasResolved(resolvedRequest);\n assertAssetWasResolved(resolvedAsset);\n\n if (context.wcp.canUsePrivateFiles()) {\n configBuilder.decorateAssetProcessor(({ assetProcessor, context }) => {\n // Currently, we only have one authorizer.\n const assetAuthorizer = new PrivateAuthenticatedAuthorizer(context);\n\n return new PrivateFilesAssetProcessor(\n context,\n assetAuthorizer,\n assetProcessor\n );\n });\n }\n\n const outputStrategy = configBuilder.getAssetOutputStrategy(\n context,\n resolvedRequest,\n resolvedAsset\n );\n\n resolvedAsset.setOutputStrategy(outputStrategy);\n\n const assetProcessor = configBuilder.getAssetProcessor(context);\n\n const processedAsset = await assetProcessor.process(\n resolvedRequest,\n resolvedAsset\n );\n\n // Get reply object (runs the output strategy under the hood).\n console.log(`Output asset (size: ${processedAsset.getSize()} bytes).`);\n return outputAsset(reply, processedAsset);\n },\n { override: true }\n );\n });\n\n app.webiny.plugins.register(handlerOnRequest, deliveryRoute);\n }),\n // Create the default configuration\n createAssetDeliveryConfig(config => {\n config.decorateAssetRequestResolver(() => {\n // This resolver works with `/files/*` requests.\n return new FilesAssetRequestResolver();\n });\n\n config.decorateAssetRequestResolver(({ assetRequestResolver }) => {\n // This resolver works with `/private/*` requests.\n return new PrivateFileAssetRequestResolver(assetRequestResolver);\n });\n })\n ];\n};\n"],"names":["noCacheHeaders","ResponseHeaders","assertAssetRequestWasResolved","request","undefined","Error","assertAssetWasResolved","asset","setupAssetDelivery","outputAsset","reply","assetReply","headers","createModifyFastifyPlugin","app","configBuilder","AssetDeliveryConfigBuilder","configPlugins","AssetDeliveryConfigModifierPlugin","configPlugin","resolvedRequest","resolvedAsset","handlerOnRequest","createHandlerOnRequest","requestResolver","container","assetResolver","deliveryRoute","createRoute","onGet","context","_","assetProcessor","assetAuthorizer","PrivateAuthenticatedAuthorizer","PrivateFilesAssetProcessor","outputStrategy","processedAsset","console","createAssetDeliveryConfig","config","FilesAssetRequestResolver","assetRequestResolver","PrivateFileAssetRequestResolver"],"mappings":";;;;;AAmBA,MAAMA,iBAAiBC,gBAAgB,MAAM,CAAC;IAC1C,gBAAgB;IAChB,iBAAiB;AACrB;AAEA,SAASC,8BAA8BC,OAAY;IAC/C,IAAIA,AAAYC,WAAZD,SACA,MAAM,IAAIE,MAAM;AAExB;AAEA,SAASC,uBAAuBC,KAAwB;IACpD,IAAIA,AAAUH,WAAVG,OACA,MAAM,IAAIF,MAAM;AAExB;AAEO,MAAMG,qBAAqB;IAC9B,MAAMC,cAAc,OAAOC,OAAcH;QACrC,MAAMI,aAAa,MAAMJ,MAAM,MAAM;QACrC,MAAMK,UAAUD,WAAW,UAAU;QAGrCC,QAAQ,G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,CAAC,kBAAkB,IAC9Bf,cAAc,sBAAsB,CAAC,CAAC,EAAEiB,cAAc,EAAEF,OAAO,EAAE;wBAE7D,MAAMG,kBAAkB,IAAIC,+BAA+BJ;wBAE3D,OAAO,IAAIK,2BACPL,SACAG,iBACAD;oBAER;oBAGJ,MAAMI,iBAAiBrB,cAAc,sBAAsB,CACvDe,SACAV,iBACAC;oBAGJA,cAAc,iBAAiB,CAACe;oBAEhC,MAAMJ,iBAAiBjB,cAAc,iBAAiB,CAACe;oBAEvD,MAAMO,iBAAiB,MAAML,eAAe,OAAO,CAC/CZ,iBACAC;oBAIJiB,QAAQ,GAAG,CAAC,CAAC,oBAAoB,EAAED,eAAe,OAAO,GAAG,QAAQ,CAAC;oBACrE,OAAO5B,YAAYC,OAAO2B;gBAC9B,GACA;oBAAE,UAAU;gBAAK;YAEzB;YAEAvB,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAACQ,kBAAkBK;QAClD;QAEAY,0BAA0BC,CAAAA;YACtBA,OAAO,4BAA4B,CAAC,IAEzB,IAAIC;YAGfD,OAAO,4BAA4B,CAAC,CAAC,EAAEE,oBAAoB,EAAE,GAElD,IAAIC,gCAAgCD;QAEnD;KACH;AACL"}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* This will be registered via container.registerInstance in the composite feature.
|
|
5
|
-
*/
|
|
6
|
-
export const FileModel = createAbstraction("FileModel");
|
|
2
|
+
const FileModel = createAbstraction("FileModel");
|
|
3
|
+
export { FileModel };
|
|
7
4
|
|
|
8
5
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"domain/file/abstractions.js","sources":["../../../src/domain/file/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types\";\n\n/**\n * FileModel abstraction - represents the fmFile CMS model.\n * This will be registered via container.registerInstance in the composite feature.\n */\nexport const FileModel = createAbstraction<CmsModel>(\"FileModel\");\n\nexport namespace FileModel {\n export type Interface = CmsModel;\n}\n"],"names":["FileModel","createAbstraction"],"mappings":";AAOO,MAAMA,YAAYC,kBAA4B"}
|