@webiny/api-file-manager-server 0.0.0-unstable.0d717d18dd
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/FileManagerServerFeature.d.ts +5 -0
- package/FileManagerServerFeature.js +41 -0
- package/FileManagerServerFeature.js.map +1 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/assetDelivery/LocalAssetResolver.d.ts +15 -0
- package/assetDelivery/LocalAssetResolver.js +40 -0
- package/assetDelivery/LocalAssetResolver.js.map +1 -0
- package/assetDelivery/LocalContentsReader.d.ts +7 -0
- package/assetDelivery/LocalContentsReader.js +18 -0
- package/assetDelivery/LocalContentsReader.js.map +1 -0
- package/assetDelivery/LocalOutputStrategy.d.ts +12 -0
- package/assetDelivery/LocalOutputStrategy.js +21 -0
- package/assetDelivery/LocalOutputStrategy.js.map +1 -0
- package/assetDelivery/LocalSharpTransform.d.ts +24 -0
- package/assetDelivery/LocalSharpTransform.js +161 -0
- package/assetDelivery/LocalSharpTransform.js.map +1 -0
- package/assetDelivery/abstractions.d.ts +8 -0
- package/assetDelivery/abstractions.js +6 -0
- package/assetDelivery/abstractions.js.map +1 -0
- package/assetDelivery/assetDeliveryConfig.d.ts +2 -0
- package/assetDelivery/assetDeliveryConfig.js +15 -0
- package/assetDelivery/assetDeliveryConfig.js.map +1 -0
- package/assetDelivery/createAssetDelivery.d.ts +3 -0
- package/assetDelivery/createAssetDelivery.js +7 -0
- package/assetDelivery/createAssetDelivery.js.map +1 -0
- package/assetDelivery/feature.d.ts +5 -0
- package/assetDelivery/feature.js +38 -0
- package/assetDelivery/feature.js.map +1 -0
- package/assetDelivery/types.d.ts +8 -0
- package/assetDelivery/types.js +0 -0
- package/features/CleanupStaleMultipartUploads/CleanupStaleMultipartUploadsTask.d.ts +21 -0
- package/features/CleanupStaleMultipartUploads/CleanupStaleMultipartUploadsTask.js +62 -0
- package/features/CleanupStaleMultipartUploads/CleanupStaleMultipartUploadsTask.js.map +1 -0
- package/features/CleanupStaleMultipartUploads/feature.d.ts +4 -0
- package/features/CleanupStaleMultipartUploads/feature.js +11 -0
- package/features/CleanupStaleMultipartUploads/feature.js.map +1 -0
- package/features/CompleteMultiPartUpload/CompleteMultiPartUploadUseCase.d.ts +13 -0
- package/features/CompleteMultiPartUpload/CompleteMultiPartUploadUseCase.js +62 -0
- package/features/CompleteMultiPartUpload/CompleteMultiPartUploadUseCase.js.map +1 -0
- package/features/CompleteMultiPartUpload/feature.d.ts +4 -0
- package/features/CompleteMultiPartUpload/feature.js +11 -0
- package/features/CompleteMultiPartUpload/feature.js.map +1 -0
- package/features/CreateMultiPartUpload/CreateMultiPartUploadUseCase.d.ts +14 -0
- package/features/CreateMultiPartUpload/CreateMultiPartUploadUseCase.js +58 -0
- package/features/CreateMultiPartUpload/CreateMultiPartUploadUseCase.js.map +1 -0
- package/features/CreateMultiPartUpload/feature.d.ts +4 -0
- package/features/CreateMultiPartUpload/feature.js +11 -0
- package/features/CreateMultiPartUpload/feature.js.map +1 -0
- package/features/DeleteFileFromDisk/DeleteFileFromDiskHandler.d.ts +15 -0
- package/features/DeleteFileFromDisk/DeleteFileFromDiskHandler.js +34 -0
- package/features/DeleteFileFromDisk/DeleteFileFromDiskHandler.js.map +1 -0
- package/features/DeleteFileFromDisk/feature.d.ts +4 -0
- package/features/DeleteFileFromDisk/feature.js +11 -0
- package/features/DeleteFileFromDisk/feature.js.map +1 -0
- package/features/ExtractMetadata/ExtractMetadataHandler.d.ts +1 -0
- package/features/ExtractMetadata/ExtractMetadataHandler.js +1 -0
- package/features/ExtractMetadata/ExtractMetadataTask.d.ts +24 -0
- package/features/ExtractMetadata/ExtractMetadataTask.js +84 -0
- package/features/ExtractMetadata/ExtractMetadataTask.js.map +1 -0
- package/features/ExtractMetadata/feature.d.ts +4 -0
- package/features/ExtractMetadata/feature.js +13 -0
- package/features/ExtractMetadata/feature.js.map +1 -0
- package/features/FileManagerServerConfig/FileManagerServerConfig.d.ts +12 -0
- package/features/FileManagerServerConfig/FileManagerServerConfig.js +28 -0
- package/features/FileManagerServerConfig/FileManagerServerConfig.js.map +1 -0
- package/features/FileManagerServerConfig/abstractions.d.ts +10 -0
- package/features/FileManagerServerConfig/abstractions.js +5 -0
- package/features/FileManagerServerConfig/abstractions.js.map +1 -0
- package/features/FileManagerServerConfig/feature.d.ts +4 -0
- package/features/FileManagerServerConfig/feature.js +11 -0
- package/features/FileManagerServerConfig/feature.js.map +1 -0
- package/features/FlushCache/FlushCacheOnFileBeforeUpdateHandler.d.ts +8 -0
- package/features/FlushCache/FlushCacheOnFileBeforeUpdateHandler.js +11 -0
- package/features/FlushCache/FlushCacheOnFileBeforeUpdateHandler.js.map +1 -0
- package/features/FlushCache/FlushCacheOnFileDeleteHandler.d.ts +8 -0
- package/features/FlushCache/FlushCacheOnFileDeleteHandler.js +11 -0
- package/features/FlushCache/FlushCacheOnFileDeleteHandler.js.map +1 -0
- package/features/FlushCache/feature.d.ts +4 -0
- package/features/FlushCache/feature.js +13 -0
- package/features/FlushCache/feature.js.map +1 -0
- package/features/GetFileContentsById/GetFileContentsByIdUseCase.d.ts +15 -0
- package/features/GetFileContentsById/GetFileContentsByIdUseCase.js +38 -0
- package/features/GetFileContentsById/GetFileContentsByIdUseCase.js.map +1 -0
- package/features/GetFileContentsById/feature.d.ts +4 -0
- package/features/GetFileContentsById/feature.js +11 -0
- package/features/GetFileContentsById/feature.js.map +1 -0
- package/features/GetFileContentsByKey/GetFileContentsByKeyUseCase.d.ts +15 -0
- package/features/GetFileContentsByKey/GetFileContentsByKeyUseCase.js +72 -0
- package/features/GetFileContentsByKey/GetFileContentsByKeyUseCase.js.map +1 -0
- package/features/GetFileContentsByKey/feature.d.ts +4 -0
- package/features/GetFileContentsByKey/feature.js +11 -0
- package/features/GetFileContentsByKey/feature.js.map +1 -0
- package/features/GetUploadPayload/GetUploadPayloadUseCase.d.ts +16 -0
- package/features/GetUploadPayload/GetUploadPayloadUseCase.js +57 -0
- package/features/GetUploadPayload/GetUploadPayloadUseCase.js.map +1 -0
- package/features/GetUploadPayload/feature.d.ts +4 -0
- package/features/GetUploadPayload/feature.js +11 -0
- package/features/GetUploadPayload/feature.js.map +1 -0
- package/graphql/ServerGraphQLSchema.d.ts +15 -0
- package/graphql/ServerGraphQLSchema.js +221 -0
- package/graphql/ServerGraphQLSchema.js.map +1 -0
- package/index.d.ts +3 -0
- package/index.js +3 -0
- package/package.json +44 -0
- package/routes/UploadPartRoute/UploadPartRoute.d.ts +14 -0
- package/routes/UploadPartRoute/UploadPartRoute.js +66 -0
- package/routes/UploadPartRoute/UploadPartRoute.js.map +1 -0
- package/routes/UploadPartRoute/feature.d.ts +4 -0
- package/routes/UploadPartRoute/feature.js +11 -0
- package/routes/UploadPartRoute/feature.js.map +1 -0
- package/routes/UploadSingleFileRoute/UploadSingleFileRoute.d.ts +14 -0
- package/routes/UploadSingleFileRoute/UploadSingleFileRoute.js +70 -0
- package/routes/UploadSingleFileRoute/UploadSingleFileRoute.js.map +1 -0
- package/routes/UploadSingleFileRoute/feature.d.ts +4 -0
- package/routes/UploadSingleFileRoute/feature.js +11 -0
- package/routes/UploadSingleFileRoute/feature.js.map +1 -0
- package/routes/utils.d.ts +20 -0
- package/routes/utils.js +62 -0
- package/routes/utils.js.map +1 -0
- package/types.d.ts +10 -0
- package/types.js +1 -0
- package/utils/uploadToken.d.ts +3 -0
- package/utils/uploadToken.js +22 -0
- package/utils/uploadToken.js.map +1 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { existsSync, mkdirSync } from "node:fs";
|
|
2
|
+
import { BuildParams } from "@webiny/api-core/features/buildParams/index.js";
|
|
3
|
+
import { FileManagerServerConfig } from "./abstractions.js";
|
|
4
|
+
class FileManagerServerConfigImpl {
|
|
5
|
+
constructor(buildParams){
|
|
6
|
+
const storagePath = buildParams.get("WEBINY_LOCAL_STORAGE_PATH");
|
|
7
|
+
if (!storagePath) throw new Error('"WEBINY_LOCAL_STORAGE_PATH" build parameter is not defined. Please set it to a valid local path.');
|
|
8
|
+
const uploadSecret = buildParams.get("WEBINY_UPLOAD_SECRET");
|
|
9
|
+
if (!uploadSecret) throw new Error('"WEBINY_UPLOAD_SECRET" build parameter is not defined. Please set it to a secret string used to sign upload tokens.');
|
|
10
|
+
const apiUrl = buildParams.get("WEBINY_API_URL");
|
|
11
|
+
if (!apiUrl) throw new Error('"WEBINY_API_URL" build parameter is not defined. Configure it via <Infra.ApiUrl url="..." /> in webiny.config.');
|
|
12
|
+
this.storagePath = storagePath;
|
|
13
|
+
this.uploadSecret = uploadSecret;
|
|
14
|
+
this.apiUrl = apiUrl.replace(/\/+$/, "");
|
|
15
|
+
if (!existsSync(this.storagePath)) mkdirSync(this.storagePath, {
|
|
16
|
+
recursive: true
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const FileManagerServerConfig_FileManagerServerConfig = FileManagerServerConfig.createImplementation({
|
|
21
|
+
implementation: FileManagerServerConfigImpl,
|
|
22
|
+
dependencies: [
|
|
23
|
+
BuildParams
|
|
24
|
+
]
|
|
25
|
+
});
|
|
26
|
+
export { FileManagerServerConfig_FileManagerServerConfig as FileManagerServerConfig };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=FileManagerServerConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/FileManagerServerConfig/FileManagerServerConfig.js","sources":["../../../src/features/FileManagerServerConfig/FileManagerServerConfig.ts"],"sourcesContent":["import { existsSync, mkdirSync } from \"node:fs\";\nimport { BuildParams } from \"@webiny/api-core/features/buildParams/index.js\";\nimport { FileManagerServerConfig as FileManagerServerConfigAbstraction } from \"./abstractions.js\";\n\nclass FileManagerServerConfigImpl implements FileManagerServerConfigAbstraction.Interface {\n public readonly storagePath: string;\n public readonly uploadSecret: string;\n public readonly apiUrl: string;\n\n constructor(buildParams: BuildParams.Interface) {\n const storagePath = buildParams.get<string>(\"WEBINY_LOCAL_STORAGE_PATH\");\n if (!storagePath) {\n throw new Error(\n `\"WEBINY_LOCAL_STORAGE_PATH\" build parameter is not defined. Please set it to a valid local path.`\n );\n }\n\n const uploadSecret = buildParams.get<string>(\"WEBINY_UPLOAD_SECRET\");\n if (!uploadSecret) {\n throw new Error(\n `\"WEBINY_UPLOAD_SECRET\" build parameter is not defined. Please set it to a secret string used to sign upload tokens.`\n );\n }\n\n // The API's own public origin, used to build client-reachable URLs (upload endpoint + file\n // srcPrefix). A build param (baked by Infra.ApiUrl), NOT a process.env read in api runtime code.\n const apiUrl = buildParams.get<string>(\"WEBINY_API_URL\");\n if (!apiUrl) {\n throw new Error(\n `\"WEBINY_API_URL\" build parameter is not defined. Configure it via <Infra.ApiUrl url=\"...\" /> in webiny.config.`\n );\n }\n\n this.storagePath = storagePath;\n this.uploadSecret = uploadSecret;\n this.apiUrl = apiUrl.replace(/\\/+$/, \"\");\n\n // Ensure the storage directory exists. Done here (on first resolve, at request time) rather\n // than in FileManagerServerFeature.register(): build params like WEBINY_LOCAL_STORAGE_PATH are\n // only registered once project extensions are applied, which happens LATER in the request\n // stack than the file-manager transport hook — so resolving this config at register() time\n // would read the param before it exists and throw.\n if (!existsSync(this.storagePath)) {\n mkdirSync(this.storagePath, { recursive: true });\n }\n }\n}\n\nexport const FileManagerServerConfig = FileManagerServerConfigAbstraction.createImplementation({\n implementation: FileManagerServerConfigImpl,\n dependencies: [BuildParams]\n});\n"],"names":["FileManagerServerConfigImpl","buildParams","storagePath","Error","uploadSecret","apiUrl","existsSync","mkdirSync","FileManagerServerConfig","FileManagerServerConfigAbstraction","BuildParams"],"mappings":";;;AAIA,MAAMA;IAKF,YAAYC,WAAkC,CAAE;QAC5C,MAAMC,cAAcD,YAAY,GAAG,CAAS;QAC5C,IAAI,CAACC,aACD,MAAM,IAAIC,MACN;QAIR,MAAMC,eAAeH,YAAY,GAAG,CAAS;QAC7C,IAAI,CAACG,cACD,MAAM,IAAID,MACN;QAMR,MAAME,SAASJ,YAAY,GAAG,CAAS;QACvC,IAAI,CAACI,QACD,MAAM,IAAIF,MACN;QAIR,IAAI,CAAC,WAAW,GAAGD;QACnB,IAAI,CAAC,YAAY,GAAGE;QACpB,IAAI,CAAC,MAAM,GAAGC,OAAO,OAAO,CAAC,QAAQ;QAOrC,IAAI,CAACC,WAAW,IAAI,CAAC,WAAW,GAC5BC,UAAU,IAAI,CAAC,WAAW,EAAE;YAAE,WAAW;QAAK;IAEtD;AACJ;AAEO,MAAMC,kDAA0BC,wBAAAA,oBAAuD,CAAC;IAC3F,gBAAgBT;IAChB,cAAc;QAACU;KAAY;AAC/B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface IFileManagerServerConfig {
|
|
2
|
+
readonly storagePath: string;
|
|
3
|
+
readonly uploadSecret: string;
|
|
4
|
+
/** The API's public origin (no trailing slash), e.g. https://api.example.com. */
|
|
5
|
+
readonly apiUrl: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const FileManagerServerConfig: import("@webiny/di").Abstraction<IFileManagerServerConfig>;
|
|
8
|
+
export declare namespace FileManagerServerConfig {
|
|
9
|
+
type Interface = IFileManagerServerConfig;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/FileManagerServerConfig/abstractions.js","sources":["../../../src/features/FileManagerServerConfig/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\nexport interface IFileManagerServerConfig {\n readonly storagePath: string;\n readonly uploadSecret: string;\n /** The API's public origin (no trailing slash), e.g. https://api.example.com. */\n readonly apiUrl: string;\n}\n\nexport const FileManagerServerConfig = createAbstraction<IFileManagerServerConfig>(\n \"FileManagerServer/Config\"\n);\n\nexport namespace FileManagerServerConfig {\n export type Interface = IFileManagerServerConfig;\n}\n"],"names":["FileManagerServerConfig","createAbstraction"],"mappings":";AASO,MAAMA,0BAA0BC,kBACnC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { FileManagerServerConfig } from "./FileManagerServerConfig.js";
|
|
3
|
+
const FileManagerServerConfigFeature = createFeature({
|
|
4
|
+
name: "FileManagerServer/Config",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(FileManagerServerConfig);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { FileManagerServerConfigFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/FileManagerServerConfig/feature.js","sources":["../../../src/features/FileManagerServerConfig/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { FileManagerServerConfig } from \"./FileManagerServerConfig.js\";\n\nexport const FileManagerServerConfigFeature = createFeature({\n name: \"FileManagerServer/Config\",\n register(container) {\n container.register(FileManagerServerConfig);\n }\n});\n"],"names":["FileManagerServerConfigFeature","createFeature","container","FileManagerServerConfig"],"mappings":";;AAGO,MAAMA,iCAAiCC,cAAc;IACxD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FileBeforeUpdateEventHandler } from "@webiny/api-file-manager/features/file/UpdateFile/events.js";
|
|
2
|
+
declare class FlushCacheOnFileBeforeUpdateHandlerImpl implements FileBeforeUpdateEventHandler.Interface {
|
|
3
|
+
handle(_event: FileBeforeUpdateEventHandler.Event): Promise<void>;
|
|
4
|
+
}
|
|
5
|
+
export declare const FlushCacheOnFileBeforeUpdateHandler: typeof FlushCacheOnFileBeforeUpdateHandlerImpl & {
|
|
6
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher").IEventHandler<import("@webiny/api-file-manager/features/file/UpdateFile/events.js").FileBeforeUpdateEvent>>;
|
|
7
|
+
};
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FileBeforeUpdateEventHandler } from "@webiny/api-file-manager/features/file/UpdateFile/events.js";
|
|
2
|
+
class FlushCacheOnFileBeforeUpdateHandlerImpl {
|
|
3
|
+
async handle(_event) {}
|
|
4
|
+
}
|
|
5
|
+
const FlushCacheOnFileBeforeUpdateHandler = FileBeforeUpdateEventHandler.createImplementation({
|
|
6
|
+
implementation: FlushCacheOnFileBeforeUpdateHandlerImpl,
|
|
7
|
+
dependencies: []
|
|
8
|
+
});
|
|
9
|
+
export { FlushCacheOnFileBeforeUpdateHandler };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=FlushCacheOnFileBeforeUpdateHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/FlushCache/FlushCacheOnFileBeforeUpdateHandler.js","sources":["../../../src/features/FlushCache/FlushCacheOnFileBeforeUpdateHandler.ts"],"sourcesContent":["import { FileBeforeUpdateEventHandler } from \"@webiny/api-file-manager/features/file/UpdateFile/events.js\";\n\nclass FlushCacheOnFileBeforeUpdateHandlerImpl implements FileBeforeUpdateEventHandler.Interface {\n /* No-op: local disk does not use a CDN cache. */\n async handle(_event: FileBeforeUpdateEventHandler.Event): Promise<void> {\n /* Nothing to do. */\n }\n}\n\nexport const FlushCacheOnFileBeforeUpdateHandler =\n FileBeforeUpdateEventHandler.createImplementation({\n implementation: FlushCacheOnFileBeforeUpdateHandlerImpl,\n dependencies: []\n });\n"],"names":["FlushCacheOnFileBeforeUpdateHandlerImpl","_event","FlushCacheOnFileBeforeUpdateHandler","FileBeforeUpdateEventHandler"],"mappings":";AAEA,MAAMA;IAEF,MAAM,OAAOC,MAA0C,EAAiB,CAExE;AACJ;AAEO,MAAMC,sCACTC,6BAA6B,oBAAoB,CAAC;IAC9C,gBAAgBH;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FileAfterDeleteEventHandler } from "@webiny/api-file-manager/features/file/DeleteFile/events.js";
|
|
2
|
+
declare class FlushCacheOnFileDeleteHandlerImpl implements FileAfterDeleteEventHandler.Interface {
|
|
3
|
+
handle(_event: FileAfterDeleteEventHandler.Event): Promise<void>;
|
|
4
|
+
}
|
|
5
|
+
export declare const FlushCacheOnFileDeleteHandler: typeof FlushCacheOnFileDeleteHandlerImpl & {
|
|
6
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/eventPublisher").IEventHandler<import("@webiny/api-file-manager/features/file/DeleteFile/events.js").FileAfterDeleteEvent>>;
|
|
7
|
+
};
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FileAfterDeleteEventHandler } from "@webiny/api-file-manager/features/file/DeleteFile/events.js";
|
|
2
|
+
class FlushCacheOnFileDeleteHandlerImpl {
|
|
3
|
+
async handle(_event) {}
|
|
4
|
+
}
|
|
5
|
+
const FlushCacheOnFileDeleteHandler = FileAfterDeleteEventHandler.createImplementation({
|
|
6
|
+
implementation: FlushCacheOnFileDeleteHandlerImpl,
|
|
7
|
+
dependencies: []
|
|
8
|
+
});
|
|
9
|
+
export { FlushCacheOnFileDeleteHandler };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=FlushCacheOnFileDeleteHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/FlushCache/FlushCacheOnFileDeleteHandler.js","sources":["../../../src/features/FlushCache/FlushCacheOnFileDeleteHandler.ts"],"sourcesContent":["import { FileAfterDeleteEventHandler } from \"@webiny/api-file-manager/features/file/DeleteFile/events.js\";\n\nclass FlushCacheOnFileDeleteHandlerImpl implements FileAfterDeleteEventHandler.Interface {\n /* No-op: local disk does not use a CDN cache. */\n async handle(_event: FileAfterDeleteEventHandler.Event): Promise<void> {\n /* Nothing to do. */\n }\n}\n\nexport const FlushCacheOnFileDeleteHandler = FileAfterDeleteEventHandler.createImplementation({\n implementation: FlushCacheOnFileDeleteHandlerImpl,\n dependencies: []\n});\n"],"names":["FlushCacheOnFileDeleteHandlerImpl","_event","FlushCacheOnFileDeleteHandler","FileAfterDeleteEventHandler"],"mappings":";AAEA,MAAMA;IAEF,MAAM,OAAOC,MAAyC,EAAiB,CAEvE;AACJ;AAEO,MAAMC,gCAAgCC,4BAA4B,oBAAoB,CAAC;IAC1F,gBAAgBH;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { FlushCacheOnFileDeleteHandler } from "./FlushCacheOnFileDeleteHandler.js";
|
|
3
|
+
import { FlushCacheOnFileBeforeUpdateHandler } from "./FlushCacheOnFileBeforeUpdateHandler.js";
|
|
4
|
+
const FlushCacheFeature = createFeature({
|
|
5
|
+
name: "FileManagerServer/FlushCache",
|
|
6
|
+
register (container) {
|
|
7
|
+
container.register(FlushCacheOnFileDeleteHandler);
|
|
8
|
+
container.register(FlushCacheOnFileBeforeUpdateHandler);
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
export { FlushCacheFeature };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/FlushCache/feature.js","sources":["../../../src/features/FlushCache/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { FlushCacheOnFileDeleteHandler } from \"./FlushCacheOnFileDeleteHandler.js\";\nimport { FlushCacheOnFileBeforeUpdateHandler } from \"./FlushCacheOnFileBeforeUpdateHandler.js\";\n\nexport const FlushCacheFeature = createFeature({\n name: \"FileManagerServer/FlushCache\",\n register(container) {\n container.register(FlushCacheOnFileDeleteHandler);\n container.register(FlushCacheOnFileBeforeUpdateHandler);\n }\n});\n"],"names":["FlushCacheFeature","createFeature","container","FlushCacheOnFileDeleteHandler","FlushCacheOnFileBeforeUpdateHandler"],"mappings":";;;AAIO,MAAMA,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;IACvB;AACJ"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { GetFileContentsByIdUseCase as GetFileContentsByIdUseCaseAbstraction } from "@webiny/api-file-manager/features/file/GetFileContentsById/index.js";
|
|
3
|
+
import type { FileContents } from "@webiny/api-file-manager/features/file/GetFileContentsById/index.js";
|
|
4
|
+
import { MetadataReader } from "@webiny/api-file-manager/features/upload/ReadFileMetadata/abstractions.js";
|
|
5
|
+
import { FileManagerServerConfig } from "../../features/FileManagerServerConfig/abstractions.js";
|
|
6
|
+
declare class GetFileContentsByIdUseCaseImpl implements GetFileContentsByIdUseCaseAbstraction.Interface {
|
|
7
|
+
private readonly metadataReader;
|
|
8
|
+
private readonly config;
|
|
9
|
+
constructor(metadataReader: MetadataReader.Interface, config: FileManagerServerConfig.Interface);
|
|
10
|
+
execute(fileId: string): Promise<Result<FileContents, GetFileContentsByIdUseCaseAbstraction.Error>>;
|
|
11
|
+
}
|
|
12
|
+
export declare const GetFileContentsByIdUseCase: typeof GetFileContentsByIdUseCaseImpl & {
|
|
13
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-file-manager/features/file/GetFileContentsById/abstractions").IGetFileContentsByIdUseCase>;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { promises } from "node:fs";
|
|
2
|
+
import { Result } from "@webiny/feature/api";
|
|
3
|
+
import { GetFileContentsByIdUseCase } from "@webiny/api-file-manager/features/file/GetFileContentsById/index.js";
|
|
4
|
+
import { FileNotFoundError, FilePersistenceError } from "@webiny/api-file-manager/domain/file/errors.js";
|
|
5
|
+
import { MetadataReader } from "@webiny/api-file-manager/features/upload/ReadFileMetadata/abstractions.js";
|
|
6
|
+
import { FileManagerServerConfig } from "../FileManagerServerConfig/abstractions.js";
|
|
7
|
+
class GetFileContentsByIdUseCaseImpl {
|
|
8
|
+
constructor(metadataReader, config){
|
|
9
|
+
this.metadataReader = metadataReader;
|
|
10
|
+
this.config = config;
|
|
11
|
+
}
|
|
12
|
+
async execute(fileId) {
|
|
13
|
+
const metadata = await this.metadataReader.read(fileId);
|
|
14
|
+
if (!metadata) return Result.fail(new FileNotFoundError(fileId));
|
|
15
|
+
const storagePath = this.config.storagePath;
|
|
16
|
+
try {
|
|
17
|
+
const filePath = `${storagePath}/${metadata.bucketKey}`;
|
|
18
|
+
const buffer = await promises.readFile(filePath);
|
|
19
|
+
return Result.ok({
|
|
20
|
+
buffer,
|
|
21
|
+
contentType: metadata.contentType
|
|
22
|
+
});
|
|
23
|
+
} catch (error) {
|
|
24
|
+
if ("ENOENT" === error.code) return Result.fail(new FileNotFoundError(fileId));
|
|
25
|
+
return Result.fail(new FilePersistenceError(error instanceof Error ? error : new Error(String(error))));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const GetFileContentsByIdUseCase_GetFileContentsByIdUseCase = GetFileContentsByIdUseCase.createImplementation({
|
|
30
|
+
implementation: GetFileContentsByIdUseCaseImpl,
|
|
31
|
+
dependencies: [
|
|
32
|
+
MetadataReader,
|
|
33
|
+
FileManagerServerConfig
|
|
34
|
+
]
|
|
35
|
+
});
|
|
36
|
+
export { GetFileContentsByIdUseCase_GetFileContentsByIdUseCase as GetFileContentsByIdUseCase };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=GetFileContentsByIdUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/GetFileContentsById/GetFileContentsByIdUseCase.js","sources":["../../../src/features/GetFileContentsById/GetFileContentsByIdUseCase.ts"],"sourcesContent":["import { promises as fs } from \"node:fs\";\nimport { Result } from \"@webiny/feature/api\";\nimport { GetFileContentsByIdUseCase as GetFileContentsByIdUseCaseAbstraction } from \"@webiny/api-file-manager/features/file/GetFileContentsById/index.js\";\nimport type { FileContents } from \"@webiny/api-file-manager/features/file/GetFileContentsById/index.js\";\nimport {\n FileNotFoundError,\n FilePersistenceError\n} from \"@webiny/api-file-manager/domain/file/errors.js\";\nimport { MetadataReader } from \"@webiny/api-file-manager/features/upload/ReadFileMetadata/abstractions.js\";\nimport { FileManagerServerConfig } from \"~/features/FileManagerServerConfig/abstractions.js\";\n\nclass GetFileContentsByIdUseCaseImpl implements GetFileContentsByIdUseCaseAbstraction.Interface {\n private readonly metadataReader: MetadataReader.Interface;\n private readonly config: FileManagerServerConfig.Interface;\n\n public constructor(\n metadataReader: MetadataReader.Interface,\n config: FileManagerServerConfig.Interface\n ) {\n this.metadataReader = metadataReader;\n this.config = config;\n }\n\n public async execute(\n fileId: string\n ): Promise<Result<FileContents, GetFileContentsByIdUseCaseAbstraction.Error>> {\n const metadata = await this.metadataReader.read(fileId);\n if (!metadata) {\n return Result.fail(new FileNotFoundError(fileId));\n }\n\n const storagePath = this.config.storagePath;\n\n try {\n const filePath = `${storagePath}/${metadata.bucketKey}`;\n const buffer = await fs.readFile(filePath);\n return Result.ok({ buffer, contentType: metadata.contentType });\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\") {\n return Result.fail(new FileNotFoundError(fileId));\n }\n return Result.fail(\n new FilePersistenceError(error instanceof Error ? error : new Error(String(error)))\n );\n }\n }\n}\n\nexport const GetFileContentsByIdUseCase =\n GetFileContentsByIdUseCaseAbstraction.createImplementation({\n implementation: GetFileContentsByIdUseCaseImpl,\n dependencies: [MetadataReader, FileManagerServerConfig]\n });\n"],"names":["GetFileContentsByIdUseCaseImpl","metadataReader","config","fileId","metadata","Result","FileNotFoundError","storagePath","filePath","buffer","fs","error","FilePersistenceError","Error","String","GetFileContentsByIdUseCase","GetFileContentsByIdUseCaseAbstraction","MetadataReader","FileManagerServerConfig"],"mappings":";;;;;;AAWA,MAAMA;IAIF,YACIC,cAAwC,EACxCC,MAAyC,CAC3C;QACE,IAAI,CAAC,cAAc,GAAGD;QACtB,IAAI,CAAC,MAAM,GAAGC;IAClB;IAEA,MAAa,QACTC,MAAc,EAC4D;QAC1E,MAAMC,WAAW,MAAM,IAAI,CAAC,cAAc,CAAC,IAAI,CAACD;QAChD,IAAI,CAACC,UACD,OAAOC,OAAO,IAAI,CAAC,IAAIC,kBAAkBH;QAG7C,MAAMI,cAAc,IAAI,CAAC,MAAM,CAAC,WAAW;QAE3C,IAAI;YACA,MAAMC,WAAW,GAAGD,YAAY,CAAC,EAAEH,SAAS,SAAS,EAAE;YACvD,MAAMK,SAAS,MAAMC,SAAAA,QAAW,CAACF;YACjC,OAAOH,OAAO,EAAE,CAAC;gBAAEI;gBAAQ,aAAaL,SAAS,WAAW;YAAC;QACjE,EAAE,OAAOO,OAAO;YACZ,IAAKA,AAAyC,aAAzCA,MAAgC,IAAI,EACrC,OAAON,OAAO,IAAI,CAAC,IAAIC,kBAAkBH;YAE7C,OAAOE,OAAO,IAAI,CACd,IAAIO,qBAAqBD,iBAAiBE,QAAQF,QAAQ,IAAIE,MAAMC,OAAOH;QAEnF;IACJ;AACJ;AAEO,MAAMI,wDACTC,2BAAAA,oBAA0D,CAAC;IACvD,gBAAgBhB;IAChB,cAAc;QAACiB;QAAgBC;KAAwB;AAC3D"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { GetFileContentsByIdUseCase } from "./GetFileContentsByIdUseCase.js";
|
|
3
|
+
const GetFileContentsByIdFeature = createFeature({
|
|
4
|
+
name: "FileManagerServer/GetFileContentsById",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(GetFileContentsByIdUseCase);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { GetFileContentsByIdFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/GetFileContentsById/feature.js","sources":["../../../src/features/GetFileContentsById/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { GetFileContentsByIdUseCase } from \"./GetFileContentsByIdUseCase.js\";\n\nexport const GetFileContentsByIdFeature = createFeature({\n name: \"FileManagerServer/GetFileContentsById\",\n register(container) {\n container.register(GetFileContentsByIdUseCase);\n }\n});\n"],"names":["GetFileContentsByIdFeature","createFeature","container","GetFileContentsByIdUseCase"],"mappings":";;AAGO,MAAMA,6BAA6BC,cAAc;IACpD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
3
|
+
import { GetFileContentsByKeyUseCase as GetFileContentsByKeyUseCaseAbstraction } from "@webiny/api-file-manager/features/file/GetFileContentsByKey/index.js";
|
|
4
|
+
import type { FileContents } from "@webiny/api-file-manager/features/file/GetFileContentsById/index.js";
|
|
5
|
+
import { FileManagerServerConfig } from "../../features/FileManagerServerConfig/abstractions.js";
|
|
6
|
+
declare class GetFileContentsByKeyUseCaseImpl implements GetFileContentsByKeyUseCaseAbstraction.Interface {
|
|
7
|
+
private readonly tenantContext;
|
|
8
|
+
private readonly config;
|
|
9
|
+
constructor(tenantContext: TenantContext.Interface, config: FileManagerServerConfig.Interface);
|
|
10
|
+
execute(key: string): Promise<Result<FileContents, GetFileContentsByKeyUseCaseAbstraction.Error>>;
|
|
11
|
+
}
|
|
12
|
+
export declare const GetFileContentsByKeyUseCase: typeof GetFileContentsByKeyUseCaseImpl & {
|
|
13
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-file-manager/features/file/GetFileContentsByKey/abstractions").IGetFileContentsByKeyUseCase>;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { promises } from "node:fs";
|
|
2
|
+
import { Result } from "@webiny/feature/api";
|
|
3
|
+
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
4
|
+
import { GetFileContentsByKeyUseCase } from "@webiny/api-file-manager/features/file/GetFileContentsByKey/index.js";
|
|
5
|
+
import { FileNotFoundError, FilePersistenceError } from "@webiny/api-file-manager/domain/file/errors.js";
|
|
6
|
+
import { FileManagerServerConfig } from "../FileManagerServerConfig/abstractions.js";
|
|
7
|
+
const CONTENT_TYPE_MAP = {
|
|
8
|
+
jpg: "image/jpeg",
|
|
9
|
+
jpeg: "image/jpeg",
|
|
10
|
+
png: "image/png",
|
|
11
|
+
gif: "image/gif",
|
|
12
|
+
webp: "image/webp",
|
|
13
|
+
svg: "image/svg+xml",
|
|
14
|
+
ico: "image/x-icon",
|
|
15
|
+
bmp: "image/bmp",
|
|
16
|
+
tiff: "image/tiff",
|
|
17
|
+
tif: "image/tiff",
|
|
18
|
+
pdf: "application/pdf",
|
|
19
|
+
json: "application/json",
|
|
20
|
+
xml: "application/xml",
|
|
21
|
+
zip: "application/zip",
|
|
22
|
+
gz: "application/gzip",
|
|
23
|
+
txt: "text/plain",
|
|
24
|
+
html: "text/html",
|
|
25
|
+
htm: "text/html",
|
|
26
|
+
css: "text/css",
|
|
27
|
+
js: "application/javascript",
|
|
28
|
+
ts: "application/typescript",
|
|
29
|
+
mp4: "video/mp4",
|
|
30
|
+
webm: "video/webm",
|
|
31
|
+
mp3: "audio/mpeg",
|
|
32
|
+
wav: "audio/wav",
|
|
33
|
+
ogg: "audio/ogg"
|
|
34
|
+
};
|
|
35
|
+
function resolveContentType(key) {
|
|
36
|
+
const ext = key.split(".").pop()?.toLowerCase();
|
|
37
|
+
if (!ext) return "application/octet-stream";
|
|
38
|
+
return CONTENT_TYPE_MAP[ext] ?? "application/octet-stream";
|
|
39
|
+
}
|
|
40
|
+
class GetFileContentsByKeyUseCaseImpl {
|
|
41
|
+
constructor(tenantContext, config){
|
|
42
|
+
this.tenantContext = tenantContext;
|
|
43
|
+
this.config = config;
|
|
44
|
+
}
|
|
45
|
+
async execute(key) {
|
|
46
|
+
const tenant = this.tenantContext.getTenant();
|
|
47
|
+
const bucketKey = `tenants/${tenant.id}/files/${key}`;
|
|
48
|
+
const storagePath = this.config.storagePath;
|
|
49
|
+
const filePath = `${storagePath}/${bucketKey}`;
|
|
50
|
+
try {
|
|
51
|
+
const buffer = await promises.readFile(filePath);
|
|
52
|
+
const contentType = resolveContentType(key);
|
|
53
|
+
return Result.ok({
|
|
54
|
+
buffer,
|
|
55
|
+
contentType
|
|
56
|
+
});
|
|
57
|
+
} catch (error) {
|
|
58
|
+
if ("ENOENT" === error.code) return Result.fail(new FileNotFoundError(key));
|
|
59
|
+
return Result.fail(new FilePersistenceError(error instanceof Error ? error : new Error(String(error))));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const GetFileContentsByKeyUseCase_GetFileContentsByKeyUseCase = GetFileContentsByKeyUseCase.createImplementation({
|
|
64
|
+
implementation: GetFileContentsByKeyUseCaseImpl,
|
|
65
|
+
dependencies: [
|
|
66
|
+
TenantContext,
|
|
67
|
+
FileManagerServerConfig
|
|
68
|
+
]
|
|
69
|
+
});
|
|
70
|
+
export { GetFileContentsByKeyUseCase_GetFileContentsByKeyUseCase as GetFileContentsByKeyUseCase };
|
|
71
|
+
|
|
72
|
+
//# sourceMappingURL=GetFileContentsByKeyUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/GetFileContentsByKey/GetFileContentsByKeyUseCase.js","sources":["../../../src/features/GetFileContentsByKey/GetFileContentsByKeyUseCase.ts"],"sourcesContent":["import { promises as fs } from \"node:fs\";\nimport { Result } from \"@webiny/feature/api\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { GetFileContentsByKeyUseCase as GetFileContentsByKeyUseCaseAbstraction } from \"@webiny/api-file-manager/features/file/GetFileContentsByKey/index.js\";\nimport type { FileContents } from \"@webiny/api-file-manager/features/file/GetFileContentsById/index.js\";\nimport {\n FileNotFoundError,\n FilePersistenceError\n} from \"@webiny/api-file-manager/domain/file/errors.js\";\nimport { FileManagerServerConfig } from \"~/features/FileManagerServerConfig/abstractions.js\";\n\nconst CONTENT_TYPE_MAP: Record<string, string> = {\n jpg: \"image/jpeg\",\n jpeg: \"image/jpeg\",\n png: \"image/png\",\n gif: \"image/gif\",\n webp: \"image/webp\",\n svg: \"image/svg+xml\",\n ico: \"image/x-icon\",\n bmp: \"image/bmp\",\n tiff: \"image/tiff\",\n tif: \"image/tiff\",\n pdf: \"application/pdf\",\n json: \"application/json\",\n xml: \"application/xml\",\n zip: \"application/zip\",\n gz: \"application/gzip\",\n txt: \"text/plain\",\n html: \"text/html\",\n htm: \"text/html\",\n css: \"text/css\",\n js: \"application/javascript\",\n ts: \"application/typescript\",\n mp4: \"video/mp4\",\n webm: \"video/webm\",\n mp3: \"audio/mpeg\",\n wav: \"audio/wav\",\n ogg: \"audio/ogg\"\n};\n\nfunction resolveContentType(key: string): string {\n const ext = key.split(\".\").pop()?.toLowerCase();\n if (!ext) {\n return \"application/octet-stream\";\n }\n return CONTENT_TYPE_MAP[ext] ?? \"application/octet-stream\";\n}\n\nclass GetFileContentsByKeyUseCaseImpl implements GetFileContentsByKeyUseCaseAbstraction.Interface {\n constructor(\n private readonly tenantContext: TenantContext.Interface,\n private readonly config: FileManagerServerConfig.Interface\n ) {}\n\n async execute(\n key: string\n ): Promise<Result<FileContents, GetFileContentsByKeyUseCaseAbstraction.Error>> {\n const tenant = this.tenantContext.getTenant();\n const bucketKey = `tenants/${tenant.id}/files/${key}`;\n const storagePath = this.config.storagePath;\n const filePath = `${storagePath}/${bucketKey}`;\n\n try {\n const buffer = await fs.readFile(filePath);\n const contentType = resolveContentType(key);\n return Result.ok({ buffer, contentType });\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\") {\n return Result.fail(new FileNotFoundError(key));\n }\n return Result.fail(\n new FilePersistenceError(error instanceof Error ? error : new Error(String(error)))\n );\n }\n }\n}\n\nexport const GetFileContentsByKeyUseCase =\n GetFileContentsByKeyUseCaseAbstraction.createImplementation({\n implementation: GetFileContentsByKeyUseCaseImpl,\n dependencies: [TenantContext, FileManagerServerConfig]\n });\n"],"names":["CONTENT_TYPE_MAP","resolveContentType","key","ext","GetFileContentsByKeyUseCaseImpl","tenantContext","config","tenant","bucketKey","storagePath","filePath","buffer","fs","contentType","Result","error","FileNotFoundError","FilePersistenceError","Error","String","GetFileContentsByKeyUseCase","GetFileContentsByKeyUseCaseAbstraction","TenantContext","FileManagerServerConfig"],"mappings":";;;;;;AAWA,MAAMA,mBAA2C;IAC7C,KAAK;IACL,MAAM;IACN,KAAK;IACL,KAAK;IACL,MAAM;IACN,KAAK;IACL,KAAK;IACL,KAAK;IACL,MAAM;IACN,KAAK;IACL,KAAK;IACL,MAAM;IACN,KAAK;IACL,KAAK;IACL,IAAI;IACJ,KAAK;IACL,MAAM;IACN,KAAK;IACL,KAAK;IACL,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,MAAM;IACN,KAAK;IACL,KAAK;IACL,KAAK;AACT;AAEA,SAASC,mBAAmBC,GAAW;IACnC,MAAMC,MAAMD,IAAI,KAAK,CAAC,KAAK,GAAG,IAAI;IAClC,IAAI,CAACC,KACD,OAAO;IAEX,OAAOH,gBAAgB,CAACG,IAAI,IAAI;AACpC;AAEA,MAAMC;IACF,YACqBC,aAAsC,EACtCC,MAAyC,CAC5D;aAFmBD,aAAa,GAAbA;aACAC,MAAM,GAANA;IAClB;IAEH,MAAM,QACFJ,GAAW,EACgE;QAC3E,MAAMK,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;QAC3C,MAAMC,YAAY,CAAC,QAAQ,EAAED,OAAO,EAAE,CAAC,OAAO,EAAEL,KAAK;QACrD,MAAMO,cAAc,IAAI,CAAC,MAAM,CAAC,WAAW;QAC3C,MAAMC,WAAW,GAAGD,YAAY,CAAC,EAAED,WAAW;QAE9C,IAAI;YACA,MAAMG,SAAS,MAAMC,SAAAA,QAAW,CAACF;YACjC,MAAMG,cAAcZ,mBAAmBC;YACvC,OAAOY,OAAO,EAAE,CAAC;gBAAEH;gBAAQE;YAAY;QAC3C,EAAE,OAAOE,OAAO;YACZ,IAAKA,AAAyC,aAAzCA,MAAgC,IAAI,EACrC,OAAOD,OAAO,IAAI,CAAC,IAAIE,kBAAkBd;YAE7C,OAAOY,OAAO,IAAI,CACd,IAAIG,qBAAqBF,iBAAiBG,QAAQH,QAAQ,IAAIG,MAAMC,OAAOJ;QAEnF;IACJ;AACJ;AAEO,MAAMK,0DACTC,4BAAAA,oBAA2D,CAAC;IACxD,gBAAgBjB;IAChB,cAAc;QAACkB;QAAeC;KAAwB;AAC1D"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { GetFileContentsByKeyUseCase } from "./GetFileContentsByKeyUseCase.js";
|
|
3
|
+
const GetFileContentsByKeyFeature = createFeature({
|
|
4
|
+
name: "FileManagerServer/GetFileContentsByKey",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(GetFileContentsByKeyUseCase);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { GetFileContentsByKeyFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/GetFileContentsByKey/feature.js","sources":["../../../src/features/GetFileContentsByKey/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { GetFileContentsByKeyUseCase } from \"./GetFileContentsByKeyUseCase.js\";\n\nexport const GetFileContentsByKeyFeature = createFeature({\n name: \"FileManagerServer/GetFileContentsByKey\",\n register(container) {\n container.register(GetFileContentsByKeyUseCase);\n }\n});\n"],"names":["GetFileContentsByKeyFeature","createFeature","container","GetFileContentsByKeyUseCase"],"mappings":";;AAGO,MAAMA,8BAA8BC,cAAc;IACrD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
2
|
+
import { GetUploadPayloadUseCase as GetUploadPayloadUseCaseAbstraction } from "@webiny/api-file-manager/features/upload/GetUploadPayload/index.js";
|
|
3
|
+
import type { FileData } from "@webiny/api-file-manager/features/upload/types.js";
|
|
4
|
+
import type { UploadPayloadResponse } from "@webiny/api-file-manager/features/upload/types.js";
|
|
5
|
+
import type { FileManagerSettings } from "@webiny/api-file-manager/domain/settings/types.js";
|
|
6
|
+
import { FileManagerServerConfig } from "../../features/FileManagerServerConfig/abstractions.js";
|
|
7
|
+
declare class GetUploadPayloadUseCaseImpl implements GetUploadPayloadUseCaseAbstraction.Interface {
|
|
8
|
+
private readonly tenantContext;
|
|
9
|
+
private readonly config;
|
|
10
|
+
constructor(tenantContext: TenantContext.Interface, config: FileManagerServerConfig.Interface);
|
|
11
|
+
execute(file: FileData, settings: FileManagerSettings): Promise<UploadPayloadResponse>;
|
|
12
|
+
}
|
|
13
|
+
export declare const GetUploadPayloadUseCase: typeof GetUploadPayloadUseCaseImpl & {
|
|
14
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-file-manager/features/upload/GetUploadPayload/abstractions").IGetUploadPayloadUseCase>;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { validation } from "@webiny/validation";
|
|
2
|
+
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
3
|
+
import { GetUploadPayloadUseCase } from "@webiny/api-file-manager/features/upload/GetUploadPayload/index.js";
|
|
4
|
+
import { createUploadToken } from "../../utils/uploadToken.js";
|
|
5
|
+
import { FileManagerServerConfig } from "../FileManagerServerConfig/abstractions.js";
|
|
6
|
+
const UPLOAD_MAX_FILE_SIZE_DEFAULT = 1099511627776;
|
|
7
|
+
const sanitizeFileSizeValue = (value, defaultValue)=>{
|
|
8
|
+
try {
|
|
9
|
+
validation.validateSync(value, "required,numeric,gte:0");
|
|
10
|
+
return value;
|
|
11
|
+
} catch {
|
|
12
|
+
return defaultValue;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
class GetUploadPayloadUseCaseImpl {
|
|
16
|
+
constructor(tenantContext, config){
|
|
17
|
+
this.tenantContext = tenantContext;
|
|
18
|
+
this.config = config;
|
|
19
|
+
}
|
|
20
|
+
async execute(file, settings) {
|
|
21
|
+
const uploadMinFileSize = sanitizeFileSizeValue(settings.uploadMinFileSize, 0);
|
|
22
|
+
const uploadMaxFileSize = sanitizeFileSizeValue(settings.uploadMaxFileSize, UPLOAD_MAX_FILE_SIZE_DEFAULT);
|
|
23
|
+
const tenant = this.tenantContext.getTenant();
|
|
24
|
+
const storageKey = `tenants/${tenant.id}/files/${file.key}`;
|
|
25
|
+
const secret = this.config.uploadSecret;
|
|
26
|
+
const expiresAt = Date.now() + 60000;
|
|
27
|
+
const token = createUploadToken({
|
|
28
|
+
key: storageKey,
|
|
29
|
+
tenantId: tenant.id,
|
|
30
|
+
expiresAt,
|
|
31
|
+
uploadMinFileSize,
|
|
32
|
+
uploadMaxFileSize
|
|
33
|
+
}, secret);
|
|
34
|
+
const serverUrl = this.config.apiUrl;
|
|
35
|
+
const data = {
|
|
36
|
+
url: `${serverUrl}/webiny-file-upload`,
|
|
37
|
+
fields: {
|
|
38
|
+
key: storageKey,
|
|
39
|
+
token
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
data: data,
|
|
44
|
+
file
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const GetUploadPayloadUseCase_GetUploadPayloadUseCase = GetUploadPayloadUseCase.createImplementation({
|
|
49
|
+
implementation: GetUploadPayloadUseCaseImpl,
|
|
50
|
+
dependencies: [
|
|
51
|
+
TenantContext,
|
|
52
|
+
FileManagerServerConfig
|
|
53
|
+
]
|
|
54
|
+
});
|
|
55
|
+
export { GetUploadPayloadUseCase_GetUploadPayloadUseCase as GetUploadPayloadUseCase };
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=GetUploadPayloadUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/GetUploadPayload/GetUploadPayloadUseCase.js","sources":["../../../src/features/GetUploadPayload/GetUploadPayloadUseCase.ts"],"sourcesContent":["import { validation } from \"@webiny/validation\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { GetUploadPayloadUseCase as GetUploadPayloadUseCaseAbstraction } from \"@webiny/api-file-manager/features/upload/GetUploadPayload/index.js\";\nimport type { FileData } from \"@webiny/api-file-manager/features/upload/types.js\";\nimport type { UploadPayloadResponse } from \"@webiny/api-file-manager/features/upload/types.js\";\nimport type { FileManagerSettings } from \"@webiny/api-file-manager/domain/settings/types.js\";\nimport { createUploadToken } from \"~/utils/uploadToken.js\";\nimport { FileManagerServerConfig } from \"~/features/FileManagerServerConfig/abstractions.js\";\n\nconst UPLOAD_MAX_FILE_SIZE_DEFAULT = 1099511627776; /* 1TB */\n\nconst sanitizeFileSizeValue = (value: number, defaultValue: number): number => {\n try {\n validation.validateSync(value, \"required,numeric,gte:0\");\n return value;\n } catch {\n return defaultValue;\n }\n};\n\nclass GetUploadPayloadUseCaseImpl implements GetUploadPayloadUseCaseAbstraction.Interface {\n public constructor(\n private readonly tenantContext: TenantContext.Interface,\n private readonly config: FileManagerServerConfig.Interface\n ) {}\n\n public async execute(\n file: FileData,\n settings: FileManagerSettings\n ): Promise<UploadPayloadResponse> {\n const uploadMinFileSize = sanitizeFileSizeValue(settings.uploadMinFileSize, 0);\n const uploadMaxFileSize = sanitizeFileSizeValue(\n settings.uploadMaxFileSize,\n UPLOAD_MAX_FILE_SIZE_DEFAULT\n );\n\n const tenant = this.tenantContext.getTenant();\n const storageKey = `tenants/${tenant.id}/files/${file.key}`;\n const secret = this.config.uploadSecret;\n const expiresAt = Date.now() + 60_000;\n\n const token = createUploadToken(\n {\n key: storageKey,\n tenantId: tenant.id,\n expiresAt,\n uploadMinFileSize,\n uploadMaxFileSize\n },\n secret\n );\n\n const serverUrl = this.config.apiUrl;\n\n const data = {\n url: `${serverUrl}/webiny-file-upload`,\n fields: {\n key: storageKey,\n token\n }\n };\n\n return {\n data: data as unknown as Record<string, unknown>,\n file\n };\n }\n}\n\nexport const GetUploadPayloadUseCase = GetUploadPayloadUseCaseAbstraction.createImplementation({\n implementation: GetUploadPayloadUseCaseImpl,\n dependencies: [TenantContext, FileManagerServerConfig]\n});\n"],"names":["UPLOAD_MAX_FILE_SIZE_DEFAULT","sanitizeFileSizeValue","value","defaultValue","validation","GetUploadPayloadUseCaseImpl","tenantContext","config","file","settings","uploadMinFileSize","uploadMaxFileSize","tenant","storageKey","secret","expiresAt","Date","token","createUploadToken","serverUrl","data","GetUploadPayloadUseCase","GetUploadPayloadUseCaseAbstraction","TenantContext","FileManagerServerConfig"],"mappings":";;;;;AASA,MAAMA,+BAA+B;AAErC,MAAMC,wBAAwB,CAACC,OAAeC;IAC1C,IAAI;QACAC,WAAW,YAAY,CAACF,OAAO;QAC/B,OAAOA;IACX,EAAE,OAAM;QACJ,OAAOC;IACX;AACJ;AAEA,MAAME;IACF,YACqBC,aAAsC,EACtCC,MAAyC,CAC5D;aAFmBD,aAAa,GAAbA;aACAC,MAAM,GAANA;IAClB;IAEH,MAAa,QACTC,IAAc,EACdC,QAA6B,EACC;QAC9B,MAAMC,oBAAoBT,sBAAsBQ,SAAS,iBAAiB,EAAE;QAC5E,MAAME,oBAAoBV,sBACtBQ,SAAS,iBAAiB,EAC1BT;QAGJ,MAAMY,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;QAC3C,MAAMC,aAAa,CAAC,QAAQ,EAAED,OAAO,EAAE,CAAC,OAAO,EAAEJ,KAAK,GAAG,EAAE;QAC3D,MAAMM,SAAS,IAAI,CAAC,MAAM,CAAC,YAAY;QACvC,MAAMC,YAAYC,KAAK,GAAG,KAAK;QAE/B,MAAMC,QAAQC,kBACV;YACI,KAAKL;YACL,UAAUD,OAAO,EAAE;YACnBG;YACAL;YACAC;QACJ,GACAG;QAGJ,MAAMK,YAAY,IAAI,CAAC,MAAM,CAAC,MAAM;QAEpC,MAAMC,OAAO;YACT,KAAK,GAAGD,UAAU,mBAAmB,CAAC;YACtC,QAAQ;gBACJ,KAAKN;gBACLI;YACJ;QACJ;QAEA,OAAO;YACH,MAAMG;YACNZ;QACJ;IACJ;AACJ;AAEO,MAAMa,kDAA0BC,wBAAAA,oBAAuD,CAAC;IAC3F,gBAAgBjB;IAChB,cAAc;QAACkB;QAAeC;KAAwB;AAC1D"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { GetUploadPayloadUseCase } from "./GetUploadPayloadUseCase.js";
|
|
3
|
+
const GetUploadPayloadFeature = createFeature({
|
|
4
|
+
name: "FileManagerServer/GetUploadPayload",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(GetUploadPayloadUseCase);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { GetUploadPayloadFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/GetUploadPayload/feature.js","sources":["../../../src/features/GetUploadPayload/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { GetUploadPayloadUseCase } from \"./GetUploadPayloadUseCase.js\";\n\nexport const GetUploadPayloadFeature = createFeature({\n name: \"FileManagerServer/GetUploadPayload\",\n register(container) {\n container.register(GetUploadPayloadUseCase);\n }\n});\n"],"names":["GetUploadPayloadFeature","createFeature","container","GetUploadPayloadUseCase"],"mappings":";;AAGO,MAAMA,0BAA0BC,cAAc;IACjD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CoreGraphQLSchemaFactory } from "@webiny/api-graphql/graphql/abstractions.js";
|
|
2
|
+
import { GraphQLSchemaBuilder } from "@webiny/api-graphql/features/GraphQLSchemaBuilder/abstractions.js";
|
|
3
|
+
/**
|
|
4
|
+
* Upload GraphQL for the self-hosted (server) hosting type. Mirrors the SDL that `api-file-manager-s3`'s
|
|
5
|
+
* `S3GraphQLSchema` contributes (same query/mutation names + `PreSignedPostPayloadInput`), so the
|
|
6
|
+
* transport-agnostic SDK works unchanged. Only the resolvers differ from S3 — they resolve the server
|
|
7
|
+
* upload use cases (local disk + the `/webiny-file-upload` HTTP routes) instead of an S3 client.
|
|
8
|
+
*/
|
|
9
|
+
declare class ServerGraphQLSchemaImpl implements CoreGraphQLSchemaFactory.Interface {
|
|
10
|
+
execute(builder: GraphQLSchemaBuilder.Interface): CoreGraphQLSchemaFactory.Return;
|
|
11
|
+
}
|
|
12
|
+
export declare const ServerGraphQLSchema: typeof ServerGraphQLSchemaImpl & {
|
|
13
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-graphql/graphql/abstractions.core").ICoreGraphQLSchemaFactory>;
|
|
14
|
+
};
|
|
15
|
+
export {};
|