@webiny/api-file-manager 6.6.0-alpha.1 → 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/delivery/AssetDeliveryRoute.d.ts +1 -0
- package/delivery/AssetDeliveryRoute.js +13 -2
- package/delivery/AssetDeliveryRoute.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.js +2 -1
- 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/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/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/ListImagesByTagTool/ListImagesByTagTool.d.ts +10 -5
- package/features/file/ListImagesByTagTool/ListImagesByTagTool.js +21 -12
- package/features/file/ListImagesByTagTool/ListImagesByTagTool.js.map +1 -1
- package/features/file/ListTags/ListTagsRepository.js +21 -2
- package/features/file/ListTags/ListTagsRepository.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/utils/FileNormalizer.js +8 -1
- package/features/upload/utils/FileNormalizer.js.map +1 -1
- package/graphql/FmGraphQLSchema.d.ts +2 -3
- package/graphql/FmGraphQLSchema.js +22 -5
- package/graphql/FmGraphQLSchema.js.map +1 -1
- package/package.json +19 -19
|
@@ -4,6 +4,7 @@ declare class AssetDeliveryRouteImpl implements HttpRouteHandler.Interface {
|
|
|
4
4
|
private container;
|
|
5
5
|
constructor(container: Container);
|
|
6
6
|
handle(request: HttpRouteHandler.Request, response: HttpRouteHandler.Response): Promise<import("@webiny/event-handler-core").IHttpResponseBuilder>;
|
|
7
|
+
private deliver;
|
|
7
8
|
}
|
|
8
9
|
export declare const AssetDeliveryRoute: typeof AssetDeliveryRouteImpl & {
|
|
9
10
|
__abstraction: import("@webiny/di").Abstraction<import("@webiny/event-handler-core").IHttpRoute>;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
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
5
|
const NO_CACHE = "no-cache, no-store, must-revalidate";
|
|
4
6
|
class AssetDeliveryRouteImpl {
|
|
@@ -8,8 +10,8 @@ class AssetDeliveryRouteImpl {
|
|
|
8
10
|
async handle(request, response) {
|
|
9
11
|
const requestResolver = this.container.resolve(AssetRequestResolver);
|
|
10
12
|
const assetResolver = this.container.resolve(AssetResolver);
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
+
const tenantContext = this.container.resolve(TenantContext);
|
|
14
|
+
const getTenantById = this.container.resolve(GetTenantByIdUseCase);
|
|
13
15
|
const fakeRequest = {
|
|
14
16
|
url: request.path,
|
|
15
17
|
params: {
|
|
@@ -26,6 +28,15 @@ class AssetDeliveryRouteImpl {
|
|
|
26
28
|
if (!resolvedAsset) return response.status(404).header("cache-control", NO_CACHE).json({
|
|
27
29
|
error: "Asset not found!"
|
|
28
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);
|
|
29
40
|
resolvedAsset.setOutputStrategy(outputStrategy);
|
|
30
41
|
const processedAsset = await assetProcessor.process(resolvedRequest, resolvedAsset);
|
|
31
42
|
const assetReply = await processedAsset.output();
|
|
@@ -1 +1 @@
|
|
|
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 {\n AssetRequestResolver,\n AssetResolver,\n AssetProcessor,\n AssetOutputStrategy\n} from \"~/features/assetDelivery/abstractions.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
|
|
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"}
|
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"}
|
|
@@ -8,7 +8,8 @@ class FilePrivateModelImpl {
|
|
|
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
14
|
const privateFiles = this.featureFlags.get().isEnabled("advancedAccessControlLayer.privateFiles");
|
|
14
15
|
model.fields((fields)=>({
|
|
@@ -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 { 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 });\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;
|
|
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"}
|
|
@@ -3,6 +3,7 @@ import { CreateFileRepository, CreateFileUseCase } from "./abstractions.js";
|
|
|
3
3
|
import { GetSettingsUseCase } from "../../settings/GetSettings/abstractions.js";
|
|
4
4
|
import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
5
5
|
import { FileNotAuthorizedError, InvalidFileSizeError } from "../../../domain/file/errors.js";
|
|
6
|
+
import { validateFileKey } from "../../../domain/file/validateFileKey.js";
|
|
6
7
|
import { FileAfterCreateEvent, FileBeforeCreateEvent } from "./events.js";
|
|
7
8
|
import { FmPermissions } from "../../shared/abstractions.js";
|
|
8
9
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
@@ -55,6 +56,11 @@ class CreateFileUseCaseImpl {
|
|
|
55
56
|
return Result.ok(result.value);
|
|
56
57
|
}
|
|
57
58
|
async validateInput(input) {
|
|
59
|
+
const keyResult = validateFileKey({
|
|
60
|
+
key: input.key,
|
|
61
|
+
id: input.id
|
|
62
|
+
});
|
|
63
|
+
if (keyResult.isFail()) return keyResult;
|
|
58
64
|
const settingsResult = await this.getSettings.execute();
|
|
59
65
|
if (settingsResult.isFail()) return Result.ok();
|
|
60
66
|
const settings = settingsResult.value;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/file/CreateFile/CreateFileUseCase.js","sources":["../../../../src/features/file/CreateFile/CreateFileUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n CreateFileUseCase as UseCaseAbstraction,\n CreateFileInput,\n CreateFileRepository\n} from \"./abstractions.js\";\nimport { GetSettingsUseCase } from \"../../settings/GetSettings/abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport type { File, FileInput } from \"~/domain/file/types.js\";\nimport { FileNotAuthorizedError, InvalidFileSizeError } from \"~/domain/file/errors.js\";\nimport { FileBeforeCreateEvent, FileAfterCreateEvent } from \"./events.js\";\nimport { FmPermissions } from \"~/features/shared/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { Identity } from \"~/domain/identity/Identity.js\";\n\nclass CreateFileUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private permissions: FmPermissions.Interface,\n private repository: CreateFileRepository.Interface,\n private getSettings: GetSettingsUseCase.Interface,\n private eventPublisher: EventPublisher.Interface\n ) {}\n\n async execute(\n input: CreateFileInput,\n meta?: Record<string, any>\n ): Promise<Result<File, UseCaseAbstraction.Error>> {\n const hasPermission = await this.permissions.canCreate(\"file\");\n if (!hasPermission) {\n return Result.fail(new FileNotAuthorizedError());\n }\n\n const validationResult = await this.validateInput(input);\n if (validationResult.isFail()) {\n return Result.fail(validationResult.error);\n }\n\n const [id] = input.key.split(\"/\");\n const currentIdentity = this.identityContext.getIdentity();\n\n // Prepare file input\n const fileInput: FileInput = {\n id: input.id || id,\n key: input.key,\n name: input.name,\n size: input.size,\n type: input.type,\n metadata: input.metadata || {},\n location: input.location || { folderId: \"root\" },\n tags: input.tags || [],\n description: input.description ?? \"\",\n extensions: meta || {},\n // system attributes\n createdOn: input.createdOn,\n modifiedOn: input.modifiedOn,\n savedOn: input.savedOn,\n createdBy: input.createdBy\n ? Identity.from(input.createdBy)\n : Identity.from(currentIdentity),\n modifiedBy: input.modifiedBy ? Identity.from(input.modifiedBy) : undefined,\n savedBy: input.savedBy ? Identity.from(input.savedBy) : Identity.from(currentIdentity)\n };\n\n await this.eventPublisher.publish(new FileBeforeCreateEvent({ file: fileInput, meta }));\n\n const result = await this.repository.execute(fileInput);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n await this.eventPublisher.publish(new FileAfterCreateEvent({ file: result.value, meta }));\n\n return Result.ok(result.value);\n }\n\n private async validateInput(\n input: CreateFileInput\n ): Promise<Result<void, InvalidFileSizeError>> {\n const settingsResult = await this.getSettings.execute();\n\n if (settingsResult.isFail()) {\n return Result.ok();\n }\n\n const settings = settingsResult.value;\n\n if (settings) {\n // Validate file size\n if (\n input.size < settings.uploadMinFileSize ||\n input.size > settings.uploadMaxFileSize\n ) {\n return Result.fail(\n new InvalidFileSizeError({\n size: input.size,\n minSize: settings.uploadMinFileSize,\n maxSize: settings.uploadMaxFileSize\n })\n );\n }\n }\n\n return Result.ok();\n }\n}\n\nexport const CreateFileUseCase = UseCaseAbstraction.createImplementation({\n implementation: CreateFileUseCaseImpl,\n dependencies: [\n IdentityContext,\n FmPermissions,\n CreateFileRepository,\n GetSettingsUseCase,\n EventPublisher\n ]\n});\n"],"names":["CreateFileUseCaseImpl","identityContext","permissions","repository","getSettings","eventPublisher","input","meta","hasPermission","Result","FileNotAuthorizedError","validationResult","id","currentIdentity","fileInput","Identity","undefined","FileBeforeCreateEvent","result","FileAfterCreateEvent","settingsResult","settings","InvalidFileSizeError","CreateFileUseCase","UseCaseAbstraction","IdentityContext","FmPermissions","CreateFileRepository","GetSettingsUseCase","EventPublisher"],"mappings":"
|
|
1
|
+
{"version":3,"file":"features/file/CreateFile/CreateFileUseCase.js","sources":["../../../../src/features/file/CreateFile/CreateFileUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n CreateFileUseCase as UseCaseAbstraction,\n CreateFileInput,\n CreateFileRepository\n} from \"./abstractions.js\";\nimport { GetSettingsUseCase } from \"../../settings/GetSettings/abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport type { File, FileInput } from \"~/domain/file/types.js\";\nimport { FileNotAuthorizedError, InvalidFileSizeError } from \"~/domain/file/errors.js\";\nimport type { InvalidFileKeyError } from \"~/domain/file/errors.js\";\nimport { validateFileKey } from \"~/domain/file/validateFileKey.js\";\nimport { FileBeforeCreateEvent, FileAfterCreateEvent } from \"./events.js\";\nimport { FmPermissions } from \"~/features/shared/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { Identity } from \"~/domain/identity/Identity.js\";\n\nclass CreateFileUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private permissions: FmPermissions.Interface,\n private repository: CreateFileRepository.Interface,\n private getSettings: GetSettingsUseCase.Interface,\n private eventPublisher: EventPublisher.Interface\n ) {}\n\n async execute(\n input: CreateFileInput,\n meta?: Record<string, any>\n ): Promise<Result<File, UseCaseAbstraction.Error>> {\n const hasPermission = await this.permissions.canCreate(\"file\");\n if (!hasPermission) {\n return Result.fail(new FileNotAuthorizedError());\n }\n\n const validationResult = await this.validateInput(input);\n if (validationResult.isFail()) {\n return Result.fail(validationResult.error);\n }\n\n const [id] = input.key.split(\"/\");\n const currentIdentity = this.identityContext.getIdentity();\n\n // Prepare file input\n const fileInput: FileInput = {\n id: input.id || id,\n key: input.key,\n name: input.name,\n size: input.size,\n type: input.type,\n metadata: input.metadata || {},\n location: input.location || { folderId: \"root\" },\n tags: input.tags || [],\n description: input.description ?? \"\",\n extensions: meta || {},\n // system attributes\n createdOn: input.createdOn,\n modifiedOn: input.modifiedOn,\n savedOn: input.savedOn,\n createdBy: input.createdBy\n ? Identity.from(input.createdBy)\n : Identity.from(currentIdentity),\n modifiedBy: input.modifiedBy ? Identity.from(input.modifiedBy) : undefined,\n savedBy: input.savedBy ? Identity.from(input.savedBy) : Identity.from(currentIdentity)\n };\n\n await this.eventPublisher.publish(new FileBeforeCreateEvent({ file: fileInput, meta }));\n\n const result = await this.repository.execute(fileInput);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n await this.eventPublisher.publish(new FileAfterCreateEvent({ file: result.value, meta }));\n\n return Result.ok(result.value);\n }\n\n private async validateInput(\n input: CreateFileInput\n ): Promise<Result<void, InvalidFileKeyError | InvalidFileSizeError>> {\n const keyResult = validateFileKey({ key: input.key, id: input.id });\n if (keyResult.isFail()) {\n return keyResult;\n }\n\n const settingsResult = await this.getSettings.execute();\n\n if (settingsResult.isFail()) {\n return Result.ok();\n }\n\n const settings = settingsResult.value;\n\n if (settings) {\n // Validate file size\n if (\n input.size < settings.uploadMinFileSize ||\n input.size > settings.uploadMaxFileSize\n ) {\n return Result.fail(\n new InvalidFileSizeError({\n size: input.size,\n minSize: settings.uploadMinFileSize,\n maxSize: settings.uploadMaxFileSize\n })\n );\n }\n }\n\n return Result.ok();\n }\n}\n\nexport const CreateFileUseCase = UseCaseAbstraction.createImplementation({\n implementation: CreateFileUseCaseImpl,\n dependencies: [\n IdentityContext,\n FmPermissions,\n CreateFileRepository,\n GetSettingsUseCase,\n EventPublisher\n ]\n});\n"],"names":["CreateFileUseCaseImpl","identityContext","permissions","repository","getSettings","eventPublisher","input","meta","hasPermission","Result","FileNotAuthorizedError","validationResult","id","currentIdentity","fileInput","Identity","undefined","FileBeforeCreateEvent","result","FileAfterCreateEvent","keyResult","validateFileKey","settingsResult","settings","InvalidFileSizeError","CreateFileUseCase","UseCaseAbstraction","IdentityContext","FmPermissions","CreateFileRepository","GetSettingsUseCase","EventPublisher"],"mappings":";;;;;;;;;;AAiBA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,WAAoC,EACpCC,UAA0C,EAC1CC,WAAyC,EACzCC,cAAwC,CAClD;aALUJ,eAAe,GAAfA;aACAC,WAAW,GAAXA;aACAC,UAAU,GAAVA;aACAC,WAAW,GAAXA;aACAC,cAAc,GAAdA;IACT;IAEH,MAAM,QACFC,KAAsB,EACtBC,IAA0B,EACqB;QAC/C,MAAMC,gBAAgB,MAAM,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC;QACvD,IAAI,CAACA,eACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,mBAAmB,MAAM,IAAI,CAAC,aAAa,CAACL;QAClD,IAAIK,iBAAiB,MAAM,IACvB,OAAOF,OAAO,IAAI,CAACE,iBAAiB,KAAK;QAG7C,MAAM,CAACC,GAAG,GAAGN,MAAM,GAAG,CAAC,KAAK,CAAC;QAC7B,MAAMO,kBAAkB,IAAI,CAAC,eAAe,CAAC,WAAW;QAGxD,MAAMC,YAAuB;YACzB,IAAIR,MAAM,EAAE,IAAIM;YAChB,KAAKN,MAAM,GAAG;YACd,MAAMA,MAAM,IAAI;YAChB,MAAMA,MAAM,IAAI;YAChB,MAAMA,MAAM,IAAI;YAChB,UAAUA,MAAM,QAAQ,IAAI,CAAC;YAC7B,UAAUA,MAAM,QAAQ,IAAI;gBAAE,UAAU;YAAO;YAC/C,MAAMA,MAAM,IAAI,IAAI,EAAE;YACtB,aAAaA,MAAM,WAAW,IAAI;YAClC,YAAYC,QAAQ,CAAC;YAErB,WAAWD,MAAM,SAAS;YAC1B,YAAYA,MAAM,UAAU;YAC5B,SAASA,MAAM,OAAO;YACtB,WAAWA,MAAM,SAAS,GACpBS,SAAS,IAAI,CAACT,MAAM,SAAS,IAC7BS,SAAS,IAAI,CAACF;YACpB,YAAYP,MAAM,UAAU,GAAGS,SAAS,IAAI,CAACT,MAAM,UAAU,IAAIU;YACjE,SAASV,MAAM,OAAO,GAAGS,SAAS,IAAI,CAACT,MAAM,OAAO,IAAIS,SAAS,IAAI,CAACF;QAC1E;QAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAII,sBAAsB;YAAE,MAAMH;YAAWP;QAAK;QAEpF,MAAMW,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACJ;QAE7C,IAAII,OAAO,MAAM,IACb,OAAOT,OAAO,IAAI,CAACS,OAAO,KAAK;QAGnC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAIC,qBAAqB;YAAE,MAAMD,OAAO,KAAK;YAAEX;QAAK;QAEtF,OAAOE,OAAO,EAAE,CAACS,OAAO,KAAK;IACjC;IAEA,MAAc,cACVZ,KAAsB,EAC2C;QACjE,MAAMc,YAAYC,gBAAgB;YAAE,KAAKf,MAAM,GAAG;YAAE,IAAIA,MAAM,EAAE;QAAC;QACjE,IAAIc,UAAU,MAAM,IAChB,OAAOA;QAGX,MAAME,iBAAiB,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO;QAErD,IAAIA,eAAe,MAAM,IACrB,OAAOb,OAAO,EAAE;QAGpB,MAAMc,WAAWD,eAAe,KAAK;QAErC,IAAIC,UAEA;YAAA,IACIjB,MAAM,IAAI,GAAGiB,SAAS,iBAAiB,IACvCjB,MAAM,IAAI,GAAGiB,SAAS,iBAAiB,EAEvC,OAAOd,OAAO,IAAI,CACd,IAAIe,qBAAqB;gBACrB,MAAMlB,MAAM,IAAI;gBAChB,SAASiB,SAAS,iBAAiB;gBACnC,SAASA,SAAS,iBAAiB;YACvC;QAER;QAGJ,OAAOd,OAAO,EAAE;IACpB;AACJ;AAEO,MAAMgB,sCAAoBC,kBAAAA,oBAAuC,CAAC;IACrE,gBAAgB1B;IAChB,cAAc;QACV2B;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { InvalidFileKeyError } from "../../../domain/file/errors.js";
|
|
1
2
|
import type { Result } from "@webiny/feature/api";
|
|
2
3
|
import type { CreatedBy, File, FileInput } from "../../../domain/file/types.js";
|
|
3
4
|
import { type FilePersistenceError, type InvalidFileSizeError, type FileAlreadyExistsError, FileNotAuthorizedError } from "../../../domain/file/errors.js";
|
|
@@ -48,6 +49,7 @@ export interface ICreateFileUseCaseErrors {
|
|
|
48
49
|
notAuthorized: FileNotAuthorizedError;
|
|
49
50
|
persistence: FilePersistenceError;
|
|
50
51
|
invalidSize: InvalidFileSizeError;
|
|
52
|
+
invalidKey: InvalidFileKeyError;
|
|
51
53
|
alreadyExists: FileAlreadyExistsError;
|
|
52
54
|
}
|
|
53
55
|
type UseCaseError = ICreateFileUseCaseErrors[keyof ICreateFileUseCaseErrors];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/file/CreateFile/abstractions.js","sources":["../../../../src/features/file/CreateFile/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport type { CreatedBy, File, FileInput } from \"~/domain/file/types.js\";\nimport {\n type FilePersistenceError,\n type InvalidFileSizeError,\n type FileAlreadyExistsError,\n FileNotAuthorizedError\n} from \"~/domain/file/errors.js\";\n\nexport interface CreateFileInput {\n id?: string;\n key: string;\n size: number;\n type: string;\n name: string;\n metadata?: Record<string, any>;\n extensions?: Record<string, any>;\n tags?: string[];\n description?: string;\n location?: { folderId: string };\n // System attributes\n createdOn?: string;\n createdBy?: CreatedBy;\n modifiedOn?: string;\n modifiedBy?: CreatedBy;\n savedOn?: string;\n savedBy?: CreatedBy;\n}\n\n/**\n * CreateFile repository interface\n */\nexport interface ICreateFileRepository {\n execute(data: FileInput): Promise<Result<File, RepositoryError>>;\n}\n\nexport interface ICreateFileRepositoryErrors {\n notAuthorized: FileNotAuthorizedError;\n persistence: FilePersistenceError;\n}\n\ntype RepositoryError = ICreateFileRepositoryErrors[keyof ICreateFileRepositoryErrors];\n\n/** Persist a newly created file. */\nexport const CreateFileRepository =\n createAbstraction<ICreateFileRepository>(\"CreateFileRepository\");\n\nexport namespace CreateFileRepository {\n export type Interface = ICreateFileRepository;\n export type Error = RepositoryError;\n}\n\n/**\n * CreateFile use case interface\n */\nexport interface ICreateFileUseCase {\n execute(\n input: CreateFileInput,\n meta?: Record<string, any>\n ): Promise<Result<File, UseCaseError>>;\n}\n\nexport interface ICreateFileUseCaseErrors {\n notAuthorized: FileNotAuthorizedError;\n persistence: FilePersistenceError;\n invalidSize: InvalidFileSizeError;\n alreadyExists: FileAlreadyExistsError;\n}\n\ntype UseCaseError = ICreateFileUseCaseErrors[keyof ICreateFileUseCaseErrors];\n\n/** Upload and create a new file. */\nexport const CreateFileUseCase = createAbstraction<ICreateFileUseCase>(\"CreateFileUseCase\");\n\nexport namespace CreateFileUseCase {\n export type Interface = ICreateFileUseCase;\n export type Error = UseCaseError;\n}\n"],"names":["CreateFileRepository","createAbstraction","CreateFileUseCase"],"mappings":";
|
|
1
|
+
{"version":3,"file":"features/file/CreateFile/abstractions.js","sources":["../../../../src/features/file/CreateFile/abstractions.ts"],"sourcesContent":["import type { InvalidFileKeyError } from \"~/domain/file/errors.js\";\nimport { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport type { CreatedBy, File, FileInput } from \"~/domain/file/types.js\";\nimport {\n type FilePersistenceError,\n type InvalidFileSizeError,\n type FileAlreadyExistsError,\n FileNotAuthorizedError\n} from \"~/domain/file/errors.js\";\n\nexport interface CreateFileInput {\n id?: string;\n key: string;\n size: number;\n type: string;\n name: string;\n metadata?: Record<string, any>;\n extensions?: Record<string, any>;\n tags?: string[];\n description?: string;\n location?: { folderId: string };\n // System attributes\n createdOn?: string;\n createdBy?: CreatedBy;\n modifiedOn?: string;\n modifiedBy?: CreatedBy;\n savedOn?: string;\n savedBy?: CreatedBy;\n}\n\n/**\n * CreateFile repository interface\n */\nexport interface ICreateFileRepository {\n execute(data: FileInput): Promise<Result<File, RepositoryError>>;\n}\n\nexport interface ICreateFileRepositoryErrors {\n notAuthorized: FileNotAuthorizedError;\n persistence: FilePersistenceError;\n}\n\ntype RepositoryError = ICreateFileRepositoryErrors[keyof ICreateFileRepositoryErrors];\n\n/** Persist a newly created file. */\nexport const CreateFileRepository =\n createAbstraction<ICreateFileRepository>(\"CreateFileRepository\");\n\nexport namespace CreateFileRepository {\n export type Interface = ICreateFileRepository;\n export type Error = RepositoryError;\n}\n\n/**\n * CreateFile use case interface\n */\nexport interface ICreateFileUseCase {\n execute(\n input: CreateFileInput,\n meta?: Record<string, any>\n ): Promise<Result<File, UseCaseError>>;\n}\n\nexport interface ICreateFileUseCaseErrors {\n notAuthorized: FileNotAuthorizedError;\n persistence: FilePersistenceError;\n invalidSize: InvalidFileSizeError;\n invalidKey: InvalidFileKeyError;\n alreadyExists: FileAlreadyExistsError;\n}\n\ntype UseCaseError = ICreateFileUseCaseErrors[keyof ICreateFileUseCaseErrors];\n\n/** Upload and create a new file. */\nexport const CreateFileUseCase = createAbstraction<ICreateFileUseCase>(\"CreateFileUseCase\");\n\nexport namespace CreateFileUseCase {\n export type Interface = ICreateFileUseCase;\n export type Error = UseCaseError;\n}\n"],"names":["CreateFileRepository","createAbstraction","CreateFileUseCase"],"mappings":";AA8CO,MAAMA,uBACTC,kBAAyC;AA4BtC,MAAMC,oBAAoBD,kBAAsC"}
|
|
@@ -3,6 +3,7 @@ import { CreateFilesInBatchRepository, CreateFilesInBatchUseCase } from "./abstr
|
|
|
3
3
|
import { GetSettingsUseCase } from "../../settings/GetSettings/abstractions.js";
|
|
4
4
|
import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
5
5
|
import { FileNotAuthorizedError, InvalidFileSizeError } from "../../../domain/file/errors.js";
|
|
6
|
+
import { validateFileKey } from "../../../domain/file/validateFileKey.js";
|
|
6
7
|
import { FileAfterBatchCreateEvent, FileBeforeBatchCreateEvent } from "./events.js";
|
|
7
8
|
import { FmPermissions } from "../../shared/abstractions.js";
|
|
8
9
|
class CreateFilesInBatchUseCaseImpl {
|
|
@@ -46,6 +47,13 @@ class CreateFilesInBatchUseCaseImpl {
|
|
|
46
47
|
return Result.ok(result.value);
|
|
47
48
|
}
|
|
48
49
|
async validateInput(files) {
|
|
50
|
+
for (const input of files){
|
|
51
|
+
const keyResult = validateFileKey({
|
|
52
|
+
key: input.key,
|
|
53
|
+
id: input.id
|
|
54
|
+
});
|
|
55
|
+
if (keyResult.isFail()) return keyResult;
|
|
56
|
+
}
|
|
49
57
|
const settingsResult = await this.getSettings.execute();
|
|
50
58
|
if (settingsResult.isFail()) return Result.ok();
|
|
51
59
|
const settings = settingsResult.value;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/file/CreateFilesInBatch/CreateFilesInBatchUseCase.js","sources":["../../../../src/features/file/CreateFilesInBatch/CreateFilesInBatchUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n CreateFilesInBatchUseCase as UseCaseAbstraction,\n CreateFilesInBatchInput,\n CreateFilesInBatchRepository\n} from \"./abstractions.js\";\nimport { GetSettingsUseCase } from \"../../settings/GetSettings/abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport type { File, FileInput } from \"~/domain/file/types.js\";\nimport { FileNotAuthorizedError, InvalidFileSizeError } from \"~/domain/file/errors.js\";\nimport { FileBeforeBatchCreateEvent, FileAfterBatchCreateEvent } from \"./events.js\";\nimport { FmPermissions } from \"~/features/shared/abstractions.js\";\nimport { CreateFileInput } from \"~/features/file/CreateFile/abstractions.js\";\n\nclass CreateFilesInBatchUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private permissions: FmPermissions.Interface,\n private repository: CreateFilesInBatchRepository.Interface,\n private getSettings: GetSettingsUseCase.Interface,\n private eventPublisher: EventPublisher.Interface\n ) {}\n\n public async execute(\n input: CreateFilesInBatchInput\n ): Promise<Result<File[], UseCaseAbstraction.Error>> {\n const hasPermission = await this.permissions.canCreate(\"file\");\n if (!hasPermission) {\n return Result.fail(new FileNotAuthorizedError());\n }\n\n // Validate all files\n const validationResult = await this.validateInput(input.files);\n if (validationResult.isFail()) {\n return Result.fail(validationResult.error);\n }\n\n // Prepare file inputs with defaults\n const fileInputs: FileInput[] = input.files.map(file => {\n const [id] = file.key.split(\"/\");\n return {\n id: file.id || id,\n key: file.key,\n name: file.name,\n size: file.size,\n type: file.type,\n metadata: file.metadata || {},\n location: file.location || { folderId: \"root\" },\n tags: file.tags || [],\n extensions: input.meta || {}\n };\n });\n\n await this.eventPublisher.publish(\n new FileBeforeBatchCreateEvent({ files: fileInputs, meta: input.meta })\n );\n\n const result = await this.repository.createBatch(fileInputs);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n await this.eventPublisher.publish(\n new FileAfterBatchCreateEvent({ files: result.value, meta: input.meta })\n );\n\n return Result.ok(result.value);\n }\n\n private async validateInput(\n files: CreateFileInput[]\n ): Promise<Result<void, InvalidFileSizeError>> {\n const settingsResult = await this.getSettings.execute();\n\n if (settingsResult.isFail()) {\n return Result.ok();\n }\n\n const settings = settingsResult.value;\n\n if (settings) {\n for (const input of files) {\n // Validate file size\n if (\n input.size < settings.uploadMinFileSize ||\n input.size > settings.uploadMaxFileSize\n ) {\n return Result.fail(\n new InvalidFileSizeError({\n size: input.size,\n minSize: settings.uploadMinFileSize,\n maxSize: settings.uploadMaxFileSize\n })\n );\n }\n }\n }\n\n return Result.ok();\n }\n}\n\nexport const CreateFilesInBatchUseCase = UseCaseAbstraction.createImplementation({\n implementation: CreateFilesInBatchUseCaseImpl,\n dependencies: [FmPermissions, CreateFilesInBatchRepository, GetSettingsUseCase, EventPublisher]\n});\n"],"names":["CreateFilesInBatchUseCaseImpl","permissions","repository","getSettings","eventPublisher","input","hasPermission","Result","FileNotAuthorizedError","validationResult","fileInputs","file","id","FileBeforeBatchCreateEvent","result","FileAfterBatchCreateEvent","files","settingsResult","settings","InvalidFileSizeError","CreateFilesInBatchUseCase","UseCaseAbstraction","FmPermissions","CreateFilesInBatchRepository","GetSettingsUseCase","EventPublisher"],"mappings":"
|
|
1
|
+
{"version":3,"file":"features/file/CreateFilesInBatch/CreateFilesInBatchUseCase.js","sources":["../../../../src/features/file/CreateFilesInBatch/CreateFilesInBatchUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n CreateFilesInBatchUseCase as UseCaseAbstraction,\n CreateFilesInBatchInput,\n CreateFilesInBatchRepository\n} from \"./abstractions.js\";\nimport { GetSettingsUseCase } from \"../../settings/GetSettings/abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport type { File, FileInput } from \"~/domain/file/types.js\";\nimport { FileNotAuthorizedError, InvalidFileSizeError } from \"~/domain/file/errors.js\";\nimport type { InvalidFileKeyError } from \"~/domain/file/errors.js\";\nimport { validateFileKey } from \"~/domain/file/validateFileKey.js\";\nimport { FileBeforeBatchCreateEvent, FileAfterBatchCreateEvent } from \"./events.js\";\nimport { FmPermissions } from \"~/features/shared/abstractions.js\";\nimport { CreateFileInput } from \"~/features/file/CreateFile/abstractions.js\";\n\nclass CreateFilesInBatchUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private permissions: FmPermissions.Interface,\n private repository: CreateFilesInBatchRepository.Interface,\n private getSettings: GetSettingsUseCase.Interface,\n private eventPublisher: EventPublisher.Interface\n ) {}\n\n public async execute(\n input: CreateFilesInBatchInput\n ): Promise<Result<File[], UseCaseAbstraction.Error>> {\n const hasPermission = await this.permissions.canCreate(\"file\");\n if (!hasPermission) {\n return Result.fail(new FileNotAuthorizedError());\n }\n\n // Validate all files\n const validationResult = await this.validateInput(input.files);\n if (validationResult.isFail()) {\n return Result.fail(validationResult.error);\n }\n\n // Prepare file inputs with defaults\n const fileInputs: FileInput[] = input.files.map(file => {\n const [id] = file.key.split(\"/\");\n return {\n id: file.id || id,\n key: file.key,\n name: file.name,\n size: file.size,\n type: file.type,\n metadata: file.metadata || {},\n location: file.location || { folderId: \"root\" },\n tags: file.tags || [],\n extensions: input.meta || {}\n };\n });\n\n await this.eventPublisher.publish(\n new FileBeforeBatchCreateEvent({ files: fileInputs, meta: input.meta })\n );\n\n const result = await this.repository.createBatch(fileInputs);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n await this.eventPublisher.publish(\n new FileAfterBatchCreateEvent({ files: result.value, meta: input.meta })\n );\n\n return Result.ok(result.value);\n }\n\n private async validateInput(\n files: CreateFileInput[]\n ): Promise<Result<void, InvalidFileKeyError | InvalidFileSizeError>> {\n for (const input of files) {\n const keyResult = validateFileKey({ key: input.key, id: input.id });\n if (keyResult.isFail()) {\n return keyResult;\n }\n }\n\n const settingsResult = await this.getSettings.execute();\n\n if (settingsResult.isFail()) {\n return Result.ok();\n }\n\n const settings = settingsResult.value;\n\n if (settings) {\n for (const input of files) {\n // Validate file size\n if (\n input.size < settings.uploadMinFileSize ||\n input.size > settings.uploadMaxFileSize\n ) {\n return Result.fail(\n new InvalidFileSizeError({\n size: input.size,\n minSize: settings.uploadMinFileSize,\n maxSize: settings.uploadMaxFileSize\n })\n );\n }\n }\n }\n\n return Result.ok();\n }\n}\n\nexport const CreateFilesInBatchUseCase = UseCaseAbstraction.createImplementation({\n implementation: CreateFilesInBatchUseCaseImpl,\n dependencies: [FmPermissions, CreateFilesInBatchRepository, GetSettingsUseCase, EventPublisher]\n});\n"],"names":["CreateFilesInBatchUseCaseImpl","permissions","repository","getSettings","eventPublisher","input","hasPermission","Result","FileNotAuthorizedError","validationResult","fileInputs","file","id","FileBeforeBatchCreateEvent","result","FileAfterBatchCreateEvent","files","keyResult","validateFileKey","settingsResult","settings","InvalidFileSizeError","CreateFilesInBatchUseCase","UseCaseAbstraction","FmPermissions","CreateFilesInBatchRepository","GetSettingsUseCase","EventPublisher"],"mappings":";;;;;;;;AAgBA,MAAMA;IACF,YACYC,WAAoC,EACpCC,UAAkD,EAClDC,WAAyC,EACzCC,cAAwC,CAClD;aAJUH,WAAW,GAAXA;aACAC,UAAU,GAAVA;aACAC,WAAW,GAAXA;aACAC,cAAc,GAAdA;IACT;IAEH,MAAa,QACTC,KAA8B,EACmB;QACjD,MAAMC,gBAAgB,MAAM,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC;QACvD,IAAI,CAACA,eACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAI3B,MAAMC,mBAAmB,MAAM,IAAI,CAAC,aAAa,CAACJ,MAAM,KAAK;QAC7D,IAAII,iBAAiB,MAAM,IACvB,OAAOF,OAAO,IAAI,CAACE,iBAAiB,KAAK;QAI7C,MAAMC,aAA0BL,MAAM,KAAK,CAAC,GAAG,CAACM,CAAAA;YAC5C,MAAM,CAACC,GAAG,GAAGD,KAAK,GAAG,CAAC,KAAK,CAAC;YAC5B,OAAO;gBACH,IAAIA,KAAK,EAAE,IAAIC;gBACf,KAAKD,KAAK,GAAG;gBACb,MAAMA,KAAK,IAAI;gBACf,MAAMA,KAAK,IAAI;gBACf,MAAMA,KAAK,IAAI;gBACf,UAAUA,KAAK,QAAQ,IAAI,CAAC;gBAC5B,UAAUA,KAAK,QAAQ,IAAI;oBAAE,UAAU;gBAAO;gBAC9C,MAAMA,KAAK,IAAI,IAAI,EAAE;gBACrB,YAAYN,MAAM,IAAI,IAAI,CAAC;YAC/B;QACJ;QAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIQ,2BAA2B;YAAE,OAAOH;YAAY,MAAML,MAAM,IAAI;QAAC;QAGzE,MAAMS,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAACJ;QAEjD,IAAII,OAAO,MAAM,IACb,OAAOP,OAAO,IAAI,CAACO,OAAO,KAAK;QAGnC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,0BAA0B;YAAE,OAAOD,OAAO,KAAK;YAAE,MAAMT,MAAM,IAAI;QAAC;QAG1E,OAAOE,OAAO,EAAE,CAACO,OAAO,KAAK;IACjC;IAEA,MAAc,cACVE,KAAwB,EACyC;QACjE,KAAK,MAAMX,SAASW,MAAO;YACvB,MAAMC,YAAYC,gBAAgB;gBAAE,KAAKb,MAAM,GAAG;gBAAE,IAAIA,MAAM,EAAE;YAAC;YACjE,IAAIY,UAAU,MAAM,IAChB,OAAOA;QAEf;QAEA,MAAME,iBAAiB,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO;QAErD,IAAIA,eAAe,MAAM,IACrB,OAAOZ,OAAO,EAAE;QAGpB,MAAMa,WAAWD,eAAe,KAAK;QAErC,IAAIC,UACA;YAAA,KAAK,MAAMf,SAASW,MAEhB,IACIX,MAAM,IAAI,GAAGe,SAAS,iBAAiB,IACvCf,MAAM,IAAI,GAAGe,SAAS,iBAAiB,EAEvC,OAAOb,OAAO,IAAI,CACd,IAAIc,qBAAqB;gBACrB,MAAMhB,MAAM,IAAI;gBAChB,SAASe,SAAS,iBAAiB;gBACnC,SAASA,SAAS,iBAAiB;YACvC;QAGZ;QAGJ,OAAOb,OAAO,EAAE;IACpB;AACJ;AAEO,MAAMe,sDAA4BC,0BAAAA,oBAAuC,CAAC;IAC7E,gBAAgBvB;IAChB,cAAc;QAACwB;QAAeC;QAA8BC;QAAoBC;KAAe;AACnG"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { InvalidFileKeyError } from "../../../domain/file/errors.js";
|
|
1
2
|
import type { Result } from "@webiny/feature/api";
|
|
2
3
|
import type { File, FileInput } from "../../../domain/file/types.js";
|
|
3
4
|
import { type FilePersistenceError, type InvalidFileSizeError, FileNotAuthorizedError } from "../../../domain/file/errors.js";
|
|
@@ -31,6 +32,7 @@ export interface ICreateFilesInBatchUseCaseErrors {
|
|
|
31
32
|
notAuthorized: FileNotAuthorizedError;
|
|
32
33
|
persistence: FilePersistenceError;
|
|
33
34
|
invalidSize: InvalidFileSizeError;
|
|
35
|
+
invalidKey: InvalidFileKeyError;
|
|
34
36
|
}
|
|
35
37
|
type UseCaseError = ICreateFilesInBatchUseCaseErrors[keyof ICreateFilesInBatchUseCaseErrors];
|
|
36
38
|
/** Upload and create multiple files in batch. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/file/CreateFilesInBatch/abstractions.js","sources":["../../../../src/features/file/CreateFilesInBatch/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport type { File, FileInput } from \"~/domain/file/types.js\";\nimport {\n type FilePersistenceError,\n type InvalidFileSizeError,\n FileNotAuthorizedError\n} from \"~/domain/file/errors.js\";\n\nexport interface CreateFilesInBatchInput {\n files: FileInput[];\n meta?: Record<string, any>;\n}\n\n/**\n * CreateFilesInBatch repository interface\n */\nexport interface ICreateFilesInBatchRepository {\n createBatch(files: FileInput[]): Promise<Result<File[], RepositoryError>>;\n}\n\nexport interface ICreateFilesInBatchRepositoryErrors {\n persistence: FilePersistenceError;\n}\n\ntype RepositoryError =\n ICreateFilesInBatchRepositoryErrors[keyof ICreateFilesInBatchRepositoryErrors];\n\n/** Persist multiple files created in batch. */\nexport const CreateFilesInBatchRepository = createAbstraction<ICreateFilesInBatchRepository>(\n \"CreateFilesInBatchRepository\"\n);\n\nexport namespace CreateFilesInBatchRepository {\n export type Interface = ICreateFilesInBatchRepository;\n export type Error = RepositoryError;\n}\n\n/**\n * CreateFilesInBatch use case interface\n */\nexport interface ICreateFilesInBatchUseCase {\n execute(input: CreateFilesInBatchInput): Promise<Result<File[], UseCaseError>>;\n}\n\nexport interface ICreateFilesInBatchUseCaseErrors {\n notAuthorized: FileNotAuthorizedError;\n persistence: FilePersistenceError;\n invalidSize: InvalidFileSizeError;\n}\n\ntype UseCaseError = ICreateFilesInBatchUseCaseErrors[keyof ICreateFilesInBatchUseCaseErrors];\n\n/** Upload and create multiple files in batch. */\nexport const CreateFilesInBatchUseCase = createAbstraction<ICreateFilesInBatchUseCase>(\n \"CreateFilesInBatchUseCase\"\n);\n\nexport namespace CreateFilesInBatchUseCase {\n export type Interface = ICreateFilesInBatchUseCase;\n export type Error = UseCaseError;\n}\n"],"names":["CreateFilesInBatchRepository","createAbstraction","CreateFilesInBatchUseCase"],"mappings":";
|
|
1
|
+
{"version":3,"file":"features/file/CreateFilesInBatch/abstractions.js","sources":["../../../../src/features/file/CreateFilesInBatch/abstractions.ts"],"sourcesContent":["import type { InvalidFileKeyError } from \"~/domain/file/errors.js\";\nimport { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport type { File, FileInput } from \"~/domain/file/types.js\";\nimport {\n type FilePersistenceError,\n type InvalidFileSizeError,\n FileNotAuthorizedError\n} from \"~/domain/file/errors.js\";\n\nexport interface CreateFilesInBatchInput {\n files: FileInput[];\n meta?: Record<string, any>;\n}\n\n/**\n * CreateFilesInBatch repository interface\n */\nexport interface ICreateFilesInBatchRepository {\n createBatch(files: FileInput[]): Promise<Result<File[], RepositoryError>>;\n}\n\nexport interface ICreateFilesInBatchRepositoryErrors {\n persistence: FilePersistenceError;\n}\n\ntype RepositoryError =\n ICreateFilesInBatchRepositoryErrors[keyof ICreateFilesInBatchRepositoryErrors];\n\n/** Persist multiple files created in batch. */\nexport const CreateFilesInBatchRepository = createAbstraction<ICreateFilesInBatchRepository>(\n \"CreateFilesInBatchRepository\"\n);\n\nexport namespace CreateFilesInBatchRepository {\n export type Interface = ICreateFilesInBatchRepository;\n export type Error = RepositoryError;\n}\n\n/**\n * CreateFilesInBatch use case interface\n */\nexport interface ICreateFilesInBatchUseCase {\n execute(input: CreateFilesInBatchInput): Promise<Result<File[], UseCaseError>>;\n}\n\nexport interface ICreateFilesInBatchUseCaseErrors {\n notAuthorized: FileNotAuthorizedError;\n persistence: FilePersistenceError;\n invalidSize: InvalidFileSizeError;\n invalidKey: InvalidFileKeyError;\n}\n\ntype UseCaseError = ICreateFilesInBatchUseCaseErrors[keyof ICreateFilesInBatchUseCaseErrors];\n\n/** Upload and create multiple files in batch. */\nexport const CreateFilesInBatchUseCase = createAbstraction<ICreateFilesInBatchUseCase>(\n \"CreateFilesInBatchUseCase\"\n);\n\nexport namespace CreateFilesInBatchUseCase {\n export type Interface = ICreateFilesInBatchUseCase;\n export type Error = UseCaseError;\n}\n"],"names":["CreateFilesInBatchRepository","createAbstraction","CreateFilesInBatchUseCase"],"mappings":";AA8BO,MAAMA,+BAA+BC,kBACxC;AAyBG,MAAMC,4BAA4BD,kBACrC"}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { FileUrlGenerator as Abstraction } from "./abstractions.js";
|
|
2
|
-
import {
|
|
2
|
+
import { FileUrlPrefixProvider } from "./abstractions.js";
|
|
3
3
|
import type { File } from "../../../domain/file/types.js";
|
|
4
4
|
declare class FileUrlGeneratorImpl implements Abstraction.Interface {
|
|
5
|
-
private readonly
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
generateUrl(file: File): string;
|
|
9
|
-
init(): Promise<void>;
|
|
5
|
+
private readonly prefixProvider;
|
|
6
|
+
constructor(prefixProvider: FileUrlPrefixProvider.Interface);
|
|
7
|
+
generateUrl(file: File): Promise<string>;
|
|
10
8
|
}
|
|
11
9
|
export declare const FileUrlGenerator: typeof FileUrlGeneratorImpl & {
|
|
12
10
|
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IFileUrlGenerator>;
|
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
import { FileUrlGenerator } from "./abstractions.js";
|
|
2
|
-
import { GetSettingsUseCase } from "../../settings/GetSettings/abstractions.js";
|
|
1
|
+
import { FileUrlGenerator, FileUrlPrefixProvider } from "./abstractions.js";
|
|
3
2
|
class FileUrlGeneratorImpl {
|
|
4
|
-
constructor(
|
|
5
|
-
this.
|
|
6
|
-
this.srcPrefix = "";
|
|
3
|
+
constructor(prefixProvider){
|
|
4
|
+
this.prefixProvider = prefixProvider;
|
|
7
5
|
}
|
|
8
|
-
generateUrl(file) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
async init() {
|
|
12
|
-
const result = await this.getSettings.execute();
|
|
13
|
-
const settings = result.value;
|
|
14
|
-
this.srcPrefix = settings?.srcPrefix ?? "";
|
|
6
|
+
async generateUrl(file) {
|
|
7
|
+
const prefix = await this.prefixProvider.getPrefix();
|
|
8
|
+
return prefix + file.key;
|
|
15
9
|
}
|
|
16
10
|
}
|
|
17
11
|
const FileUrlGenerator_FileUrlGenerator = FileUrlGenerator.createImplementation({
|
|
18
12
|
implementation: FileUrlGeneratorImpl,
|
|
19
13
|
dependencies: [
|
|
20
|
-
|
|
14
|
+
FileUrlPrefixProvider
|
|
21
15
|
]
|
|
22
16
|
});
|
|
23
17
|
export { FileUrlGenerator_FileUrlGenerator as FileUrlGenerator };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/file/FileUrlGenerator/FileUrlGenerator.js","sources":["../../../../src/features/file/FileUrlGenerator/FileUrlGenerator.ts"],"sourcesContent":["import { FileUrlGenerator as Abstraction } from \"./abstractions.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"features/file/FileUrlGenerator/FileUrlGenerator.js","sources":["../../../../src/features/file/FileUrlGenerator/FileUrlGenerator.ts"],"sourcesContent":["import { FileUrlGenerator as Abstraction } from \"./abstractions.js\";\nimport { FileUrlPrefixProvider } from \"./abstractions.js\";\nimport type { File } from \"~/domain/file/types.js\";\n\nclass FileUrlGeneratorImpl implements Abstraction.Interface {\n public constructor(private readonly prefixProvider: FileUrlPrefixProvider.Interface) {}\n\n public async generateUrl(file: File): Promise<string> {\n const prefix = await this.prefixProvider.getPrefix();\n return prefix + file.key;\n }\n}\n\nexport const FileUrlGenerator = Abstraction.createImplementation({\n implementation: FileUrlGeneratorImpl,\n dependencies: [FileUrlPrefixProvider]\n});\n"],"names":["FileUrlGeneratorImpl","prefixProvider","file","prefix","FileUrlGenerator","Abstraction","FileUrlPrefixProvider"],"mappings":";AAIA,MAAMA;IACF,YAAoCC,cAA+C,CAAE;aAAjDA,cAAc,GAAdA;IAAkD;IAEtF,MAAa,YAAYC,IAAU,EAAmB;QAClD,MAAMC,SAAS,MAAM,IAAI,CAAC,cAAc,CAAC,SAAS;QAClD,OAAOA,SAASD,KAAK,GAAG;IAC5B;AACJ;AAEO,MAAME,oCAAmBC,iBAAAA,oBAAgC,CAAC;IAC7D,gBAAgBL;IAChB,cAAc;QAACM;KAAsB;AACzC"}
|