@webiny/api-file-manager 6.6.0-alpha.0 → 6.6.0-alpha.10
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/FileManagerAppFeature.js +4 -4
- package/FileManagerAppFeature.js.map +1 -1
- package/delivery/AssetDelivery/AssetRequest.d.ts +1 -1
- package/delivery/AssetDelivery/AssetRequest.js.map +1 -1
- package/delivery/AssetDeliveryRoute.d.ts +16 -6
- package/delivery/AssetDeliveryRoute.js +38 -34
- package/delivery/AssetDeliveryRoute.js.map +1 -1
- package/domain/file/abstractions.d.ts +13 -5
- package/domain/file/abstractions.js +2 -2
- package/domain/file/abstractions.js.map +1 -1
- package/domain/file/errors.d.ts +10 -0
- package/domain/file/errors.js +9 -1
- package/domain/file/errors.js.map +1 -1
- package/domain/file/file.model.d.ts +3 -3
- package/domain/file/file.model.js +12 -7
- package/domain/file/file.model.js.map +1 -1
- package/domain/file/validateFileKey.d.ts +10 -0
- package/domain/file/validateFileKey.js +15 -0
- package/domain/file/validateFileKey.js.map +1 -0
- package/domain/settings/validation.d.ts +1 -1
- package/domain/settings/validation.js +3 -10
- package/domain/settings/validation.js.map +1 -1
- package/exports/api/file-manager/file.d.ts +2 -1
- package/exports/api/file-manager/file.js +2 -1
- package/features/FileManagerFeature.js +2 -0
- package/features/FileManagerFeature.js.map +1 -1
- package/features/assetDelivery/abstractions/AssetType.d.ts +17 -0
- package/features/assetDelivery/abstractions/AssetType.js +5 -0
- package/features/assetDelivery/abstractions/AssetType.js.map +1 -0
- package/features/assetDelivery/{transformation → assetTypes/image}/AssetKeyGenerator.d.ts +5 -2
- package/features/assetDelivery/assetTypes/image/AssetKeyGenerator.js +30 -0
- package/features/assetDelivery/assetTypes/image/AssetKeyGenerator.js.map +1 -0
- package/features/assetDelivery/assetTypes/image/ImageAssetType.d.ts +9 -0
- package/features/assetDelivery/assetTypes/image/ImageAssetType.js +18 -0
- package/features/assetDelivery/assetTypes/image/ImageAssetType.js.map +1 -0
- package/features/assetDelivery/assetTypes/image/ImageAssetTypeHandler.d.ts +5 -0
- package/features/assetDelivery/assetTypes/image/ImageAssetTypeHandler.js +5 -0
- package/features/assetDelivery/assetTypes/image/ImageAssetTypeHandler.js.map +1 -0
- package/features/assetDelivery/assetTypes/image/SharpTransformer.d.ts +18 -0
- package/features/assetDelivery/assetTypes/image/SharpTransformer.js +47 -0
- package/features/assetDelivery/assetTypes/image/SharpTransformer.js.map +1 -0
- package/features/assetDelivery/assetTypes/image/WidthCollection.js.map +1 -0
- package/features/assetDelivery/assetTypes/image/imageFormat.d.ts +26 -0
- package/features/assetDelivery/assetTypes/image/imageFormat.js +51 -0
- package/features/assetDelivery/assetTypes/image/imageFormat.js.map +1 -0
- package/features/assetDelivery/assetTypes/image/imageTypes.d.ts +39 -0
- package/features/assetDelivery/assetTypes/image/imageTypes.js +0 -0
- package/features/assetDelivery/assetTypes/image/index.d.ts +5 -0
- package/features/assetDelivery/assetTypes/image/index.js +4 -0
- package/features/assetDelivery/assetTypes/image/normalizeImageOptions.d.ts +6 -0
- package/features/assetDelivery/assetTypes/image/normalizeImageOptions.js +56 -0
- package/features/assetDelivery/assetTypes/image/normalizeImageOptions.js.map +1 -0
- package/features/assetDelivery/assetTypes/image/transformImage.d.ts +59 -0
- package/features/assetDelivery/assetTypes/image/transformImage.js +146 -0
- package/features/assetDelivery/assetTypes/image/transformImage.js.map +1 -0
- package/features/assetDelivery/assetTypes/image/utils.d.ts +26 -0
- package/features/assetDelivery/assetTypes/image/utils.js +47 -0
- package/features/assetDelivery/assetTypes/image/utils.js.map +1 -0
- package/features/assetDelivery/feature.js +7 -7
- package/features/assetDelivery/feature.js.map +1 -1
- package/features/assetDelivery/privateFiles/PrivateFilesAssetProcessor.js.map +1 -1
- package/features/assetDelivery/transformation/TransformationAssetProcessor.d.ts +4 -6
- package/features/assetDelivery/transformation/TransformationAssetProcessor.js +13 -11
- package/features/assetDelivery/transformation/TransformationAssetProcessor.js.map +1 -1
- package/features/assetDelivery/transformation/index.d.ts +4 -3
- package/features/assetDelivery/transformation/index.js +3 -3
- package/features/file/CreateFile/CreateFileRepository.d.ts +3 -3
- package/features/file/CreateFile/CreateFileRepository.js +6 -5
- package/features/file/CreateFile/CreateFileRepository.js.map +1 -1
- package/features/file/CreateFile/CreateFileUseCase.js +6 -0
- package/features/file/CreateFile/CreateFileUseCase.js.map +1 -1
- package/features/file/CreateFile/abstractions.d.ts +2 -0
- package/features/file/CreateFile/abstractions.js.map +1 -1
- package/features/file/CreateFilesInBatch/CreateFilesInBatchUseCase.js +8 -0
- package/features/file/CreateFilesInBatch/CreateFilesInBatchUseCase.js.map +1 -1
- package/features/file/CreateFilesInBatch/abstractions.d.ts +2 -0
- package/features/file/CreateFilesInBatch/abstractions.js.map +1 -1
- package/features/file/DeleteFile/DeleteFileRepository.d.ts +3 -3
- package/features/file/DeleteFile/DeleteFileRepository.js +6 -5
- package/features/file/DeleteFile/DeleteFileRepository.js.map +1 -1
- package/features/file/FileModelProvider.d.ts +31 -0
- package/features/file/FileModelProvider.js +22 -0
- package/features/file/FileModelProvider.js.map +1 -0
- package/features/file/FileUrlGenerator/FileUrlGenerator.d.ts +4 -6
- package/features/file/FileUrlGenerator/FileUrlGenerator.js +7 -13
- package/features/file/FileUrlGenerator/FileUrlGenerator.js.map +1 -1
- package/features/file/FileUrlGenerator/SettingsFileUrlPrefixProvider.d.ts +13 -0
- package/features/file/FileUrlGenerator/SettingsFileUrlPrefixProvider.js +29 -0
- package/features/file/FileUrlGenerator/SettingsFileUrlPrefixProvider.js.map +1 -0
- package/features/file/FileUrlGenerator/abstractions.d.ts +13 -2
- package/features/file/FileUrlGenerator/abstractions.js +2 -1
- package/features/file/FileUrlGenerator/abstractions.js.map +1 -1
- package/features/file/FileUrlGenerator/feature.js +2 -0
- package/features/file/FileUrlGenerator/feature.js.map +1 -1
- package/features/file/FileUrlGenerator/index.d.ts +1 -0
- package/features/file/FileUrlGenerator/index.js +1 -1
- package/features/file/GetFile/GetFileRepository.d.ts +3 -3
- package/features/file/GetFile/GetFileRepository.js +6 -5
- package/features/file/GetFile/GetFileRepository.js.map +1 -1
- package/features/file/ListFiles/ListFilesRepository.d.ts +3 -3
- package/features/file/ListFiles/ListFilesRepository.js +8 -7
- package/features/file/ListFiles/ListFilesRepository.js.map +1 -1
- package/features/file/ListImagesByTagTool/ListImagesByTagTool.d.ts +15 -5
- package/features/file/ListImagesByTagTool/ListImagesByTagTool.js +21 -7
- package/features/file/ListImagesByTagTool/ListImagesByTagTool.js.map +1 -1
- package/features/file/ListTags/ListTagsRepository.d.ts +3 -3
- package/features/file/ListTags/ListTagsRepository.js +28 -8
- package/features/file/ListTags/ListTagsRepository.js.map +1 -1
- package/features/file/UpdateFile/UpdateFileRepository.d.ts +3 -3
- package/features/file/UpdateFile/UpdateFileRepository.js +6 -5
- package/features/file/UpdateFile/UpdateFileRepository.js.map +1 -1
- package/features/settings/DefaultSrcPrefix/PublicUrlsDefaultSrcPrefix.d.ts +11 -0
- package/features/settings/DefaultSrcPrefix/PublicUrlsDefaultSrcPrefix.js +20 -0
- package/features/settings/DefaultSrcPrefix/PublicUrlsDefaultSrcPrefix.js.map +1 -0
- package/features/settings/DefaultSrcPrefix/abstractions.d.ts +20 -0
- package/features/settings/DefaultSrcPrefix/abstractions.js +5 -0
- package/features/settings/DefaultSrcPrefix/abstractions.js.map +1 -0
- package/features/settings/DefaultSrcPrefix/feature.d.ts +4 -0
- package/features/settings/DefaultSrcPrefix/feature.js +11 -0
- package/features/settings/DefaultSrcPrefix/feature.js.map +1 -0
- package/features/settings/DefaultSrcPrefix/index.d.ts +1 -0
- package/features/settings/DefaultSrcPrefix/index.js +1 -0
- package/features/settings/GetSettings/GetSettingsUseCase.d.ts +7 -1
- package/features/settings/GetSettings/GetSettingsUseCase.js +15 -8
- package/features/settings/GetSettings/GetSettingsUseCase.js.map +1 -1
- package/features/settings/SettingsInstaller/SettingsInstaller.d.ts +1 -5
- package/features/settings/SettingsInstaller/SettingsInstaller.js +3 -16
- package/features/settings/SettingsInstaller/SettingsInstaller.js.map +1 -1
- package/features/settings/UpdateSettings/UpdateSettingsUseCase.d.ts +9 -1
- package/features/settings/UpdateSettings/UpdateSettingsUseCase.js +16 -4
- package/features/settings/UpdateSettings/UpdateSettingsUseCase.js.map +1 -1
- package/features/upload/WriteFileMetadata/WriteMetadataAfterUpdateHandler.d.ts +11 -0
- package/features/upload/WriteFileMetadata/WriteMetadataAfterUpdateHandler.js +22 -0
- package/features/upload/WriteFileMetadata/WriteMetadataAfterUpdateHandler.js.map +1 -0
- package/features/upload/WriteFileMetadata/feature.js +2 -0
- package/features/upload/WriteFileMetadata/feature.js.map +1 -1
- package/features/upload/utils/FileNormalizer.js +8 -1
- package/features/upload/utils/FileNormalizer.js.map +1 -1
- package/graphql/FmGraphQLSchema.d.ts +4 -5
- package/graphql/FmGraphQLSchema.js +33 -15
- package/graphql/FmGraphQLSchema.js.map +1 -1
- package/package.json +19 -20
- package/features/FileModelContextualSchema.d.ts +0 -13
- package/features/FileModelContextualSchema.js +0 -31
- package/features/FileModelContextualSchema.js.map +0 -1
- package/features/assetDelivery/transformation/AssetKeyGenerator.js +0 -24
- package/features/assetDelivery/transformation/AssetKeyGenerator.js.map +0 -1
- package/features/assetDelivery/transformation/PassthroughAssetTransformationStrategy.d.ts +0 -9
- package/features/assetDelivery/transformation/PassthroughAssetTransformationStrategy.js +0 -13
- package/features/assetDelivery/transformation/PassthroughAssetTransformationStrategy.js.map +0 -1
- package/features/assetDelivery/transformation/WidthCollection.js.map +0 -1
- package/features/assetDelivery/transformation/utils.d.ts +0 -9
- package/features/assetDelivery/transformation/utils.js +0 -31
- package/features/assetDelivery/transformation/utils.js.map +0 -1
- /package/features/assetDelivery/{transformation → assetTypes/image}/WidthCollection.d.ts +0 -0
- /package/features/assetDelivery/{transformation → assetTypes/image}/WidthCollection.js +0 -0
package/FileManagerAppFeature.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { AssetDeliveryFeature } from "./features/assetDelivery/feature.js";
|
|
3
|
-
import {
|
|
3
|
+
import { AssetDeliveryRouteDefinition } from "./delivery/AssetDeliveryRoute.js";
|
|
4
4
|
import { FileModel } from "./domain/file/file.model.js";
|
|
5
5
|
import { FmPermissionsFeature } from "./features/permissions/feature.js";
|
|
6
6
|
import { FileManagerFeature } from "./features/FileManagerFeature.js";
|
|
7
|
-
import {
|
|
7
|
+
import { FileModelProvider } from "./features/file/FileModelProvider.js";
|
|
8
8
|
const FileManagerAppFeature = createFeature({
|
|
9
9
|
name: "FileManagerApp",
|
|
10
10
|
register (container) {
|
|
11
11
|
AssetDeliveryFeature.register(container);
|
|
12
|
-
container.register(
|
|
12
|
+
container.register(AssetDeliveryRouteDefinition);
|
|
13
13
|
container.register(FileModel);
|
|
14
14
|
FmPermissionsFeature.register(container);
|
|
15
15
|
FileManagerFeature.register(container);
|
|
16
|
-
container.register(
|
|
16
|
+
container.register(FileModelProvider);
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
19
|
export { FileManagerAppFeature };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileManagerAppFeature.js","sources":["../src/FileManagerAppFeature.ts"],"sourcesContent":["import { type Container, createFeature } from \"@webiny/feature/api\";\nimport { AssetDeliveryFeature } from \"~/features/assetDelivery/feature.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"FileManagerAppFeature.js","sources":["../src/FileManagerAppFeature.ts"],"sourcesContent":["import { type Container, createFeature } from \"@webiny/feature/api\";\nimport { AssetDeliveryFeature } from \"~/features/assetDelivery/feature.js\";\nimport { AssetDeliveryRouteDefinition } from \"./delivery/AssetDeliveryRoute.js\";\nimport { FileModel } from \"~/domain/file/file.model.js\";\nimport { FmPermissionsFeature } from \"~/features/permissions/feature.js\";\nimport { FileManagerFeature } from \"~/features/FileManagerFeature.js\";\nimport { FileModelProvider } from \"~/features/file/FileModelProvider.js\";\n\nexport const FileManagerAppFeature = createFeature({\n name: \"FileManagerApp\",\n register(container: Container) {\n AssetDeliveryFeature.register(container);\n container.register(AssetDeliveryRouteDefinition);\n container.register(FileModel);\n FmPermissionsFeature.register(container);\n FileManagerFeature.register(container);\n\n // Stateless — the model list is already cached per request by the CMS (`ModelCache`), so the\n // provider holds nothing and needs no lifetime of its own.\n container.register(FileModelProvider);\n }\n});\n"],"names":["FileManagerAppFeature","createFeature","container","AssetDeliveryFeature","AssetDeliveryRouteDefinition","FileModel","FmPermissionsFeature","FileManagerFeature","FileModelProvider"],"mappings":";;;;;;;AAQO,MAAMA,wBAAwBC,cAAc;IAC/C,MAAM;IACN,UAASC,SAAoB;QACzBC,qBAAqB,QAAQ,CAACD;QAC9BA,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;QACnBC,qBAAqB,QAAQ,CAACJ;QAC9BK,mBAAmB,QAAQ,CAACL;QAI5BA,UAAU,QAAQ,CAACM;IACvB;AACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delivery/AssetDelivery/AssetRequest.js","sources":["../../../src/delivery/AssetDelivery/AssetRequest.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport interface AssetRequestOptions {\n original?: boolean;\n
|
|
1
|
+
{"version":3,"file":"delivery/AssetDelivery/AssetRequest.js","sources":["../../../src/delivery/AssetDelivery/AssetRequest.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport interface AssetRequestOptions {\n original?: boolean;\n [key: string]: unknown;\n}\n\nexport type AssetRequestContext<T extends GenericRecord = GenericRecord> = T & {\n /**\n * Asset request URL.\n */\n url: string;\n};\n\nexport interface AssetRequestData<TOptions> {\n key: string;\n context: AssetRequestContext;\n options: TOptions;\n}\n\nexport class AssetRequest<TOptions extends AssetRequestOptions = AssetRequestOptions> {\n private data: AssetRequestData<TOptions>;\n\n constructor(data: AssetRequestData<TOptions>) {\n this.data = data;\n }\n\n getKey() {\n return this.data.key;\n }\n\n getOptions(): TOptions {\n return this.data.options;\n }\n\n setOptions(options: TOptions) {\n this.data.options = options;\n }\n\n getContext<T extends GenericRecord = GenericRecord>() {\n return this.data.context as AssetRequestContext<T>;\n }\n\n getExtension() {\n return this.data.key.split(\".\").pop();\n }\n}\n"],"names":["AssetRequest","data","options"],"mappings":"AAoBO,MAAMA;IAGT,YAAYC,IAAgC,CAAE;QAC1C,IAAI,CAAC,IAAI,GAAGA;IAChB;IAEA,SAAS;QACL,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG;IACxB;IAEA,aAAuB;QACnB,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO;IAC5B;IAEA,WAAWC,OAAiB,EAAE;QAC1B,IAAI,CAAC,IAAI,CAAC,OAAO,GAAGA;IACxB;IAEA,aAAsD;QAClD,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO;IAC5B;IAEA,eAAe;QACX,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,GAAG;IACvC;AACJ"}
|
|
@@ -1,14 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { IHttpRequest, IHttpResponse } from "@webiny/event-handler-core";
|
|
1
|
+
import { HttpRouteDefinition, HttpRouteHandler } from "@webiny/event-handler-core";
|
|
3
2
|
import type { Container } from "@webiny/di";
|
|
4
|
-
declare class AssetDeliveryRouteImpl implements
|
|
3
|
+
declare class AssetDeliveryRouteImpl implements HttpRouteHandler.Interface {
|
|
5
4
|
private container;
|
|
6
|
-
readonly method = "GET";
|
|
7
|
-
readonly path = "/files/*";
|
|
8
5
|
constructor(container: Container);
|
|
9
|
-
handle(request:
|
|
6
|
+
handle(request: HttpRouteHandler.Request, response: HttpRouteHandler.Response): Promise<import("@webiny/event-handler-core").IHttpResponseBuilder>;
|
|
7
|
+
private deliver;
|
|
10
8
|
}
|
|
11
9
|
export declare const AssetDeliveryRoute: typeof AssetDeliveryRouteImpl & {
|
|
12
10
|
__abstraction: import("@webiny/di").Abstraction<import("@webiny/event-handler-core").IHttpRoute>;
|
|
13
11
|
};
|
|
12
|
+
declare class AssetDeliveryRouteDefinitionImpl implements HttpRouteDefinition.Interface {
|
|
13
|
+
readonly name = "asset-delivery";
|
|
14
|
+
readonly method = "GET";
|
|
15
|
+
readonly path = "/files/*";
|
|
16
|
+
readonly handler: typeof AssetDeliveryRouteImpl & {
|
|
17
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/event-handler-core").IHttpRoute>;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** What the router matches on. Zero dependencies, so building it costs nothing. */
|
|
21
|
+
export declare const AssetDeliveryRouteDefinition: typeof AssetDeliveryRouteDefinitionImpl & {
|
|
22
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/event-handler-core").IHttpRouteDefinition>;
|
|
23
|
+
};
|
|
14
24
|
export {};
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HttpRouteDefinition, HttpRouteHandler, RequestContainer } from "@webiny/event-handler-core";
|
|
2
|
+
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
3
|
+
import { GetTenantByIdUseCase } from "@webiny/api-core/features/tenancy/GetTenantById/index.js";
|
|
2
4
|
import { AssetOutputStrategy, AssetProcessor, AssetRequestResolver, AssetResolver } from "../features/assetDelivery/abstractions.js";
|
|
3
|
-
const
|
|
4
|
-
"content-type": "application/json",
|
|
5
|
-
"cache-control": "no-cache, no-store, must-revalidate"
|
|
6
|
-
};
|
|
5
|
+
const NO_CACHE = "no-cache, no-store, must-revalidate";
|
|
7
6
|
class AssetDeliveryRouteImpl {
|
|
8
7
|
constructor(container){
|
|
9
8
|
this.container = container;
|
|
10
|
-
this.method = "GET";
|
|
11
|
-
this.path = "/files/*";
|
|
12
9
|
}
|
|
13
|
-
async handle(request) {
|
|
10
|
+
async handle(request, response) {
|
|
14
11
|
const requestResolver = this.container.resolve(AssetRequestResolver);
|
|
15
12
|
const assetResolver = this.container.resolve(AssetResolver);
|
|
16
|
-
const
|
|
17
|
-
const
|
|
13
|
+
const tenantContext = this.container.resolve(TenantContext);
|
|
14
|
+
const getTenantById = this.container.resolve(GetTenantByIdUseCase);
|
|
18
15
|
const fakeRequest = {
|
|
19
16
|
url: request.path,
|
|
20
17
|
params: {
|
|
@@ -24,42 +21,49 @@ class AssetDeliveryRouteImpl {
|
|
|
24
21
|
headers: request.headers ?? {}
|
|
25
22
|
};
|
|
26
23
|
const resolvedRequest = await requestResolver.resolve(fakeRequest);
|
|
27
|
-
if (!resolvedRequest) return {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
body: JSON.stringify({
|
|
31
|
-
error: "Unable to resolve the request!"
|
|
32
|
-
})
|
|
33
|
-
};
|
|
24
|
+
if (!resolvedRequest) return response.status(404).header("cache-control", NO_CACHE).json({
|
|
25
|
+
error: "Unable to resolve the request!"
|
|
26
|
+
});
|
|
34
27
|
const resolvedAsset = await assetResolver.resolve(resolvedRequest);
|
|
35
|
-
if (!resolvedAsset) return {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
};
|
|
28
|
+
if (!resolvedAsset) return response.status(404).header("cache-control", NO_CACHE).json({
|
|
29
|
+
error: "Asset not found!"
|
|
30
|
+
});
|
|
31
|
+
const tenantResult = await getTenantById.execute(resolvedAsset.getTenant());
|
|
32
|
+
if (tenantResult.isFail()) return response.status(404).header("cache-control", NO_CACHE).json({
|
|
33
|
+
error: "Asset not found!"
|
|
34
|
+
});
|
|
35
|
+
return tenantContext.withTenant(tenantResult.value, ()=>this.deliver(resolvedRequest, resolvedAsset, response));
|
|
36
|
+
}
|
|
37
|
+
async deliver(resolvedRequest, resolvedAsset, response) {
|
|
38
|
+
const assetProcessor = this.container.resolve(AssetProcessor);
|
|
39
|
+
const outputStrategy = this.container.resolve(AssetOutputStrategy);
|
|
42
40
|
resolvedAsset.setOutputStrategy(outputStrategy);
|
|
43
41
|
const processedAsset = await assetProcessor.process(resolvedRequest, resolvedAsset);
|
|
44
42
|
const assetReply = await processedAsset.output();
|
|
45
43
|
const rawHeaders = assetReply.getHeaders().getHeaders();
|
|
46
|
-
const
|
|
47
|
-
for (const [k, v] of Object.entries(rawHeaders))if (void 0 !== v) headers[k] = String(v);
|
|
44
|
+
for (const [k, v] of Object.entries(rawHeaders))if (void 0 !== v) response.header(k, String(v));
|
|
48
45
|
const body = await assetReply.getBody();
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
statusCode,
|
|
52
|
-
headers,
|
|
53
|
-
body: body ?? ""
|
|
54
|
-
};
|
|
46
|
+
return response.status(assetReply.getCode()).end(body ?? "");
|
|
55
47
|
}
|
|
56
48
|
}
|
|
57
|
-
const AssetDeliveryRoute =
|
|
49
|
+
const AssetDeliveryRoute = HttpRouteHandler.createImplementation({
|
|
58
50
|
implementation: AssetDeliveryRouteImpl,
|
|
59
51
|
dependencies: [
|
|
60
52
|
RequestContainer
|
|
61
53
|
]
|
|
62
54
|
});
|
|
63
|
-
|
|
55
|
+
class AssetDeliveryRouteDefinitionImpl {
|
|
56
|
+
constructor(){
|
|
57
|
+
this.name = "asset-delivery";
|
|
58
|
+
this.method = "GET";
|
|
59
|
+
this.path = "/files/*";
|
|
60
|
+
this.handler = AssetDeliveryRoute;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const AssetDeliveryRouteDefinition = HttpRouteDefinition.createImplementation({
|
|
64
|
+
implementation: AssetDeliveryRouteDefinitionImpl,
|
|
65
|
+
dependencies: []
|
|
66
|
+
});
|
|
67
|
+
export { AssetDeliveryRoute, AssetDeliveryRouteDefinition };
|
|
64
68
|
|
|
65
69
|
//# sourceMappingURL=AssetDeliveryRoute.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delivery/AssetDeliveryRoute.js","sources":["../../src/delivery/AssetDeliveryRoute.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"delivery/AssetDeliveryRoute.js","sources":["../../src/delivery/AssetDeliveryRoute.ts"],"sourcesContent":["import {\n HttpRouteDefinition,\n HttpRouteHandler,\n RequestContainer\n} from \"@webiny/event-handler-core\";\nimport type { Container } from \"@webiny/di\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { GetTenantByIdUseCase } from \"@webiny/api-core/features/tenancy/GetTenantById/index.js\";\nimport {\n AssetRequestResolver,\n AssetResolver,\n AssetProcessor,\n AssetOutputStrategy\n} from \"~/features/assetDelivery/abstractions.js\";\nimport type { Asset } from \"~/delivery/AssetDelivery/Asset.js\";\nimport type { AssetRequest } from \"~/delivery/AssetDelivery/AssetRequest.js\";\n\nconst NO_CACHE = \"no-cache, no-store, must-revalidate\";\n\nclass AssetDeliveryRouteImpl implements HttpRouteHandler.Interface {\n constructor(private container: Container) {}\n\n async handle(request: HttpRouteHandler.Request, response: HttpRouteHandler.Response) {\n // Resolve asset-delivery collaborators lazily (request time), not as constructor deps.\n // HttpRouter eagerly constructs every route to match paths, and AssetProcessor's\n // PrivateFilesAssetProcessor decorator pulls in GetFileUseCase -> CMS entry repositories\n // that depend on EntryFromStorageTransform, which is only registered while a CMS GraphQL\n // request is in flight. Resolving here keeps route construction cheap so non-asset\n // requests (e.g. /graphql) don't trigger that chain before it is registered.\n const requestResolver = this.container.resolve(AssetRequestResolver);\n const assetResolver = this.container.resolve(AssetResolver);\n const tenantContext = this.container.resolve(TenantContext);\n const getTenantById = this.container.resolve(GetTenantByIdUseCase);\n\n // Reconstruct a minimal request object compatible with IAssetRequestResolver\n const fakeRequest = {\n url: request.path,\n params: { \"*\": request.path.replace(\"/files/\", \"\") },\n query: request.query ?? {},\n headers: request.headers ?? {}\n };\n\n const resolvedRequest = await requestResolver.resolve(fakeRequest as any);\n if (!resolvedRequest) {\n return response\n .status(404)\n .header(\"cache-control\", NO_CACHE)\n .json({ error: \"Unable to resolve the request!\" });\n }\n\n const resolvedAsset = await assetResolver.resolve(resolvedRequest);\n if (!resolvedAsset) {\n return response\n .status(404)\n .header(\"cache-control\", NO_CACHE)\n .json({ error: \"Asset not found!\" });\n }\n\n // Delivery requests carry no tenant header, so up to this point the request runs in the\n // root tenant. Now that we know which tenant owns the asset, switch to it for the rest of\n // the request, so processors, authorizers and output strategies (e.g. the private files\n // check, which loads the tenant-scoped file entry) all run in the asset's tenant.\n const tenantResult = await getTenantById.execute(resolvedAsset.getTenant());\n if (tenantResult.isFail()) {\n return response\n .status(404)\n .header(\"cache-control\", NO_CACHE)\n .json({ error: \"Asset not found!\" });\n }\n\n return tenantContext.withTenant(tenantResult.value, () =>\n this.deliver(resolvedRequest, resolvedAsset, response)\n );\n }\n\n private async deliver(\n resolvedRequest: AssetRequest,\n resolvedAsset: Asset,\n response: HttpRouteHandler.Response\n ) {\n const assetProcessor = this.container.resolve(AssetProcessor);\n const outputStrategy = this.container.resolve(AssetOutputStrategy);\n\n resolvedAsset.setOutputStrategy(outputStrategy);\n\n const processedAsset = await assetProcessor.process(resolvedRequest, resolvedAsset);\n const assetReply = await processedAsset.output();\n\n const rawHeaders = assetReply.getHeaders().getHeaders();\n for (const [k, v] of Object.entries(rawHeaders)) {\n if (v !== undefined) {\n response.header(k, String(v));\n }\n }\n\n const body = await assetReply.getBody();\n\n // `end()` (not `send()`) so the raw body passes through untouched and the asset's OWN\n // Content-Type — set from `rawHeaders` above — is preserved. The transport translator\n // (e.g. httpResponseToApiGatewayResult) base64-encodes Buffers and sets isBase64Encoded so\n // API Gateway returns proper binary. Pre-encoding to a base64 STRING here defeated that —\n // the string passed through undecoded and browsers received base64 text, not an image.\n return response.status(assetReply.getCode()).end(body ?? \"\");\n }\n}\n\nexport const AssetDeliveryRoute = HttpRouteHandler.createImplementation({\n implementation: AssetDeliveryRouteImpl,\n dependencies: [RequestContainer]\n});\n\nclass AssetDeliveryRouteDefinitionImpl implements HttpRouteDefinition.Interface {\n readonly name = \"asset-delivery\";\n readonly method = \"GET\";\n readonly path = \"/files/*\";\n readonly handler = AssetDeliveryRoute;\n}\n\n/** What the router matches on. Zero dependencies, so building it costs nothing. */\nexport const AssetDeliveryRouteDefinition = HttpRouteDefinition.createImplementation({\n implementation: AssetDeliveryRouteDefinitionImpl,\n dependencies: []\n});\n"],"names":["NO_CACHE","AssetDeliveryRouteImpl","container","request","response","requestResolver","AssetRequestResolver","assetResolver","AssetResolver","tenantContext","TenantContext","getTenantById","GetTenantByIdUseCase","fakeRequest","resolvedRequest","resolvedAsset","tenantResult","assetProcessor","AssetProcessor","outputStrategy","AssetOutputStrategy","processedAsset","assetReply","rawHeaders","k","v","Object","undefined","String","body","AssetDeliveryRoute","HttpRouteHandler","RequestContainer","AssetDeliveryRouteDefinitionImpl","AssetDeliveryRouteDefinition","HttpRouteDefinition"],"mappings":";;;;AAiBA,MAAMA,WAAW;AAEjB,MAAMC;IACF,YAAoBC,SAAoB,CAAE;aAAtBA,SAAS,GAATA;IAAuB;IAE3C,MAAM,OAAOC,OAAiC,EAAEC,QAAmC,EAAE;QAOjF,MAAMC,kBAAkB,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC;QAC/C,MAAMC,gBAAgB,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC;QAC7C,MAAMC,gBAAgB,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC;QAC7C,MAAMC,gBAAgB,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC;QAG7C,MAAMC,cAAc;YAChB,KAAKV,QAAQ,IAAI;YACjB,QAAQ;gBAAE,KAAKA,QAAQ,IAAI,CAAC,OAAO,CAAC,WAAW;YAAI;YACnD,OAAOA,QAAQ,KAAK,IAAI,CAAC;YACzB,SAASA,QAAQ,OAAO,IAAI,CAAC;QACjC;QAEA,MAAMW,kBAAkB,MAAMT,gBAAgB,OAAO,CAACQ;QACtD,IAAI,CAACC,iBACD,OAAOV,SACF,MAAM,CAAC,KACP,MAAM,CAAC,iBAAiBJ,UACxB,IAAI,CAAC;YAAE,OAAO;QAAiC;QAGxD,MAAMe,gBAAgB,MAAMR,cAAc,OAAO,CAACO;QAClD,IAAI,CAACC,eACD,OAAOX,SACF,MAAM,CAAC,KACP,MAAM,CAAC,iBAAiBJ,UACxB,IAAI,CAAC;YAAE,OAAO;QAAmB;QAO1C,MAAMgB,eAAe,MAAML,cAAc,OAAO,CAACI,cAAc,SAAS;QACxE,IAAIC,aAAa,MAAM,IACnB,OAAOZ,SACF,MAAM,CAAC,KACP,MAAM,CAAC,iBAAiBJ,UACxB,IAAI,CAAC;YAAE,OAAO;QAAmB;QAG1C,OAAOS,cAAc,UAAU,CAACO,aAAa,KAAK,EAAE,IAChD,IAAI,CAAC,OAAO,CAACF,iBAAiBC,eAAeX;IAErD;IAEA,MAAc,QACVU,eAA6B,EAC7BC,aAAoB,EACpBX,QAAmC,EACrC;QACE,MAAMa,iBAAiB,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC;QAC9C,MAAMC,iBAAiB,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC;QAE9CL,cAAc,iBAAiB,CAACI;QAEhC,MAAME,iBAAiB,MAAMJ,eAAe,OAAO,CAACH,iBAAiBC;QACrE,MAAMO,aAAa,MAAMD,eAAe,MAAM;QAE9C,MAAME,aAAaD,WAAW,UAAU,GAAG,UAAU;QACrD,KAAK,MAAM,CAACE,GAAGC,EAAE,IAAIC,OAAO,OAAO,CAACH,YAChC,IAAIE,AAAME,WAANF,GACArB,SAAS,MAAM,CAACoB,GAAGI,OAAOH;QAIlC,MAAMI,OAAO,MAAMP,WAAW,OAAO;QAOrC,OAAOlB,SAAS,MAAM,CAACkB,WAAW,OAAO,IAAI,GAAG,CAACO,QAAQ;IAC7D;AACJ;AAEO,MAAMC,qBAAqBC,iBAAiB,oBAAoB,CAAC;IACpE,gBAAgB9B;IAChB,cAAc;QAAC+B;KAAiB;AACpC;AAEA,MAAMC;;aACO,IAAI,GAAG;aACP,MAAM,GAAG;aACT,IAAI,GAAG;aACP,OAAO,GAAGH;;AACvB;AAGO,MAAMI,+BAA+BC,oBAAoB,oBAAoB,CAAC;IACjF,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import type { CmsModel } from "@webiny/api-headless-cms/types";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Provides the `fmFile` CMS model for the current request's tenant.
|
|
4
|
+
*
|
|
5
|
+
* Fetching a model is asynchronous and tenant-dependent, which is why this is a provider rather
|
|
6
|
+
* than the model itself: DI resolution is synchronous, so an already-resolved `CmsModel` could only
|
|
7
|
+
* be supplied by a per-request hook running before any consumer (what `FileModelContextualSchema`
|
|
8
|
+
* used to do). Consumers instead `await get()` at the point of use — by which time the tenant is
|
|
9
|
+
* established — and the provider memoizes for the rest of the request.
|
|
5
10
|
*/
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
11
|
+
export interface IFileModelProvider {
|
|
12
|
+
get(): Promise<CmsModel>;
|
|
13
|
+
}
|
|
14
|
+
export declare const FileModelProvider: import("@webiny/di").Abstraction<IFileModelProvider>;
|
|
15
|
+
export declare namespace FileModelProvider {
|
|
16
|
+
type Interface = IFileModelProvider;
|
|
9
17
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
-
const
|
|
3
|
-
export {
|
|
2
|
+
const FileModelProvider = createAbstraction("FileModelProvider");
|
|
3
|
+
export { FileModelProvider };
|
|
4
4
|
|
|
5
5
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
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 *
|
|
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 * Provides the `fmFile` CMS model for the current request's tenant.\n *\n * Fetching a model is asynchronous and tenant-dependent, which is why this is a provider rather\n * than the model itself: DI resolution is synchronous, so an already-resolved `CmsModel` could only\n * be supplied by a per-request hook running before any consumer (what `FileModelContextualSchema`\n * used to do). Consumers instead `await get()` at the point of use — by which time the tenant is\n * established — and the provider memoizes for the rest of the request.\n */\nexport interface IFileModelProvider {\n get(): Promise<CmsModel>;\n}\n\nexport const FileModelProvider = createAbstraction<IFileModelProvider>(\"FileModelProvider\");\n\nexport namespace FileModelProvider {\n export type Interface = IFileModelProvider;\n}\n"],"names":["FileModelProvider","createAbstraction"],"mappings":";AAgBO,MAAMA,oBAAoBC,kBAAsC"}
|
package/domain/file/errors.d.ts
CHANGED
|
@@ -57,3 +57,13 @@ export declare class InvalidFileTypeError extends BaseError<{
|
|
|
57
57
|
type: string;
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
|
+
export declare class InvalidFileKeyError extends BaseError<{
|
|
61
|
+
key: string;
|
|
62
|
+
id?: string;
|
|
63
|
+
}> {
|
|
64
|
+
readonly code: "FileManager/File/InvalidFileKeyError";
|
|
65
|
+
constructor(data: {
|
|
66
|
+
key: string;
|
|
67
|
+
id?: string;
|
|
68
|
+
});
|
|
69
|
+
}
|
package/domain/file/errors.js
CHANGED
|
@@ -75,6 +75,14 @@ class InvalidFileTypeError extends BaseError {
|
|
|
75
75
|
}), this.code = "FileManager/File/InvalidFileTypeError";
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
|
|
78
|
+
class InvalidFileKeyError extends BaseError {
|
|
79
|
+
constructor(data){
|
|
80
|
+
super({
|
|
81
|
+
message: `File key "${data.key}" is not a valid storage key.`,
|
|
82
|
+
data
|
|
83
|
+
}), this.code = "FileManager/File/InvalidFileKeyError";
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export { FileAlreadyExistsError, FileCreateError, FileDeleteError, FileListError, FileNotAuthorizedError, FileNotFoundError, FilePersistenceError, FileUpdateError, InvalidFileKeyError, InvalidFileSizeError, InvalidFileTypeError };
|
|
79
87
|
|
|
80
88
|
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domain/file/errors.js","sources":["../../../src/domain/file/errors.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\n\nexport class FilePersistenceError extends BaseError {\n override readonly code = \"FileManager/File/PersistenceError\" as const;\n\n constructor(error: Error) {\n super({\n message: error.message\n });\n }\n}\n\nexport class FileNotFoundError extends BaseError<{ id: string }> {\n override readonly code = \"FileManager/File/NotFoundError\" as const;\n\n constructor(id: string) {\n super({\n message: `File with ID \"${id}\" not found.`,\n data: { id }\n });\n }\n}\n\nexport class FileNotAuthorizedError extends BaseError {\n override readonly code = \"FileManager/File/NotAuthorizedError\" as const;\n\n constructor() {\n super({\n message: `Not authorized.`\n });\n }\n}\n\nexport class FileListError extends BaseError {\n override readonly code = \"FileManager/File/ListError\" as const;\n\n constructor(error: Error) {\n super({\n message: `Error listing files: ${error.message}`\n });\n }\n}\n\nexport class FileCreateError extends BaseError {\n override readonly code = \"FileManager/File/CreateError\" as const;\n\n constructor(error: Error) {\n super({\n message: `Error creating file: ${error.message}`\n });\n }\n}\n\nexport class FileUpdateError extends BaseError {\n override readonly code = \"FileManager/File/UpdateError\" as const;\n\n constructor(error: Error) {\n super({\n message: `Error updating file: ${error.message}`\n });\n }\n}\n\nexport class FileDeleteError extends BaseError {\n override readonly code = \"FileManager/File/DeleteError\" as const;\n\n constructor(error: Error) {\n super({\n message: `Error deleting file: ${error.message}`\n });\n }\n}\n\nexport class FileAlreadyExistsError extends BaseError<{ key: string }> {\n override readonly code = \"FileManager/File/AlreadyExistsError\" as const;\n\n constructor(data: { key: string }) {\n super({\n message: `File with key \"${data.key}\" already exists.`,\n data\n });\n }\n}\n\nexport class InvalidFileSizeError extends BaseError<{\n size: number;\n minSize: number;\n maxSize: number;\n}> {\n override readonly code = \"FileManager/File/InvalidFileSizeError\" as const;\n\n constructor(data: { size: number; minSize: number; maxSize: number }) {\n super({\n message: `File size ${data.size} bytes is outside allowed range (${data.minSize}-${data.maxSize} bytes).`,\n data\n });\n }\n}\n\nexport class InvalidFileTypeError extends BaseError<{ type: string }> {\n override readonly code = \"FileManager/File/InvalidFileTypeError\" as const;\n\n constructor(data: { type: string }) {\n super({\n message: `File type \"${data.type}\" is not allowed.`,\n data\n });\n }\n}\n"],"names":["FilePersistenceError","BaseError","error","FileNotFoundError","id","FileNotAuthorizedError","FileListError","FileCreateError","FileUpdateError","FileDeleteError","FileAlreadyExistsError","data","InvalidFileSizeError","InvalidFileTypeError"],"mappings":";AAEO,MAAMA,6BAA6BC;IAGtC,YAAYC,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAASA,MAAM,OAAO;QAC1B,SALc,IAAI,GAAG;IAMzB;AACJ;AAEO,MAAMC,0BAA0BF;IAGnC,YAAYG,EAAU,CAAE;QACpB,KAAK,CAAC;YACF,SAAS,CAAC,cAAc,EAAEA,GAAG,YAAY,CAAC;YAC1C,MAAM;gBAAEA;YAAG;QACf,SANc,IAAI,GAAG;IAOzB;AACJ;AAEO,MAAMC,+BAA+BJ;IAGxC,aAAc;QACV,KAAK,CAAC;YACF,SAAS;QACb,SALc,IAAI,GAAG;IAMzB;AACJ;AAEO,MAAMK,sBAAsBL;IAG/B,YAAYC,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS,CAAC,qBAAqB,EAAEA,MAAM,OAAO,EAAE;QACpD,SALc,IAAI,GAAG;IAMzB;AACJ;AAEO,MAAMK,wBAAwBN;IAGjC,YAAYC,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS,CAAC,qBAAqB,EAAEA,MAAM,OAAO,EAAE;QACpD,SALc,IAAI,GAAG;IAMzB;AACJ;AAEO,MAAMM,wBAAwBP;IAGjC,YAAYC,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS,CAAC,qBAAqB,EAAEA,MAAM,OAAO,EAAE;QACpD,SALc,IAAI,GAAG;IAMzB;AACJ;AAEO,MAAMO,wBAAwBR;IAGjC,YAAYC,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS,CAAC,qBAAqB,EAAEA,MAAM,OAAO,EAAE;QACpD,SALc,IAAI,GAAG;IAMzB;AACJ;AAEO,MAAMQ,+BAA+BT;IAGxC,YAAYU,IAAqB,CAAE;QAC/B,KAAK,CAAC;YACF,SAAS,CAAC,eAAe,EAAEA,KAAK,GAAG,CAAC,iBAAiB,CAAC;YACtDA;QACJ,SANc,IAAI,GAAG;IAOzB;AACJ;AAEO,MAAMC,6BAA6BX;IAOtC,YAAYU,IAAwD,CAAE;QAClE,KAAK,CAAC;YACF,SAAS,CAAC,UAAU,EAAEA,KAAK,IAAI,CAAC,iCAAiC,EAAEA,KAAK,OAAO,CAAC,CAAC,EAAEA,KAAK,OAAO,CAAC,QAAQ,CAAC;YACzGA;QACJ,SANc,IAAI,GAAG;IAOzB;AACJ;AAEO,MAAME,6BAA6BZ;IAGtC,YAAYU,IAAsB,CAAE;QAChC,KAAK,CAAC;YACF,SAAS,CAAC,WAAW,EAAEA,KAAK,IAAI,CAAC,iBAAiB,CAAC;YACnDA;QACJ,SANc,IAAI,GAAG;IAOzB;AACJ"}
|
|
1
|
+
{"version":3,"file":"domain/file/errors.js","sources":["../../../src/domain/file/errors.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\n\nexport class FilePersistenceError extends BaseError {\n override readonly code = \"FileManager/File/PersistenceError\" as const;\n\n constructor(error: Error) {\n super({\n message: error.message\n });\n }\n}\n\nexport class FileNotFoundError extends BaseError<{ id: string }> {\n override readonly code = \"FileManager/File/NotFoundError\" as const;\n\n constructor(id: string) {\n super({\n message: `File with ID \"${id}\" not found.`,\n data: { id }\n });\n }\n}\n\nexport class FileNotAuthorizedError extends BaseError {\n override readonly code = \"FileManager/File/NotAuthorizedError\" as const;\n\n constructor() {\n super({\n message: `Not authorized.`\n });\n }\n}\n\nexport class FileListError extends BaseError {\n override readonly code = \"FileManager/File/ListError\" as const;\n\n constructor(error: Error) {\n super({\n message: `Error listing files: ${error.message}`\n });\n }\n}\n\nexport class FileCreateError extends BaseError {\n override readonly code = \"FileManager/File/CreateError\" as const;\n\n constructor(error: Error) {\n super({\n message: `Error creating file: ${error.message}`\n });\n }\n}\n\nexport class FileUpdateError extends BaseError {\n override readonly code = \"FileManager/File/UpdateError\" as const;\n\n constructor(error: Error) {\n super({\n message: `Error updating file: ${error.message}`\n });\n }\n}\n\nexport class FileDeleteError extends BaseError {\n override readonly code = \"FileManager/File/DeleteError\" as const;\n\n constructor(error: Error) {\n super({\n message: `Error deleting file: ${error.message}`\n });\n }\n}\n\nexport class FileAlreadyExistsError extends BaseError<{ key: string }> {\n override readonly code = \"FileManager/File/AlreadyExistsError\" as const;\n\n constructor(data: { key: string }) {\n super({\n message: `File with key \"${data.key}\" already exists.`,\n data\n });\n }\n}\n\nexport class InvalidFileSizeError extends BaseError<{\n size: number;\n minSize: number;\n maxSize: number;\n}> {\n override readonly code = \"FileManager/File/InvalidFileSizeError\" as const;\n\n constructor(data: { size: number; minSize: number; maxSize: number }) {\n super({\n message: `File size ${data.size} bytes is outside allowed range (${data.minSize}-${data.maxSize} bytes).`,\n data\n });\n }\n}\n\nexport class InvalidFileTypeError extends BaseError<{ type: string }> {\n override readonly code = \"FileManager/File/InvalidFileTypeError\" as const;\n\n constructor(data: { type: string }) {\n super({\n message: `File type \"${data.type}\" is not allowed.`,\n data\n });\n }\n}\n\nexport class InvalidFileKeyError extends BaseError<{ key: string; id?: string }> {\n override readonly code = \"FileManager/File/InvalidFileKeyError\" as const;\n\n constructor(data: { key: string; id?: string }) {\n super({\n message: `File key \"${data.key}\" is not a valid storage key.`,\n data\n });\n }\n}\n"],"names":["FilePersistenceError","BaseError","error","FileNotFoundError","id","FileNotAuthorizedError","FileListError","FileCreateError","FileUpdateError","FileDeleteError","FileAlreadyExistsError","data","InvalidFileSizeError","InvalidFileTypeError","InvalidFileKeyError"],"mappings":";AAEO,MAAMA,6BAA6BC;IAGtC,YAAYC,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAASA,MAAM,OAAO;QAC1B,SALc,IAAI,GAAG;IAMzB;AACJ;AAEO,MAAMC,0BAA0BF;IAGnC,YAAYG,EAAU,CAAE;QACpB,KAAK,CAAC;YACF,SAAS,CAAC,cAAc,EAAEA,GAAG,YAAY,CAAC;YAC1C,MAAM;gBAAEA;YAAG;QACf,SANc,IAAI,GAAG;IAOzB;AACJ;AAEO,MAAMC,+BAA+BJ;IAGxC,aAAc;QACV,KAAK,CAAC;YACF,SAAS;QACb,SALc,IAAI,GAAG;IAMzB;AACJ;AAEO,MAAMK,sBAAsBL;IAG/B,YAAYC,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS,CAAC,qBAAqB,EAAEA,MAAM,OAAO,EAAE;QACpD,SALc,IAAI,GAAG;IAMzB;AACJ;AAEO,MAAMK,wBAAwBN;IAGjC,YAAYC,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS,CAAC,qBAAqB,EAAEA,MAAM,OAAO,EAAE;QACpD,SALc,IAAI,GAAG;IAMzB;AACJ;AAEO,MAAMM,wBAAwBP;IAGjC,YAAYC,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS,CAAC,qBAAqB,EAAEA,MAAM,OAAO,EAAE;QACpD,SALc,IAAI,GAAG;IAMzB;AACJ;AAEO,MAAMO,wBAAwBR;IAGjC,YAAYC,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS,CAAC,qBAAqB,EAAEA,MAAM,OAAO,EAAE;QACpD,SALc,IAAI,GAAG;IAMzB;AACJ;AAEO,MAAMQ,+BAA+BT;IAGxC,YAAYU,IAAqB,CAAE;QAC/B,KAAK,CAAC;YACF,SAAS,CAAC,eAAe,EAAEA,KAAK,GAAG,CAAC,iBAAiB,CAAC;YACtDA;QACJ,SANc,IAAI,GAAG;IAOzB;AACJ;AAEO,MAAMC,6BAA6BX;IAOtC,YAAYU,IAAwD,CAAE;QAClE,KAAK,CAAC;YACF,SAAS,CAAC,UAAU,EAAEA,KAAK,IAAI,CAAC,iCAAiC,EAAEA,KAAK,OAAO,CAAC,CAAC,EAAEA,KAAK,OAAO,CAAC,QAAQ,CAAC;YACzGA;QACJ,SANc,IAAI,GAAG;IAOzB;AACJ;AAEO,MAAME,6BAA6BZ;IAGtC,YAAYU,IAAsB,CAAE;QAChC,KAAK,CAAC;YACF,SAAS,CAAC,WAAW,EAAEA,KAAK,IAAI,CAAC,iBAAiB,CAAC;YACnDA;QACJ,SANc,IAAI,GAAG;IAOzB;AACJ;AAEO,MAAMG,4BAA4Bb;IAGrC,YAAYU,IAAkC,CAAE;QAC5C,KAAK,CAAC;YACF,SAAS,CAAC,UAAU,EAAEA,KAAK,GAAG,CAAC,6BAA6B,CAAC;YAC7DA;QACJ,SANc,IAAI,GAAG;IAOzB;AACJ"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ModelFactory } from "@webiny/api-headless-cms/features/modelBuilder/index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { FeatureFlags } from "@webiny/api-core/features/featureFlags/abstractions.js";
|
|
3
3
|
export declare const FILE_MODEL_ID: string;
|
|
4
4
|
declare class FilePrivateModelImpl implements ModelFactory.Interface {
|
|
5
|
-
private
|
|
6
|
-
constructor(
|
|
5
|
+
private featureFlags;
|
|
6
|
+
constructor(featureFlags: FeatureFlags.Interface);
|
|
7
7
|
execute(builder: ModelFactory.Builder): Promise<import("@webiny/api-headless-cms/features/modelBuilder/index.js").PrivateModelBuilder[]>;
|
|
8
8
|
}
|
|
9
9
|
export declare const FileModel: typeof FilePrivateModelImpl & {
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { ModelFactory } from "@webiny/api-headless-cms/features/modelBuilder/index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { FeatureFlags } from "@webiny/api-core/features/featureFlags/abstractions.js";
|
|
3
3
|
const FILE_MODEL_ID = process.env.WEBINY_API_LEGACY_MODELS ? "fmFile" : "wbyFmFile";
|
|
4
4
|
class FilePrivateModelImpl {
|
|
5
|
-
constructor(
|
|
6
|
-
this.
|
|
5
|
+
constructor(featureFlags){
|
|
6
|
+
this.featureFlags = featureFlags;
|
|
7
7
|
}
|
|
8
8
|
async execute(builder) {
|
|
9
9
|
const model = builder.private({
|
|
10
10
|
modelId: FILE_MODEL_ID,
|
|
11
|
-
name: "FmFile"
|
|
11
|
+
name: "FmFile",
|
|
12
|
+
lifecycleEvents: false
|
|
12
13
|
});
|
|
13
|
-
const privateFiles = this.
|
|
14
|
+
const privateFiles = this.featureFlags.get().isEnabled("advancedAccessControlLayer.privateFiles");
|
|
14
15
|
model.fields((fields)=>({
|
|
15
16
|
name: fields.text().label("Name").required("Value is required."),
|
|
16
17
|
key: fields.text().label("Key").required("Value is required."),
|
|
@@ -21,7 +22,11 @@ class FilePrivateModelImpl {
|
|
|
21
22
|
width: fields.number().label("Width"),
|
|
22
23
|
height: fields.number().label("Height"),
|
|
23
24
|
format: fields.text().label("Format"),
|
|
24
|
-
orientation: fields.number().label("Orientation")
|
|
25
|
+
orientation: fields.number().label("Orientation"),
|
|
26
|
+
crop: fields.json().label("Crop"),
|
|
27
|
+
focalPoint: fields.json().label("Focal point"),
|
|
28
|
+
alt: fields.text().label("Alt text"),
|
|
29
|
+
caption: fields.text().label("Caption")
|
|
25
30
|
})),
|
|
26
31
|
exif: fields.searchableJson().label("EXIF Data"),
|
|
27
32
|
iptc: fields.searchableJson().label("IPTC Data")
|
|
@@ -57,7 +62,7 @@ class FilePrivateModelImpl {
|
|
|
57
62
|
const FileModel = ModelFactory.createImplementation({
|
|
58
63
|
implementation: FilePrivateModelImpl,
|
|
59
64
|
dependencies: [
|
|
60
|
-
|
|
65
|
+
FeatureFlags
|
|
61
66
|
]
|
|
62
67
|
});
|
|
63
68
|
export { FILE_MODEL_ID, FileModel };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domain/file/file.model.js","sources":["../../../src/domain/file/file.model.ts"],"sourcesContent":["import { ModelFactory } from \"@webiny/api-headless-cms/features/modelBuilder/index.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"domain/file/file.model.js","sources":["../../../src/domain/file/file.model.ts"],"sourcesContent":["import { ModelFactory } from \"@webiny/api-headless-cms/features/modelBuilder/index.js\";\nimport { FeatureFlags } from \"@webiny/api-core/features/featureFlags/abstractions.js\";\n\nexport const FILE_MODEL_ID = process.env.WEBINY_API_LEGACY_MODELS ? \"fmFile\" : \"wbyFmFile\";\n\nclass FilePrivateModelImpl implements ModelFactory.Interface {\n public constructor(private featureFlags: FeatureFlags.Interface) {}\n\n public async execute(builder: ModelFactory.Builder) {\n const model = builder.private({\n modelId: FILE_MODEL_ID,\n name: \"FmFile\",\n lifecycleEvents: false\n });\n const privateFiles = this.featureFlags\n .get()\n .isEnabled(\"advancedAccessControlLayer.privateFiles\");\n\n model.fields(fields => ({\n name: fields.text().label(\"Name\").required(\"Value is required.\"),\n key: fields.text().label(\"Key\").required(\"Value is required.\"),\n type: fields.text().label(\"Type\").required(\"Value is required.\"),\n size: fields.number().label(\"Size\").required(\"Value is required.\"),\n metadata: fields\n .object()\n .label(\"Metadata\")\n .renderer(\"hidden\")\n .fields(fields => ({\n image: fields\n .object()\n .label(\"Image\")\n .fields(fields => ({\n width: fields.number().label(\"Width\"),\n height: fields.number().label(\"Height\"),\n format: fields.text().label(\"Format\"),\n orientation: fields.number().label(\"Orientation\"),\n crop: fields.json().label(\"Crop\"),\n focalPoint: fields.json().label(\"Focal point\"),\n alt: fields.text().label(\"Alt text\"),\n caption: fields.text().label(\"Caption\")\n })),\n // Store complete raw EXIF as JSON\n exif: fields.searchableJson().label(\"EXIF Data\"),\n // Store complete raw IPTC as JSON\n iptc: fields.searchableJson().label(\"IPTC Data\")\n })),\n tags: fields\n .text()\n .label(\"Tags\")\n .tags([\"$bulk-edit\"])\n .list()\n .required(\"Value is required.\"),\n description: fields.text().label(\"Description\").defaultValue(\"\")\n }));\n\n if (privateFiles) {\n model.fields(fields => ({\n accessControl: fields\n .object()\n .label(\"Access Control\")\n .tags([\"$bulk-edit\"])\n .fields(fields => ({\n type: fields\n .text()\n .label(\"Type\")\n .predefinedValues([\n {\n label: \"Public\",\n value: \"public\",\n selected: true\n },\n {\n label: \"Private\",\n value: \"private-authenticated\",\n selected: false\n }\n ])\n }))\n }));\n }\n\n return [model];\n }\n}\n\nexport const FileModel = ModelFactory.createImplementation({\n implementation: FilePrivateModelImpl,\n dependencies: [FeatureFlags]\n});\n"],"names":["FILE_MODEL_ID","process","FilePrivateModelImpl","featureFlags","builder","model","privateFiles","fields","FileModel","ModelFactory","FeatureFlags"],"mappings":";;AAGO,MAAMA,gBAAgBC,QAAQ,GAAG,CAAC,wBAAwB,GAAG,WAAW;AAE/E,MAAMC;IACF,YAA2BC,YAAoC,CAAE;aAAtCA,YAAY,GAAZA;IAAuC;IAElE,MAAa,QAAQC,OAA6B,EAAE;QAChD,MAAMC,QAAQD,QAAQ,OAAO,CAAC;YAC1B,SAASJ;YACT,MAAM;YACN,iBAAiB;QACrB;QACA,MAAMM,eAAe,IAAI,CAAC,YAAY,CACjC,GAAG,GACH,SAAS,CAAC;QAEfD,MAAM,MAAM,CAACE,CAAAA,SAAW;gBACpB,MAAMA,OAAO,IAAI,GAAG,KAAK,CAAC,QAAQ,QAAQ,CAAC;gBAC3C,KAAKA,OAAO,IAAI,GAAG,KAAK,CAAC,OAAO,QAAQ,CAAC;gBACzC,MAAMA,OAAO,IAAI,GAAG,KAAK,CAAC,QAAQ,QAAQ,CAAC;gBAC3C,MAAMA,OAAO,MAAM,GAAG,KAAK,CAAC,QAAQ,QAAQ,CAAC;gBAC7C,UAAUA,OACL,MAAM,GACN,KAAK,CAAC,YACN,QAAQ,CAAC,UACT,MAAM,CAACA,CAAAA,SAAW;wBACf,OAAOA,OACF,MAAM,GACN,KAAK,CAAC,SACN,MAAM,CAACA,CAAAA,SAAW;gCACf,OAAOA,OAAO,MAAM,GAAG,KAAK,CAAC;gCAC7B,QAAQA,OAAO,MAAM,GAAG,KAAK,CAAC;gCAC9B,QAAQA,OAAO,IAAI,GAAG,KAAK,CAAC;gCAC5B,aAAaA,OAAO,MAAM,GAAG,KAAK,CAAC;gCACnC,MAAMA,OAAO,IAAI,GAAG,KAAK,CAAC;gCAC1B,YAAYA,OAAO,IAAI,GAAG,KAAK,CAAC;gCAChC,KAAKA,OAAO,IAAI,GAAG,KAAK,CAAC;gCACzB,SAASA,OAAO,IAAI,GAAG,KAAK,CAAC;4BACjC;wBAEJ,MAAMA,OAAO,cAAc,GAAG,KAAK,CAAC;wBAEpC,MAAMA,OAAO,cAAc,GAAG,KAAK,CAAC;oBACxC;gBACJ,MAAMA,OACD,IAAI,GACJ,KAAK,CAAC,QACN,IAAI,CAAC;oBAAC;iBAAa,EACnB,IAAI,GACJ,QAAQ,CAAC;gBACd,aAAaA,OAAO,IAAI,GAAG,KAAK,CAAC,eAAe,YAAY,CAAC;YACjE;QAEA,IAAID,cACAD,MAAM,MAAM,CAACE,CAAAA,SAAW;gBACpB,eAAeA,OACV,MAAM,GACN,KAAK,CAAC,kBACN,IAAI,CAAC;oBAAC;iBAAa,EACnB,MAAM,CAACA,CAAAA,SAAW;wBACf,MAAMA,OACD,IAAI,GACJ,KAAK,CAAC,QACN,gBAAgB,CAAC;4BACd;gCACI,OAAO;gCACP,OAAO;gCACP,UAAU;4BACd;4BACA;gCACI,OAAO;gCACP,OAAO;gCACP,UAAU;4BACd;yBACH;oBACT;YACR;QAGJ,OAAO;YAACF;SAAM;IAClB;AACJ;AAEO,MAAMG,YAAYC,aAAa,oBAAoB,CAAC;IACvD,gBAAgBP;IAChB,cAAc;QAACQ;KAAa;AAChC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { InvalidFileKeyError } from "./errors.js";
|
|
3
|
+
/**
|
|
4
|
+
* File keys and IDs end up in storage paths (local disk, S3 object keys). Reject anything that
|
|
5
|
+
* could point outside the tenant's files: absolute paths, `.`/`..` segments, backslashes and NUL bytes.
|
|
6
|
+
*/
|
|
7
|
+
export declare const validateFileKey: (input: {
|
|
8
|
+
key: string;
|
|
9
|
+
id?: string;
|
|
10
|
+
}) => Result<void, InvalidFileKeyError>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { InvalidFileKeyError } from "./errors.js";
|
|
3
|
+
const isUnsafeSegment = (segment)=>"" === segment || "." === segment || ".." === segment;
|
|
4
|
+
const validateFileKey = (input)=>{
|
|
5
|
+
const { key, id } = input;
|
|
6
|
+
const isInvalid = (value)=>/[\\\0]/.test(value) || value.split("/").some(isUnsafeSegment);
|
|
7
|
+
if (!key || isInvalid(key) || void 0 !== id && (isInvalid(id) || id.includes("/"))) return Result.fail(new InvalidFileKeyError({
|
|
8
|
+
key,
|
|
9
|
+
id
|
|
10
|
+
}));
|
|
11
|
+
return Result.ok();
|
|
12
|
+
};
|
|
13
|
+
export { validateFileKey };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=validateFileKey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain/file/validateFileKey.js","sources":["../../../src/domain/file/validateFileKey.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { InvalidFileKeyError } from \"./errors.js\";\n\nconst isUnsafeSegment = (segment: string) => {\n return segment === \"\" || segment === \".\" || segment === \"..\";\n};\n\n/**\n * File keys and IDs end up in storage paths (local disk, S3 object keys). Reject anything that\n * could point outside the tenant's files: absolute paths, `.`/`..` segments, backslashes and NUL bytes.\n */\nexport const validateFileKey = (input: {\n key: string;\n id?: string;\n}): Result<void, InvalidFileKeyError> => {\n const { key, id } = input;\n const isInvalid = (value: string) => {\n return /[\\\\\\0]/.test(value) || value.split(\"/\").some(isUnsafeSegment);\n };\n\n if (!key || isInvalid(key) || (id !== undefined && (isInvalid(id) || id.includes(\"/\")))) {\n return Result.fail(new InvalidFileKeyError({ key, id }));\n }\n\n return Result.ok();\n};\n"],"names":["isUnsafeSegment","segment","validateFileKey","input","key","id","isInvalid","value","undefined","Result","InvalidFileKeyError"],"mappings":";;AAGA,MAAMA,kBAAkB,CAACC,UACdA,AAAY,OAAZA,WAAkBA,AAAY,QAAZA,WAAmBA,AAAY,SAAZA;AAOzC,MAAMC,kBAAkB,CAACC;IAI5B,MAAM,EAAEC,GAAG,EAAEC,EAAE,EAAE,GAAGF;IACpB,MAAMG,YAAY,CAACC,QACR,SAAS,IAAI,CAACA,UAAUA,MAAM,KAAK,CAAC,KAAK,IAAI,CAACP;IAGzD,IAAI,CAACI,OAAOE,UAAUF,QAASC,AAAOG,WAAPH,MAAqBC,CAAAA,UAAUD,OAAOA,GAAG,QAAQ,CAAC,IAAG,GAChF,OAAOI,OAAO,IAAI,CAAC,IAAIC,oBAAoB;QAAEN;QAAKC;IAAG;IAGzD,OAAOI,OAAO,EAAE;AACpB"}
|
|
@@ -2,5 +2,5 @@ import zod from "zod";
|
|
|
2
2
|
export declare const updateSettingsValidation: zod.ZodObject<{
|
|
3
3
|
uploadMinFileSize: zod.ZodOptional<zod.ZodPipe<zod.ZodOptional<zod.ZodNullable<zod.ZodNumber>>, zod.ZodTransform<number, number | null | undefined>>>;
|
|
4
4
|
uploadMaxFileSize: zod.ZodOptional<zod.ZodPipe<zod.ZodOptional<zod.ZodNullable<zod.ZodNumber>>, zod.ZodTransform<number, number | null | undefined>>>;
|
|
5
|
-
srcPrefix: zod.ZodPipe<zod.ZodOptional<zod.ZodString>, zod.ZodTransform<string, string | undefined>>;
|
|
5
|
+
srcPrefix: zod.ZodPipe<zod.ZodOptional<zod.ZodString>, zod.ZodTransform<string | undefined, string | undefined>>;
|
|
6
6
|
}, zod.core.$strip>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import zod from "zod";
|
|
2
|
-
import { ServiceDiscovery } from "@webiny/api-core/features/serviceDiscovery/index.js";
|
|
3
2
|
const MIN_FILE_SIZE = 0;
|
|
4
3
|
const MAX_FILE_SIZE = 10737418240;
|
|
5
4
|
const uploadMinFileSizeValidation = zod.number().min(MIN_FILE_SIZE, {
|
|
@@ -11,15 +10,9 @@ const uploadMaxFileSizeValidation = zod.number().max(MAX_FILE_SIZE, {
|
|
|
11
10
|
const updateSettingsValidation = zod.object({
|
|
12
11
|
uploadMinFileSize: uploadMinFileSizeValidation,
|
|
13
12
|
uploadMaxFileSize: uploadMaxFileSizeValidation,
|
|
14
|
-
srcPrefix: zod.string().optional().transform(
|
|
15
|
-
if (!value)
|
|
16
|
-
|
|
17
|
-
if (!manifest || !manifest.api) return "";
|
|
18
|
-
const { domain } = manifest.api.cloudfront;
|
|
19
|
-
return `https://${domain}/files/`;
|
|
20
|
-
}
|
|
21
|
-
if ("string" == typeof value) return value.endsWith("/") ? value : value + "/";
|
|
22
|
-
return value;
|
|
13
|
+
srcPrefix: zod.string().optional().transform((value)=>{
|
|
14
|
+
if (!value) return value;
|
|
15
|
+
return value.endsWith("/") ? value : value + "/";
|
|
23
16
|
})
|
|
24
17
|
});
|
|
25
18
|
export { updateSettingsValidation };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domain/settings/validation.js","sources":["../../../src/domain/settings/validation.ts"],"sourcesContent":["import zod from \"zod\";\
|
|
1
|
+
{"version":3,"file":"domain/settings/validation.js","sources":["../../../src/domain/settings/validation.ts"],"sourcesContent":["import zod from \"zod\";\n\nconst MIN_FILE_SIZE = 0;\nconst MAX_FILE_SIZE = 10737418240;\n\nconst uploadMinFileSizeValidation = zod\n .number()\n .min(MIN_FILE_SIZE, {\n message: `Value needs to be greater than or equal to ${MIN_FILE_SIZE}.`\n })\n .nullish()\n .transform(value => {\n return value || MIN_FILE_SIZE;\n })\n .optional();\n\nconst uploadMaxFileSizeValidation = zod\n .number()\n .max(MAX_FILE_SIZE, {\n message: `Value needs to be lesser than or equal to ${MAX_FILE_SIZE}.`\n })\n .nullish()\n .transform(value => {\n return value || MAX_FILE_SIZE;\n })\n .optional();\n\nexport const updateSettingsValidation = zod.object({\n uploadMinFileSize: uploadMinFileSizeValidation,\n uploadMaxFileSize: uploadMaxFileSizeValidation,\n /*\n * Omitted stays omitted, so a partial update keeps the stored prefix. An empty value is kept\n * as empty: UpdateSettingsUseCase stores it as \"no custom prefix\".\n */\n srcPrefix: zod\n .string()\n .optional()\n .transform(value => {\n if (!value) {\n return value;\n }\n return value.endsWith(\"/\") ? value : value + \"/\";\n })\n});\n"],"names":["MIN_FILE_SIZE","MAX_FILE_SIZE","uploadMinFileSizeValidation","zod","value","uploadMaxFileSizeValidation","updateSettingsValidation"],"mappings":";AAEA,MAAMA,gBAAgB;AACtB,MAAMC,gBAAgB;AAEtB,MAAMC,8BAA8BC,IAAAA,MACzB,GACN,GAAG,CAACH,eAAe;IAChB,SAAS,CAAC,2CAA2C,EAAEA,cAAc,CAAC,CAAC;AAC3E,GACC,OAAO,GACP,SAAS,CAACI,CAAAA,QACAA,SAASJ,eAEnB,QAAQ;AAEb,MAAMK,8BAA8BF,IAAAA,MACzB,GACN,GAAG,CAACF,eAAe;IAChB,SAAS,CAAC,0CAA0C,EAAEA,cAAc,CAAC,CAAC;AAC1E,GACC,OAAO,GACP,SAAS,CAACG,CAAAA,QACAA,SAASH,eAEnB,QAAQ;AAEN,MAAMK,2BAA2BH,IAAI,MAAM,CAAC;IAC/C,mBAAmBD;IACnB,mBAAmBG;IAKnB,WAAWF,IAAAA,MACA,GACN,QAAQ,GACR,SAAS,CAACC,CAAAA;QACP,IAAI,CAACA,OACD,OAAOA;QAEX,OAAOA,MAAM,QAAQ,CAAC,OAAOA,QAAQA,QAAQ;IACjD;AACR"}
|
|
@@ -6,8 +6,9 @@ export { UpdateFileRepository, UpdateFileUseCase } from "../../../features/file/
|
|
|
6
6
|
export { FileAfterUpdateEventHandler, FileBeforeUpdateEventHandler } from "../../../features/file/UpdateFile/events.js";
|
|
7
7
|
export { DeleteFileRepository, DeleteFileUseCase } from "../../../features/file/DeleteFile/abstractions.js";
|
|
8
8
|
export { FileAfterDeleteEventHandler, FileBeforeDeleteEventHandler } from "../../../features/file/DeleteFile/events.js";
|
|
9
|
-
export { FileUrlGenerator } from "../../../features/file/FileUrlGenerator/abstractions.js";
|
|
9
|
+
export { FileUrlGenerator, FileUrlPrefixProvider } from "../../../features/file/FileUrlGenerator/abstractions.js";
|
|
10
10
|
export { GetFileRepository, GetFileUseCase } from "../../../features/file/GetFile/abstractions.js";
|
|
11
11
|
export { GetFileByUrlUseCase } from "../../../features/file/GetFileByUrl/abstractions.js";
|
|
12
|
+
export { GetFileContentsByIdUseCase } from "../../../features/file/GetFileContentsById/abstractions.js";
|
|
12
13
|
export { ListFilesRepository, ListFilesUseCase } from "../../../features/file/ListFiles/abstractions.js";
|
|
13
14
|
export { ListTagsRepository, ListTagsUseCase } from "../../../features/file/ListTags/abstractions.js";
|
|
@@ -6,8 +6,9 @@ export { UpdateFileRepository, UpdateFileUseCase } from "../../../features/file/
|
|
|
6
6
|
export { FileAfterUpdateEventHandler, FileBeforeUpdateEventHandler } from "../../../features/file/UpdateFile/events.js";
|
|
7
7
|
export { DeleteFileRepository, DeleteFileUseCase } from "../../../features/file/DeleteFile/abstractions.js";
|
|
8
8
|
export { FileAfterDeleteEventHandler, FileBeforeDeleteEventHandler } from "../../../features/file/DeleteFile/events.js";
|
|
9
|
-
export { FileUrlGenerator } from "../../../features/file/FileUrlGenerator/abstractions.js";
|
|
9
|
+
export { FileUrlGenerator, FileUrlPrefixProvider } from "../../../features/file/FileUrlGenerator/abstractions.js";
|
|
10
10
|
export { GetFileRepository, GetFileUseCase } from "../../../features/file/GetFile/abstractions.js";
|
|
11
11
|
export { GetFileByUrlUseCase } from "../../../features/file/GetFileByUrl/abstractions.js";
|
|
12
|
+
export { GetFileContentsByIdUseCase } from "../../../features/file/GetFileContentsById/abstractions.js";
|
|
12
13
|
export { ListFilesRepository, ListFilesUseCase } from "../../../features/file/ListFiles/abstractions.js";
|
|
13
14
|
export { ListTagsRepository, ListTagsUseCase } from "../../../features/file/ListTags/abstractions.js";
|
|
@@ -7,6 +7,7 @@ import { ListFilesFeature } from "./file/ListFiles/feature.js";
|
|
|
7
7
|
import { ListTagsFeature } from "./file/ListTags/feature.js";
|
|
8
8
|
import { UpdateFileFeature } from "./file/UpdateFile/feature.js";
|
|
9
9
|
import { SettingsInstallerFeature } from "./settings/SettingsInstaller/feature.js";
|
|
10
|
+
import { DefaultSrcPrefixFeature } from "./settings/DefaultSrcPrefix/feature.js";
|
|
10
11
|
import { GetSettingsFeature } from "./settings/GetSettings/feature.js";
|
|
11
12
|
import { UpdateSettingsFeature } from "./settings/UpdateSettings/feature.js";
|
|
12
13
|
import { ListImagesByTagToolFeature } from "./file/ListImagesByTagTool/feature.js";
|
|
@@ -24,6 +25,7 @@ const FileManagerFeature = createFeature({
|
|
|
24
25
|
ListFilesFeature.register(container);
|
|
25
26
|
ListTagsFeature.register(container);
|
|
26
27
|
SettingsInstallerFeature.register(container);
|
|
28
|
+
DefaultSrcPrefixFeature.register(container);
|
|
27
29
|
GetSettingsFeature.register(container);
|
|
28
30
|
UpdateSettingsFeature.register(container);
|
|
29
31
|
ListImagesByTagToolFeature.register(container);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/FileManagerFeature.js","sources":["../../src/features/FileManagerFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { CreateFileFeature } from \"~/features/file/CreateFile/feature.js\";\nimport { CreateFilesInBatchFeature } from \"~/features/file/CreateFilesInBatch/feature.js\";\nimport { DeleteFileFeature } from \"~/features/file/DeleteFile/feature.js\";\nimport { GetFileFeature } from \"~/features/file/GetFile/feature.js\";\nimport { ListFilesFeature } from \"~/features/file/ListFiles/feature.js\";\nimport { ListTagsFeature } from \"~/features/file/ListTags/feature.js\";\nimport { UpdateFileFeature } from \"~/features/file/UpdateFile/feature.js\";\nimport { SettingsInstallerFeature } from \"~/features/settings/SettingsInstaller/feature.js\";\nimport { GetSettingsFeature } from \"~/features/settings/GetSettings/feature.js\";\nimport { UpdateSettingsFeature } from \"~/features/settings/UpdateSettings/feature.js\";\nimport { ListImagesByTagToolFeature } from \"~/features/file/ListImagesByTagTool/feature.js\";\nimport { FileUrlGeneratorFeature } from \"~/features/file/FileUrlGenerator/feature.js\";\nimport { GetFileByUrlFeature } from \"~/features/file/GetFileByUrl/feature.js\";\nimport { FmGraphQLSchema } from \"~/graphql/FmGraphQLSchema.js\";\n\nexport const FileManagerFeature = createFeature({\n name: \"FileManager\",\n register(container) {\n CreateFileFeature.register(container);\n CreateFilesInBatchFeature.register(container);\n UpdateFileFeature.register(container);\n DeleteFileFeature.register(container);\n GetFileFeature.register(container);\n ListFilesFeature.register(container);\n ListTagsFeature.register(container);\n SettingsInstallerFeature.register(container);\n GetSettingsFeature.register(container);\n UpdateSettingsFeature.register(container);\n ListImagesByTagToolFeature.register(container);\n FileUrlGeneratorFeature.register(container);\n GetFileByUrlFeature.register(container);\n\n /* GraphQL schema factory. */\n container.register(FmGraphQLSchema);\n }\n});\n"],"names":["FileManagerFeature","createFeature","container","CreateFileFeature","CreateFilesInBatchFeature","UpdateFileFeature","DeleteFileFeature","GetFileFeature","ListFilesFeature","ListTagsFeature","SettingsInstallerFeature","GetSettingsFeature","UpdateSettingsFeature","ListImagesByTagToolFeature","FileUrlGeneratorFeature","GetFileByUrlFeature","FmGraphQLSchema"],"mappings":"
|
|
1
|
+
{"version":3,"file":"features/FileManagerFeature.js","sources":["../../src/features/FileManagerFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { CreateFileFeature } from \"~/features/file/CreateFile/feature.js\";\nimport { CreateFilesInBatchFeature } from \"~/features/file/CreateFilesInBatch/feature.js\";\nimport { DeleteFileFeature } from \"~/features/file/DeleteFile/feature.js\";\nimport { GetFileFeature } from \"~/features/file/GetFile/feature.js\";\nimport { ListFilesFeature } from \"~/features/file/ListFiles/feature.js\";\nimport { ListTagsFeature } from \"~/features/file/ListTags/feature.js\";\nimport { UpdateFileFeature } from \"~/features/file/UpdateFile/feature.js\";\nimport { SettingsInstallerFeature } from \"~/features/settings/SettingsInstaller/feature.js\";\nimport { DefaultSrcPrefixFeature } from \"~/features/settings/DefaultSrcPrefix/feature.js\";\nimport { GetSettingsFeature } from \"~/features/settings/GetSettings/feature.js\";\nimport { UpdateSettingsFeature } from \"~/features/settings/UpdateSettings/feature.js\";\nimport { ListImagesByTagToolFeature } from \"~/features/file/ListImagesByTagTool/feature.js\";\nimport { FileUrlGeneratorFeature } from \"~/features/file/FileUrlGenerator/feature.js\";\nimport { GetFileByUrlFeature } from \"~/features/file/GetFileByUrl/feature.js\";\nimport { FmGraphQLSchema } from \"~/graphql/FmGraphQLSchema.js\";\n\nexport const FileManagerFeature = createFeature({\n name: \"FileManager\",\n register(container) {\n CreateFileFeature.register(container);\n CreateFilesInBatchFeature.register(container);\n UpdateFileFeature.register(container);\n DeleteFileFeature.register(container);\n GetFileFeature.register(container);\n ListFilesFeature.register(container);\n ListTagsFeature.register(container);\n SettingsInstallerFeature.register(container);\n DefaultSrcPrefixFeature.register(container);\n GetSettingsFeature.register(container);\n UpdateSettingsFeature.register(container);\n ListImagesByTagToolFeature.register(container);\n FileUrlGeneratorFeature.register(container);\n GetFileByUrlFeature.register(container);\n\n /* GraphQL schema factory. */\n container.register(FmGraphQLSchema);\n }\n});\n"],"names":["FileManagerFeature","createFeature","container","CreateFileFeature","CreateFilesInBatchFeature","UpdateFileFeature","DeleteFileFeature","GetFileFeature","ListFilesFeature","ListTagsFeature","SettingsInstallerFeature","DefaultSrcPrefixFeature","GetSettingsFeature","UpdateSettingsFeature","ListImagesByTagToolFeature","FileUrlGeneratorFeature","GetFileByUrlFeature","FmGraphQLSchema"],"mappings":";;;;;;;;;;;;;;;;AAiBO,MAAMA,qBAAqBC,cAAc;IAC5C,MAAM;IACN,UAASC,SAAS;QACdC,kBAAkB,QAAQ,CAACD;QAC3BE,0BAA0B,QAAQ,CAACF;QACnCG,kBAAkB,QAAQ,CAACH;QAC3BI,kBAAkB,QAAQ,CAACJ;QAC3BK,eAAe,QAAQ,CAACL;QACxBM,iBAAiB,QAAQ,CAACN;QAC1BO,gBAAgB,QAAQ,CAACP;QACzBQ,yBAAyB,QAAQ,CAACR;QAClCS,wBAAwB,QAAQ,CAACT;QACjCU,mBAAmB,QAAQ,CAACV;QAC5BW,sBAAsB,QAAQ,CAACX;QAC/BY,2BAA2B,QAAQ,CAACZ;QACpCa,wBAAwB,QAAQ,CAACb;QACjCc,oBAAoB,QAAQ,CAACd;QAG7BA,UAAU,QAAQ,CAACe;IACvB;AACJ"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Abstraction } from "@webiny/di";
|
|
2
|
+
import type { AssetRequest as IAssetRequest } from "../../../delivery/AssetDelivery/AssetRequest.js";
|
|
3
|
+
import type { Asset as IAsset } from "../../../delivery/AssetDelivery/Asset.js";
|
|
4
|
+
export interface IAssetTypeHandler {
|
|
5
|
+
handle(assetRequest: IAssetRequest, asset: IAsset): Promise<IAsset>;
|
|
6
|
+
}
|
|
7
|
+
export interface IAssetType {
|
|
8
|
+
canHandle(asset: IAsset): boolean;
|
|
9
|
+
getHandlerAbstraction(): Abstraction<IAssetTypeHandler>;
|
|
10
|
+
}
|
|
11
|
+
export declare const AssetType: Abstraction<IAssetType>;
|
|
12
|
+
export declare namespace AssetType {
|
|
13
|
+
type Interface = IAssetType;
|
|
14
|
+
type AssetRequest = IAssetRequest;
|
|
15
|
+
type Asset = IAsset;
|
|
16
|
+
type Handler = IAssetTypeHandler;
|
|
17
|
+
}
|