@webiny/api-file-manager-server 0.0.0-unstable.9f53ea597d
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/LICENSE +21 -0
- package/README.md +11 -0
- package/assetDelivery/LocalAssetResolver.d.ts +13 -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 +11 -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 +174 -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 +33 -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 +18 -0
- package/features/CleanupStaleMultipartUploads/CleanupStaleMultipartUploadsTask.js +58 -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 +11 -0
- package/features/CompleteMultiPartUpload/CompleteMultiPartUploadUseCase.js +59 -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 +59 -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 +13 -0
- package/features/DeleteFileFromDisk/DeleteFileFromDiskHandler.js +31 -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 +22 -0
- package/features/ExtractMetadata/ExtractMetadataTask.js +81 -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/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 +13 -0
- package/features/GetFileContentsById/GetFileContentsByIdUseCase.js +35 -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 +13 -0
- package/features/GetFileContentsByKey/GetFileContentsByKeyUseCase.js +69 -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 +58 -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/index.d.ts +4 -0
- package/index.js +42 -0
- package/index.js.map +1 -0
- package/package.json +44 -0
- package/routes/uploadRoutes.d.ts +4 -0
- package/routes/uploadRoutes.js +130 -0
- package/routes/uploadRoutes.js.map +1 -0
- package/types.d.ts +10 -0
- package/types.js +1 -0
- package/utils/resolveServerUrl.d.ts +2 -0
- package/utils/resolveServerUrl.js +10 -0
- package/utils/resolveServerUrl.js.map +1 -0
- package/utils/uploadToken.d.ts +3 -0
- package/utils/uploadToken.js +22 -0
- package/utils/uploadToken.js.map +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Webiny
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @webiny/api-file-manager-server
|
|
2
|
+
|
|
3
|
+
> [!NOTE]
|
|
4
|
+
> This package is part of the [Webiny](https://www.webiny.com) monorepo.
|
|
5
|
+
> It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
|
|
6
|
+
|
|
7
|
+
📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
_This README file is automatically generated during the publish process._
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AssetFactory, AssetResolver as AssetResolverAbstraction, ObjectKey } from "@webiny/api-file-manager/exports/api/file-manager/assetDelivery.js";
|
|
2
|
+
import { GlobalKeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
|
|
3
|
+
export declare class LocalAssetResolver implements AssetResolverAbstraction.Interface {
|
|
4
|
+
private readonly keyValueStore;
|
|
5
|
+
private readonly storagePath;
|
|
6
|
+
private readonly objectKey;
|
|
7
|
+
private readonly assetFactory;
|
|
8
|
+
constructor(keyValueStore: GlobalKeyValueStore.Interface, storagePath: string, objectKey: ObjectKey.Interface, assetFactory: AssetFactory.Interface);
|
|
9
|
+
resolve(request: AssetResolverAbstraction.Request): Promise<AssetFactory.Asset | undefined>;
|
|
10
|
+
}
|
|
11
|
+
export declare const LocalAssetResolverImpl: typeof LocalAssetResolver & {
|
|
12
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-file-manager/delivery").AssetResolver>;
|
|
13
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { AssetFactory, AssetResolver, ObjectKey } from "@webiny/api-file-manager/exports/api/file-manager/assetDelivery.js";
|
|
2
|
+
import { GlobalKeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
|
|
3
|
+
import { LocalContentsReader } from "./LocalContentsReader.js";
|
|
4
|
+
import { LocalStoragePath } from "./abstractions.js";
|
|
5
|
+
class LocalAssetResolver {
|
|
6
|
+
constructor(keyValueStore, storagePath, objectKey, assetFactory){
|
|
7
|
+
this.keyValueStore = keyValueStore;
|
|
8
|
+
this.storagePath = storagePath;
|
|
9
|
+
this.objectKey = objectKey;
|
|
10
|
+
this.assetFactory = assetFactory;
|
|
11
|
+
}
|
|
12
|
+
async resolve(request) {
|
|
13
|
+
const objectKey = this.objectKey.from(request.getKey());
|
|
14
|
+
const fileId = objectKey.id();
|
|
15
|
+
const result = await this.keyValueStore.get(`FileManager/File/${fileId}/Metadata`);
|
|
16
|
+
if (result.isFail()) return;
|
|
17
|
+
const metadata = result.value;
|
|
18
|
+
const asset = this.assetFactory.create({
|
|
19
|
+
id: metadata.id,
|
|
20
|
+
tenant: metadata.tenant,
|
|
21
|
+
size: metadata.size,
|
|
22
|
+
contentType: metadata.contentType,
|
|
23
|
+
key: metadata.bucketKey
|
|
24
|
+
});
|
|
25
|
+
asset.setContentsReader(LocalContentsReader.create(this.storagePath));
|
|
26
|
+
return asset;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const LocalAssetResolverImpl = AssetResolver.createImplementation({
|
|
30
|
+
implementation: LocalAssetResolver,
|
|
31
|
+
dependencies: [
|
|
32
|
+
GlobalKeyValueStore,
|
|
33
|
+
LocalStoragePath,
|
|
34
|
+
ObjectKey,
|
|
35
|
+
AssetFactory
|
|
36
|
+
]
|
|
37
|
+
});
|
|
38
|
+
export { LocalAssetResolver, LocalAssetResolverImpl };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=LocalAssetResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assetDelivery/LocalAssetResolver.js","sources":["../../src/assetDelivery/LocalAssetResolver.ts"],"sourcesContent":["import {\n AssetFactory,\n AssetResolver as AssetResolverAbstraction,\n ObjectKey\n} from \"@webiny/api-file-manager/exports/api/file-manager/assetDelivery.js\";\nimport { GlobalKeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\nimport { LocalContentsReader } from \"~/assetDelivery/LocalContentsReader.js\";\nimport { LocalStoragePath } from \"~/assetDelivery/abstractions.js\";\n\ninterface AssetMetadata {\n id: string;\n tenant: string;\n size: number;\n contentType: string;\n bucketKey: string;\n}\n\nexport class LocalAssetResolver implements AssetResolverAbstraction.Interface {\n constructor(\n private readonly keyValueStore: GlobalKeyValueStore.Interface,\n private readonly storagePath: string,\n private readonly objectKey: ObjectKey.Interface,\n private readonly assetFactory: AssetFactory.Interface\n ) {}\n\n async resolve(\n request: AssetResolverAbstraction.Request\n ): Promise<AssetFactory.Asset | undefined> {\n const objectKey = this.objectKey.from(request.getKey());\n const fileId = objectKey.id();\n const result = await this.keyValueStore.get<AssetMetadata>(\n `FileManager/File/${fileId}/Metadata`\n );\n\n if (result.isFail()) {\n return undefined;\n }\n\n const metadata = result.value;\n\n const asset = this.assetFactory.create({\n id: metadata.id,\n tenant: metadata.tenant,\n size: metadata.size,\n contentType: metadata.contentType,\n key: metadata.bucketKey\n });\n\n asset.setContentsReader(LocalContentsReader.create(this.storagePath));\n\n return asset;\n }\n}\n\nexport const LocalAssetResolverImpl = AssetResolverAbstraction.createImplementation({\n implementation: LocalAssetResolver,\n dependencies: [GlobalKeyValueStore, LocalStoragePath, ObjectKey, AssetFactory]\n});\n"],"names":["LocalAssetResolver","keyValueStore","storagePath","objectKey","assetFactory","request","fileId","result","metadata","asset","LocalContentsReader","LocalAssetResolverImpl","AssetResolverAbstraction","GlobalKeyValueStore","LocalStoragePath","ObjectKey","AssetFactory"],"mappings":";;;;AAiBO,MAAMA;IACT,YACqBC,aAA4C,EAC5CC,WAAmB,EACnBC,SAA8B,EAC9BC,YAAoC,CACvD;aAJmBH,aAAa,GAAbA;aACAC,WAAW,GAAXA;aACAC,SAAS,GAATA;aACAC,YAAY,GAAZA;IAClB;IAEH,MAAM,QACFC,OAAyC,EACF;QACvC,MAAMF,YAAY,IAAI,CAAC,SAAS,CAAC,IAAI,CAACE,QAAQ,MAAM;QACpD,MAAMC,SAASH,UAAU,EAAE;QAC3B,MAAMI,SAAS,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CACvC,CAAC,iBAAiB,EAAED,OAAO,SAAS,CAAC;QAGzC,IAAIC,OAAO,MAAM,IACb;QAGJ,MAAMC,WAAWD,OAAO,KAAK;QAE7B,MAAME,QAAQ,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC;YACnC,IAAID,SAAS,EAAE;YACf,QAAQA,SAAS,MAAM;YACvB,MAAMA,SAAS,IAAI;YACnB,aAAaA,SAAS,WAAW;YACjC,KAAKA,SAAS,SAAS;QAC3B;QAEAC,MAAM,iBAAiB,CAACC,oBAAoB,MAAM,CAAC,IAAI,CAAC,WAAW;QAEnE,OAAOD;IACX;AACJ;AAEO,MAAME,yBAAyBC,cAAAA,oBAA6C,CAAC;IAChF,gBAAgBZ;IAChB,cAAc;QAACa;QAAqBC;QAAkBC;QAAWC;KAAa;AAClF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AssetContentsReader } from "@webiny/api-file-manager/exports/api/file-manager/assetDelivery.js";
|
|
2
|
+
export declare class LocalContentsReader implements AssetContentsReader.Interface {
|
|
3
|
+
private readonly storagePath;
|
|
4
|
+
static create(storagePath: string): LocalContentsReader;
|
|
5
|
+
private constructor();
|
|
6
|
+
read(asset: AssetContentsReader.Asset): Promise<Buffer>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import promises from "node:fs/promises";
|
|
2
|
+
import node_path from "node:path";
|
|
3
|
+
class LocalContentsReader {
|
|
4
|
+
static create(storagePath) {
|
|
5
|
+
return new LocalContentsReader(storagePath);
|
|
6
|
+
}
|
|
7
|
+
constructor(storagePath){
|
|
8
|
+
this.storagePath = storagePath;
|
|
9
|
+
}
|
|
10
|
+
async read(asset) {
|
|
11
|
+
const filePath = node_path.join(this.storagePath, asset.getKey());
|
|
12
|
+
const data = await promises.readFile(filePath);
|
|
13
|
+
return data;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export { LocalContentsReader };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=LocalContentsReader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assetDelivery/LocalContentsReader.js","sources":["../../src/assetDelivery/LocalContentsReader.ts"],"sourcesContent":["import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { AssetContentsReader } from \"@webiny/api-file-manager/exports/api/file-manager/assetDelivery.js\";\n\nexport class LocalContentsReader implements AssetContentsReader.Interface {\n private readonly storagePath: string;\n\n public static create(storagePath: string) {\n return new LocalContentsReader(storagePath);\n }\n\n private constructor(storagePath: string) {\n this.storagePath = storagePath;\n }\n\n public async read(asset: AssetContentsReader.Asset): Promise<Buffer> {\n const filePath = path.join(this.storagePath, asset.getKey());\n const data = await fs.readFile(filePath);\n return data;\n }\n}\n"],"names":["LocalContentsReader","storagePath","asset","filePath","path","data","fs"],"mappings":";;AAIO,MAAMA;IAGT,OAAc,OAAOC,WAAmB,EAAE;QACtC,OAAO,IAAID,oBAAoBC;IACnC;IAEA,YAAoBA,WAAmB,CAAE;QACrC,IAAI,CAAC,WAAW,GAAGA;IACvB;IAEA,MAAa,KAAKC,KAAgC,EAAmB;QACjE,MAAMC,WAAWC,UAAAA,IAAS,CAAC,IAAI,CAAC,WAAW,EAAEF,MAAM,MAAM;QACzD,MAAMG,OAAO,MAAMC,SAAAA,QAAW,CAACH;QAC/B,OAAOE;IACX;AACJ"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AssetOutputStrategy as AssetOutputStrategyAbstraction, StreamAssetReply } from "@webiny/api-file-manager/exports/api/file-manager/assetDelivery.js";
|
|
2
|
+
import type { ILocalAssetDeliveryConfig } from "../assetDelivery/abstractions.js";
|
|
3
|
+
export declare class LocalOutputStrategy implements AssetOutputStrategyAbstraction.Interface {
|
|
4
|
+
private readonly assetStreamingMaxSize;
|
|
5
|
+
private readonly streamAssetReply;
|
|
6
|
+
constructor(config: ILocalAssetDeliveryConfig, streamAssetReply: StreamAssetReply.Interface);
|
|
7
|
+
output(asset: AssetOutputStrategyAbstraction.Asset): Promise<AssetOutputStrategyAbstraction.AssetReply>;
|
|
8
|
+
}
|
|
9
|
+
export declare const LocalOutputStrategyImpl: typeof LocalOutputStrategy & {
|
|
10
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-file-manager/delivery").AssetOutputStrategy>;
|
|
11
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AssetOutputStrategy, StreamAssetReply } from "@webiny/api-file-manager/exports/api/file-manager/assetDelivery.js";
|
|
2
|
+
import { LocalAssetDeliveryConfig } from "./abstractions.js";
|
|
3
|
+
class LocalOutputStrategy {
|
|
4
|
+
constructor(config, streamAssetReply){
|
|
5
|
+
this.assetStreamingMaxSize = config.assetStreamingMaxSize;
|
|
6
|
+
this.streamAssetReply = streamAssetReply;
|
|
7
|
+
}
|
|
8
|
+
async output(asset) {
|
|
9
|
+
return this.streamAssetReply.create(asset);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const LocalOutputStrategyImpl = AssetOutputStrategy.createImplementation({
|
|
13
|
+
implementation: LocalOutputStrategy,
|
|
14
|
+
dependencies: [
|
|
15
|
+
LocalAssetDeliveryConfig,
|
|
16
|
+
StreamAssetReply
|
|
17
|
+
]
|
|
18
|
+
});
|
|
19
|
+
export { LocalOutputStrategy, LocalOutputStrategyImpl };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=LocalOutputStrategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assetDelivery/LocalOutputStrategy.js","sources":["../../src/assetDelivery/LocalOutputStrategy.ts"],"sourcesContent":["import {\n AssetOutputStrategy as AssetOutputStrategyAbstraction,\n StreamAssetReply\n} from \"@webiny/api-file-manager/exports/api/file-manager/assetDelivery.js\";\nimport { LocalAssetDeliveryConfig } from \"~/assetDelivery/abstractions.js\";\nimport type { ILocalAssetDeliveryConfig } from \"~/assetDelivery/abstractions.js\";\n\nexport class LocalOutputStrategy implements AssetOutputStrategyAbstraction.Interface {\n private readonly assetStreamingMaxSize: number;\n private readonly streamAssetReply: StreamAssetReply.Interface;\n\n constructor(config: ILocalAssetDeliveryConfig, streamAssetReply: StreamAssetReply.Interface) {\n this.assetStreamingMaxSize = config.assetStreamingMaxSize;\n this.streamAssetReply = streamAssetReply;\n }\n\n async output(\n asset: AssetOutputStrategyAbstraction.Asset\n ): Promise<AssetOutputStrategyAbstraction.AssetReply> {\n return this.streamAssetReply.create(asset);\n }\n}\n\nexport const LocalOutputStrategyImpl = AssetOutputStrategyAbstraction.createImplementation({\n implementation: LocalOutputStrategy,\n dependencies: [LocalAssetDeliveryConfig, StreamAssetReply]\n});\n"],"names":["LocalOutputStrategy","config","streamAssetReply","asset","LocalOutputStrategyImpl","AssetOutputStrategyAbstraction","LocalAssetDeliveryConfig","StreamAssetReply"],"mappings":";;AAOO,MAAMA;IAIT,YAAYC,MAAiC,EAAEC,gBAA4C,CAAE;QACzF,IAAI,CAAC,qBAAqB,GAAGD,OAAO,qBAAqB;QACzD,IAAI,CAAC,gBAAgB,GAAGC;IAC5B;IAEA,MAAM,OACFC,KAA2C,EACO;QAClD,OAAO,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAACA;IACxC;AACJ;AAEO,MAAMC,0BAA0BC,oBAAAA,oBAAmD,CAAC;IACvF,gBAAgBL;IAChB,cAAc;QAACM;QAA0BC;KAAiB;AAC9D"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
2
|
+
import { GetFileUseCase } from "@webiny/api-file-manager/features/file/GetFile/index.js";
|
|
3
|
+
import type { IAssetTypeHandler } from "@webiny/api-file-manager/features/assetDelivery/abstractions/AssetType.js";
|
|
4
|
+
import type { Asset } from "@webiny/api-file-manager/delivery/AssetDelivery/Asset.js";
|
|
5
|
+
import type { AssetRequest } from "@webiny/api-file-manager/delivery/AssetDelivery/AssetRequest.js";
|
|
6
|
+
import type { ILocalAssetDeliveryConfig } from "../assetDelivery/abstractions.js";
|
|
7
|
+
export declare class LocalSharpTransform implements IAssetTypeHandler {
|
|
8
|
+
private readonly storagePath;
|
|
9
|
+
private readonly imageResizeWidths;
|
|
10
|
+
private readonly imageQuality;
|
|
11
|
+
private readonly identityContext;
|
|
12
|
+
private readonly getFile;
|
|
13
|
+
constructor(storagePath: string, config: ILocalAssetDeliveryConfig, identityContext: IdentityContext.Interface, getFile: GetFileUseCase.Interface);
|
|
14
|
+
handle(assetRequest: AssetRequest, asset: Asset): Promise<Asset>;
|
|
15
|
+
private loadAssetCrop;
|
|
16
|
+
private transformAsset;
|
|
17
|
+
private optimizeAsset;
|
|
18
|
+
private isAssetAnimated;
|
|
19
|
+
private optimizePng;
|
|
20
|
+
private optimizeJpeg;
|
|
21
|
+
}
|
|
22
|
+
export declare const LocalSharpTransformImpl: typeof LocalSharpTransform & {
|
|
23
|
+
__abstraction: import("@webiny/di").Abstraction<IAssetTypeHandler>;
|
|
24
|
+
};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import sharp from "sharp";
|
|
2
|
+
import promises from "node:fs/promises";
|
|
3
|
+
import node_path from "node:path";
|
|
4
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
5
|
+
import { GetFileUseCase } from "@webiny/api-file-manager/features/file/GetFile/index.js";
|
|
6
|
+
import { CallableContentsReader, DEFAULT_IMAGE_QUALITY, contentTypeForFormat } from "@webiny/api-file-manager/features/assetDelivery/transformation/index.js";
|
|
7
|
+
import { extractFramedRegion, transformImageBuffer } from "@webiny/api-file-manager/features/assetDelivery/assetTypes/image/transformImage.js";
|
|
8
|
+
import { normalizeImageOptions } from "@webiny/api-file-manager/features/assetDelivery/assetTypes/image/normalizeImageOptions.js";
|
|
9
|
+
import { AssetKeyGenerator, ImageAssetTypeHandler } from "@webiny/api-file-manager/features/assetDelivery/assetTypes/image/index.js";
|
|
10
|
+
import { LocalAssetDeliveryConfig, LocalStoragePath } from "./abstractions.js";
|
|
11
|
+
const hasTransform = (options)=>void 0 !== options.width || void 0 !== options.format || void 0 !== options.quality;
|
|
12
|
+
class LocalSharpTransform {
|
|
13
|
+
constructor(storagePath, config, identityContext, getFile){
|
|
14
|
+
this.storagePath = storagePath;
|
|
15
|
+
this.imageResizeWidths = config.imageResizeWidths;
|
|
16
|
+
this.imageQuality = {
|
|
17
|
+
...DEFAULT_IMAGE_QUALITY,
|
|
18
|
+
...config.imageQuality ?? {}
|
|
19
|
+
};
|
|
20
|
+
this.identityContext = identityContext;
|
|
21
|
+
this.getFile = getFile;
|
|
22
|
+
}
|
|
23
|
+
async handle(assetRequest, asset) {
|
|
24
|
+
const rawQuery = assetRequest.getOptions();
|
|
25
|
+
const acceptHeader = assetRequest.getContext().accept;
|
|
26
|
+
const { original, crop, focal, aspectRatio, ...options } = normalizeImageOptions(rawQuery, acceptHeader);
|
|
27
|
+
const assetCrop = await this.loadAssetCrop(asset.getId());
|
|
28
|
+
const framing = {
|
|
29
|
+
crop: crop ?? assetCrop,
|
|
30
|
+
focal,
|
|
31
|
+
aspectRatio
|
|
32
|
+
};
|
|
33
|
+
const transformedAsset = asset.clone();
|
|
34
|
+
if (hasTransform(options)) return this.transformAsset(transformedAsset, options, framing);
|
|
35
|
+
return this.optimizeAsset(transformedAsset, framing);
|
|
36
|
+
}
|
|
37
|
+
async loadAssetCrop(fileId) {
|
|
38
|
+
const result = await this.identityContext.withoutAuthorization(()=>this.getFile.execute(fileId));
|
|
39
|
+
if (result.isFail()) return;
|
|
40
|
+
const imageEdit = result.value.metadata?.imageEdit;
|
|
41
|
+
return imageEdit?.crop;
|
|
42
|
+
}
|
|
43
|
+
async transformAsset(asset, options, framing) {
|
|
44
|
+
const assetKey = AssetKeyGenerator.create(asset, framing);
|
|
45
|
+
const transformedAssetKey = assetKey.getTransformedImageKey(options);
|
|
46
|
+
const transformedFilePath = node_path.join(this.storagePath, transformedAssetKey);
|
|
47
|
+
const contentType = options.format ? contentTypeForFormat(options.format) : asset.getContentType();
|
|
48
|
+
try {
|
|
49
|
+
const buffer = await promises.readFile(transformedFilePath);
|
|
50
|
+
const newAsset = asset.withProps({
|
|
51
|
+
size: buffer.length,
|
|
52
|
+
contentType
|
|
53
|
+
});
|
|
54
|
+
newAsset.setContentsReader(CallableContentsReader.create(()=>buffer));
|
|
55
|
+
console.log("Return a previously transformed asset", {
|
|
56
|
+
key: transformedAssetKey,
|
|
57
|
+
size: newAsset.getSize()
|
|
58
|
+
});
|
|
59
|
+
return newAsset;
|
|
60
|
+
} catch {
|
|
61
|
+
const optimizedImage = await this.optimizeAsset(asset, framing);
|
|
62
|
+
console.log("Transform the asset", options);
|
|
63
|
+
const baseBuffer = await optimizedImage.getContents();
|
|
64
|
+
const { buffer: transformedBuffer, contentType: outputContentType } = await transformImageBuffer({
|
|
65
|
+
buffer: baseBuffer,
|
|
66
|
+
animated: this.isAssetAnimated(asset),
|
|
67
|
+
sourceContentType: asset.getContentType(),
|
|
68
|
+
widths: this.imageResizeWidths,
|
|
69
|
+
options,
|
|
70
|
+
qualityDefaults: this.imageQuality
|
|
71
|
+
});
|
|
72
|
+
const newAsset = asset.withProps({
|
|
73
|
+
size: transformedBuffer.length,
|
|
74
|
+
contentType: outputContentType
|
|
75
|
+
});
|
|
76
|
+
newAsset.setContentsReader(CallableContentsReader.create(()=>transformedBuffer));
|
|
77
|
+
await promises.mkdir(node_path.dirname(transformedFilePath), {
|
|
78
|
+
recursive: true
|
|
79
|
+
});
|
|
80
|
+
await promises.writeFile(transformedFilePath, await newAsset.getContents());
|
|
81
|
+
console.log("Return the transformed asset", {
|
|
82
|
+
key: transformedAssetKey,
|
|
83
|
+
size: newAsset.getSize(),
|
|
84
|
+
contentType: newAsset.getContentType()
|
|
85
|
+
});
|
|
86
|
+
return newAsset;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async optimizeAsset(asset, framing) {
|
|
90
|
+
console.log("Optimize asset", {
|
|
91
|
+
id: asset.getId(),
|
|
92
|
+
key: asset.getKey(),
|
|
93
|
+
size: asset.getSize(),
|
|
94
|
+
type: asset.getContentType()
|
|
95
|
+
});
|
|
96
|
+
const assetKey = AssetKeyGenerator.create(asset, framing);
|
|
97
|
+
const optimizedAssetKey = assetKey.getOptimizedImageKey();
|
|
98
|
+
const optimizedFilePath = node_path.join(this.storagePath, optimizedAssetKey);
|
|
99
|
+
try {
|
|
100
|
+
const buffer = await promises.readFile(optimizedFilePath);
|
|
101
|
+
console.log("Return a previously optimized asset", optimizedAssetKey);
|
|
102
|
+
const newAsset = asset.withProps({
|
|
103
|
+
size: buffer.length
|
|
104
|
+
});
|
|
105
|
+
newAsset.setContentsReader(CallableContentsReader.create(()=>buffer));
|
|
106
|
+
return newAsset;
|
|
107
|
+
} catch {
|
|
108
|
+
console.log("Create an optimized version of the original asset", asset.getKey());
|
|
109
|
+
let buffer = await asset.getContents();
|
|
110
|
+
const framed = await extractFramedRegion(buffer, framing);
|
|
111
|
+
const cropped = framed !== buffer;
|
|
112
|
+
buffer = framed;
|
|
113
|
+
const optimizationMap = {
|
|
114
|
+
"image/png": (buffer)=>this.optimizePng(buffer),
|
|
115
|
+
"image/jpeg": (buffer)=>this.optimizeJpeg(buffer),
|
|
116
|
+
"image/jpg": (buffer)=>this.optimizeJpeg(buffer)
|
|
117
|
+
};
|
|
118
|
+
const optimization = optimizationMap[asset.getContentType()];
|
|
119
|
+
if (!optimization && !cropped) {
|
|
120
|
+
console.log(`No optimizations defined for ${asset.getContentType()}`);
|
|
121
|
+
return asset;
|
|
122
|
+
}
|
|
123
|
+
const finalBuffer = optimization ? await optimization(buffer).toBuffer() : buffer;
|
|
124
|
+
console.log("Optimized asset size", finalBuffer.length);
|
|
125
|
+
const newAsset = asset.withProps({
|
|
126
|
+
size: finalBuffer.length
|
|
127
|
+
});
|
|
128
|
+
newAsset.setContentsReader(CallableContentsReader.create(()=>finalBuffer));
|
|
129
|
+
await promises.mkdir(node_path.dirname(optimizedFilePath), {
|
|
130
|
+
recursive: true
|
|
131
|
+
});
|
|
132
|
+
await promises.writeFile(optimizedFilePath, await newAsset.getContents());
|
|
133
|
+
return newAsset;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
isAssetAnimated(asset) {
|
|
137
|
+
return [
|
|
138
|
+
"gif",
|
|
139
|
+
"webp"
|
|
140
|
+
].includes(asset.getExtension());
|
|
141
|
+
}
|
|
142
|
+
optimizePng(buffer) {
|
|
143
|
+
return sharp(buffer).resize({
|
|
144
|
+
width: 2560,
|
|
145
|
+
withoutEnlargement: true,
|
|
146
|
+
fit: "inside"
|
|
147
|
+
}).png({
|
|
148
|
+
compressionLevel: 9,
|
|
149
|
+
adaptiveFiltering: true,
|
|
150
|
+
force: true
|
|
151
|
+
}).withMetadata();
|
|
152
|
+
}
|
|
153
|
+
optimizeJpeg(buffer) {
|
|
154
|
+
return sharp(buffer).resize({
|
|
155
|
+
width: 2560,
|
|
156
|
+
withoutEnlargement: true,
|
|
157
|
+
fit: "inside"
|
|
158
|
+
}).withMetadata().toFormat("jpeg", {
|
|
159
|
+
quality: 90
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const LocalSharpTransformImpl = ImageAssetTypeHandler.createImplementation({
|
|
164
|
+
implementation: LocalSharpTransform,
|
|
165
|
+
dependencies: [
|
|
166
|
+
LocalStoragePath,
|
|
167
|
+
LocalAssetDeliveryConfig,
|
|
168
|
+
IdentityContext,
|
|
169
|
+
GetFileUseCase
|
|
170
|
+
]
|
|
171
|
+
});
|
|
172
|
+
export { LocalSharpTransform, LocalSharpTransformImpl };
|
|
173
|
+
|
|
174
|
+
//# sourceMappingURL=LocalSharpTransform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assetDelivery/LocalSharpTransform.js","sources":["../../src/assetDelivery/LocalSharpTransform.ts"],"sourcesContent":["import sharp from \"sharp\";\nimport type { Sharp } from \"sharp\";\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { GetFileUseCase } from \"@webiny/api-file-manager/features/file/GetFile/index.js\";\nimport {\n contentTypeForFormat,\n DEFAULT_IMAGE_QUALITY,\n type ImageFormat\n} from \"@webiny/api-file-manager/features/assetDelivery/transformation/index.js\";\nimport {\n extractFramedRegion,\n transformImageBuffer\n} from \"@webiny/api-file-manager/features/assetDelivery/assetTypes/image/transformImage.js\";\nimport type {\n AssetImageEdit,\n Framing,\n ImageRequestOptions\n} from \"@webiny/api-file-manager/features/assetDelivery/assetTypes/image/imageTypes.js\";\nimport { normalizeImageOptions } from \"@webiny/api-file-manager/features/assetDelivery/assetTypes/image/normalizeImageOptions.js\";\nimport { CallableContentsReader } from \"@webiny/api-file-manager/features/assetDelivery/transformation/index.js\";\nimport { AssetKeyGenerator } from \"@webiny/api-file-manager/features/assetDelivery/assetTypes/image/index.js\";\nimport { ImageAssetTypeHandler } from \"@webiny/api-file-manager/features/assetDelivery/assetTypes/image/index.js\";\nimport type { IAssetTypeHandler } from \"@webiny/api-file-manager/features/assetDelivery/abstractions/AssetType.js\";\nimport type { Asset } from \"@webiny/api-file-manager/delivery/AssetDelivery/Asset.js\";\nimport type { AssetRequest } from \"@webiny/api-file-manager/delivery/AssetDelivery/AssetRequest.js\";\nimport { LocalStoragePath } from \"~/assetDelivery/abstractions.js\";\nimport { LocalAssetDeliveryConfig } from \"~/assetDelivery/abstractions.js\";\nimport type { ILocalAssetDeliveryConfig } from \"~/assetDelivery/abstractions.js\";\n\ntype TransformOptions = Omit<ImageRequestOptions, \"original\" | \"crop\" | \"focal\" | \"aspectRatio\">;\n\nconst hasTransform = (options: TransformOptions): boolean => {\n return (\n options.width !== undefined || options.format !== undefined || options.quality !== undefined\n );\n};\n\nexport class LocalSharpTransform implements IAssetTypeHandler {\n private readonly storagePath: string;\n private readonly imageResizeWidths: number[];\n private readonly imageQuality: Record<ImageFormat, number>;\n private readonly identityContext: IdentityContext.Interface;\n private readonly getFile: GetFileUseCase.Interface;\n\n constructor(\n storagePath: string,\n config: ILocalAssetDeliveryConfig,\n identityContext: IdentityContext.Interface,\n getFile: GetFileUseCase.Interface\n ) {\n this.storagePath = storagePath;\n this.imageResizeWidths = config.imageResizeWidths;\n this.imageQuality = { ...DEFAULT_IMAGE_QUALITY, ...(config.imageQuality ?? {}) };\n this.identityContext = identityContext;\n this.getFile = getFile;\n }\n\n async handle(assetRequest: AssetRequest, asset: Asset): Promise<Asset> {\n const rawQuery = assetRequest.getOptions() as Record<string, any>;\n const acceptHeader = assetRequest.getContext<{ accept?: string }>().accept;\n // oxlint-disable-next-line typescript/no-unused-vars\n const { original, crop, focal, aspectRatio, ...options } = normalizeImageOptions(\n rawQuery,\n acceptHeader\n );\n\n const assetCrop = await this.loadAssetCrop(asset.getId());\n const framing: Framing = {\n crop: crop ?? assetCrop,\n focal,\n aspectRatio\n };\n\n const transformedAsset = asset.clone();\n\n if (hasTransform(options)) {\n return this.transformAsset(transformedAsset, options, framing);\n }\n\n return this.optimizeAsset(transformedAsset, framing);\n }\n\n private async loadAssetCrop(fileId: string) {\n const result = await this.identityContext.withoutAuthorization(() =>\n this.getFile.execute(fileId)\n );\n\n if (result.isFail()) {\n return undefined;\n }\n\n const imageEdit = result.value.metadata?.imageEdit as AssetImageEdit | undefined;\n return imageEdit?.crop;\n }\n\n private async transformAsset(asset: Asset, options: TransformOptions, framing: Framing) {\n const assetKey = AssetKeyGenerator.create(asset, framing);\n const transformedAssetKey = assetKey.getTransformedImageKey(options);\n const transformedFilePath = path.join(this.storagePath, transformedAssetKey);\n\n const contentType = options.format\n ? contentTypeForFormat(options.format)\n : asset.getContentType();\n\n try {\n const buffer = await fs.readFile(transformedFilePath);\n\n const newAsset = asset.withProps({ size: buffer.length, contentType });\n newAsset.setContentsReader(CallableContentsReader.create(() => buffer));\n\n console.log(`Return a previously transformed asset`, {\n key: transformedAssetKey,\n size: newAsset.getSize()\n });\n\n return newAsset;\n } catch {\n const optimizedImage = await this.optimizeAsset(asset, framing);\n\n console.log(`Transform the asset`, options);\n const baseBuffer = await optimizedImage.getContents();\n const { buffer: transformedBuffer, contentType: outputContentType } =\n await transformImageBuffer({\n buffer: baseBuffer,\n animated: this.isAssetAnimated(asset),\n sourceContentType: asset.getContentType(),\n widths: this.imageResizeWidths,\n options,\n qualityDefaults: this.imageQuality\n });\n\n const newAsset = asset.withProps({\n size: transformedBuffer.length,\n contentType: outputContentType\n });\n newAsset.setContentsReader(CallableContentsReader.create(() => transformedBuffer));\n\n await fs.mkdir(path.dirname(transformedFilePath), { recursive: true });\n await fs.writeFile(transformedFilePath, await newAsset.getContents());\n\n console.log(`Return the transformed asset`, {\n key: transformedAssetKey,\n size: newAsset.getSize(),\n contentType: newAsset.getContentType()\n });\n\n return newAsset;\n }\n }\n\n private async optimizeAsset(asset: Asset, framing: Framing) {\n console.log(\"Optimize asset\", {\n id: asset.getId(),\n key: asset.getKey(),\n size: asset.getSize(),\n type: asset.getContentType()\n });\n\n const assetKey = AssetKeyGenerator.create(asset, framing);\n const optimizedAssetKey = assetKey.getOptimizedImageKey();\n const optimizedFilePath = path.join(this.storagePath, optimizedAssetKey);\n\n try {\n const buffer = await fs.readFile(optimizedFilePath);\n\n console.log(\"Return a previously optimized asset\", optimizedAssetKey);\n\n const newAsset = asset.withProps({ size: buffer.length });\n newAsset.setContentsReader(CallableContentsReader.create(() => buffer));\n\n return newAsset;\n } catch {\n console.log(\"Create an optimized version of the original asset\", asset.getKey());\n let buffer = await asset.getContents();\n\n const framed = await extractFramedRegion(buffer, framing);\n const cropped = framed !== buffer;\n buffer = framed;\n\n const optimizationMap: Record<string, ((buffer: Buffer) => Sharp) | undefined> = {\n \"image/png\": (buffer: Buffer) => this.optimizePng(buffer),\n \"image/jpeg\": (buffer: Buffer) => this.optimizeJpeg(buffer),\n \"image/jpg\": (buffer: Buffer) => this.optimizeJpeg(buffer)\n };\n\n const optimization = optimizationMap[asset.getContentType()];\n\n if (!optimization && !cropped) {\n console.log(`No optimizations defined for ${asset.getContentType()}`);\n return asset;\n }\n\n const finalBuffer = optimization ? await optimization(buffer).toBuffer() : buffer;\n\n console.log(\"Optimized asset size\", finalBuffer.length);\n\n const newAsset = asset.withProps({ size: finalBuffer.length });\n newAsset.setContentsReader(CallableContentsReader.create(() => finalBuffer));\n\n await fs.mkdir(path.dirname(optimizedFilePath), { recursive: true });\n await fs.writeFile(optimizedFilePath, await newAsset.getContents());\n\n return newAsset;\n }\n }\n\n private isAssetAnimated(asset: Asset) {\n return [\"gif\", \"webp\"].includes(asset.getExtension());\n }\n\n private optimizePng(buffer: Buffer) {\n return sharp(buffer)\n .resize({ width: 2560, withoutEnlargement: true, fit: \"inside\" })\n .png({ compressionLevel: 9, adaptiveFiltering: true, force: true })\n .withMetadata();\n }\n\n private optimizeJpeg(buffer: Buffer) {\n return sharp(buffer)\n .resize({ width: 2560, withoutEnlargement: true, fit: \"inside\" })\n .withMetadata()\n .toFormat(\"jpeg\", { quality: 90 });\n }\n}\n\nexport const LocalSharpTransformImpl = ImageAssetTypeHandler.createImplementation({\n implementation: LocalSharpTransform,\n dependencies: [LocalStoragePath, LocalAssetDeliveryConfig, IdentityContext, GetFileUseCase]\n});\n"],"names":["hasTransform","options","undefined","LocalSharpTransform","storagePath","config","identityContext","getFile","DEFAULT_IMAGE_QUALITY","assetRequest","asset","rawQuery","acceptHeader","original","crop","focal","aspectRatio","normalizeImageOptions","assetCrop","framing","transformedAsset","fileId","result","imageEdit","assetKey","AssetKeyGenerator","transformedAssetKey","transformedFilePath","path","contentType","contentTypeForFormat","buffer","fs","newAsset","CallableContentsReader","console","optimizedImage","baseBuffer","transformedBuffer","outputContentType","transformImageBuffer","optimizedAssetKey","optimizedFilePath","framed","extractFramedRegion","cropped","optimizationMap","optimization","finalBuffer","sharp","LocalSharpTransformImpl","ImageAssetTypeHandler","LocalStoragePath","LocalAssetDeliveryConfig","IdentityContext","GetFileUseCase"],"mappings":"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"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ImageFormat } from "@webiny/api-file-manager/features/assetDelivery/transformation/index.js";
|
|
2
|
+
export interface ILocalAssetDeliveryConfig {
|
|
3
|
+
imageResizeWidths: number[];
|
|
4
|
+
imageQuality?: Partial<Record<ImageFormat, number>>;
|
|
5
|
+
assetStreamingMaxSize: number;
|
|
6
|
+
}
|
|
7
|
+
export declare const LocalAssetDeliveryConfig: import("@webiny/di").Abstraction<ILocalAssetDeliveryConfig>;
|
|
8
|
+
export declare const LocalStoragePath: import("@webiny/di").Abstraction<string>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
+
const LocalAssetDeliveryConfig = createAbstraction("AssetDelivery/LocalConfig");
|
|
3
|
+
const LocalStoragePath = createAbstraction("AssetDelivery/LocalStoragePath");
|
|
4
|
+
export { LocalAssetDeliveryConfig, LocalStoragePath };
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=abstractions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assetDelivery/abstractions.js","sources":["../../src/assetDelivery/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { ImageFormat } from \"@webiny/api-file-manager/features/assetDelivery/transformation/index.js\";\n\nexport interface ILocalAssetDeliveryConfig {\n imageResizeWidths: number[];\n imageQuality?: Partial<Record<ImageFormat, number>>;\n assetStreamingMaxSize: number;\n}\n\nexport const LocalAssetDeliveryConfig = createAbstraction<ILocalAssetDeliveryConfig>(\n \"AssetDelivery/LocalConfig\"\n);\n\nexport const LocalStoragePath = createAbstraction<string>(\"AssetDelivery/LocalStoragePath\");\n"],"names":["LocalAssetDeliveryConfig","createAbstraction","LocalStoragePath"],"mappings":";AASO,MAAMA,2BAA2BC,kBACpC;AAGG,MAAMC,mBAAmBD,kBAA0B"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { AssetDeliveryParams } from "../assetDelivery/types.js";
|
|
2
|
+
export declare const assetDeliveryConfig: (params: AssetDeliveryParams) => ((import("@webiny/handler").ModifyFastifyPlugin | import("@webiny/handler").RegisterExtensionPlugin<import("@webiny/handler/types").Context>)[] | import("@webiny/handler").RegisterExtensionPlugin<import("@webiny/handler/types").Context>)[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createAssetDelivery } from "@webiny/api-file-manager";
|
|
2
|
+
import { createRegisterExtensionPlugin } from "@webiny/handler";
|
|
3
|
+
import { createLocalAssetDeliveryFeature } from "./feature.js";
|
|
4
|
+
const assetDeliveryConfig = (params)=>{
|
|
5
|
+
const feature = createLocalAssetDeliveryFeature(params);
|
|
6
|
+
return [
|
|
7
|
+
createAssetDelivery(),
|
|
8
|
+
createRegisterExtensionPlugin((context)=>{
|
|
9
|
+
feature.register(context.container);
|
|
10
|
+
})
|
|
11
|
+
];
|
|
12
|
+
};
|
|
13
|
+
export { assetDeliveryConfig };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=assetDeliveryConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assetDelivery/assetDeliveryConfig.js","sources":["../../src/assetDelivery/assetDeliveryConfig.ts"],"sourcesContent":["import { createAssetDelivery as createBaseAssetDelivery } from \"@webiny/api-file-manager\";\nimport { createRegisterExtensionPlugin } from \"@webiny/handler\";\nimport type { AssetDeliveryParams } from \"~/assetDelivery/types.js\";\nimport { createLocalAssetDeliveryFeature } from \"~/assetDelivery/feature.js\";\n\nexport const assetDeliveryConfig = (params: AssetDeliveryParams) => {\n const feature = createLocalAssetDeliveryFeature(params);\n\n return [\n createBaseAssetDelivery(),\n createRegisterExtensionPlugin(context => {\n feature.register(context.container);\n })\n ];\n};\n"],"names":["assetDeliveryConfig","params","feature","createLocalAssetDeliveryFeature","createBaseAssetDelivery","createRegisterExtensionPlugin","context"],"mappings":";;;AAKO,MAAMA,sBAAsB,CAACC;IAChC,MAAMC,UAAUC,gCAAgCF;IAEhD,OAAO;QACHG;QACAC,8BAA8BC,CAAAA;YAC1BJ,QAAQ,QAAQ,CAACI,QAAQ,SAAS;QACtC;KACH;AACL"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createAssetDeliveryPluginLoader } from "@webiny/api-file-manager/exports/api/file-manager/assetDelivery.js";
|
|
2
|
+
const createAssetDelivery = (params = {})=>[
|
|
3
|
+
createAssetDeliveryPluginLoader(()=>import("./assetDeliveryConfig.js").then(({ assetDeliveryConfig })=>assetDeliveryConfig(params)))
|
|
4
|
+
];
|
|
5
|
+
export { createAssetDelivery };
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=createAssetDelivery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assetDelivery/createAssetDelivery.js","sources":["../../src/assetDelivery/createAssetDelivery.ts"],"sourcesContent":["import { createAssetDeliveryPluginLoader } from \"@webiny/api-file-manager/exports/api/file-manager/assetDelivery.js\";\nimport type { PluginFactory } from \"@webiny/plugins/types.js\";\nimport type { AssetDeliveryParams } from \"~/assetDelivery/types.js\";\n\nexport const createAssetDelivery = (params: AssetDeliveryParams = {}): PluginFactory[] => {\n return [\n /*\n * We only want to load this plugin in the context of the Asset Delivery Lambda function.\n */\n createAssetDeliveryPluginLoader(() => {\n return import(\n /* webpackChunkName: \"localAssetDelivery\" */ \"./assetDeliveryConfig.js\"\n ).then(({ assetDeliveryConfig }) => assetDeliveryConfig(params));\n })\n ];\n};\n"],"names":["createAssetDelivery","params","createAssetDeliveryPluginLoader","assetDeliveryConfig"],"mappings":";AAIO,MAAMA,sBAAsB,CAACC,SAA8B,CAAC,CAAC,GACzD;QAIHC,gCAAgC,IACrB,MAAM,CAAN,4BAEL,IAAI,CAAC,CAAC,EAAEC,mBAAmB,EAAE,GAAKA,oBAAoBF;KAE/D"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { LocalAssetDeliveryConfig, LocalStoragePath } from "./abstractions.js";
|
|
3
|
+
import { LocalAssetResolverImpl } from "./LocalAssetResolver.js";
|
|
4
|
+
import { LocalOutputStrategyImpl } from "./LocalOutputStrategy.js";
|
|
5
|
+
import { LocalSharpTransformImpl } from "./LocalSharpTransform.js";
|
|
6
|
+
const createLocalAssetDeliveryFeature = (params = {})=>createFeature({
|
|
7
|
+
name: "AssetDelivery/Local",
|
|
8
|
+
register (container) {
|
|
9
|
+
container.registerInstance(LocalStoragePath, process.env.WEBINY_LOCAL_STORAGE_PATH);
|
|
10
|
+
container.registerInstance(LocalAssetDeliveryConfig, {
|
|
11
|
+
imageResizeWidths: params.imageResizeWidths ?? [
|
|
12
|
+
128,
|
|
13
|
+
384,
|
|
14
|
+
640,
|
|
15
|
+
750,
|
|
16
|
+
828,
|
|
17
|
+
1080,
|
|
18
|
+
1200,
|
|
19
|
+
1920,
|
|
20
|
+
2048,
|
|
21
|
+
3840
|
|
22
|
+
],
|
|
23
|
+
imageQuality: params.imageQuality ?? {},
|
|
24
|
+
assetStreamingMaxSize: params.assetStreamingMaxSize ?? 4718592
|
|
25
|
+
});
|
|
26
|
+
container.register(LocalAssetResolverImpl);
|
|
27
|
+
container.register(LocalOutputStrategyImpl);
|
|
28
|
+
container.register(LocalSharpTransformImpl).inSingletonScope();
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
export { createLocalAssetDeliveryFeature };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assetDelivery/feature.js","sources":["../../src/assetDelivery/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { LocalStoragePath } from \"./abstractions.js\";\nimport { LocalAssetDeliveryConfig } from \"./abstractions.js\";\nimport type { AssetDeliveryParams } from \"./types.js\";\nimport { LocalAssetResolverImpl } from \"./LocalAssetResolver.js\";\nimport { LocalOutputStrategyImpl } from \"./LocalOutputStrategy.js\";\nimport { LocalSharpTransformImpl } from \"./LocalSharpTransform.js\";\n\nexport const createLocalAssetDeliveryFeature = (params: AssetDeliveryParams = {}) => {\n return createFeature({\n name: \"AssetDelivery/Local\",\n register(container) {\n container.registerInstance(\n LocalStoragePath,\n process.env.WEBINY_LOCAL_STORAGE_PATH as string\n );\n container.registerInstance(LocalAssetDeliveryConfig, {\n imageResizeWidths: params.imageResizeWidths ?? [\n 128, 384, 640, 750, 828, 1080, 1200, 1920, 2048, 3840\n ],\n imageQuality: params.imageQuality ?? {},\n assetStreamingMaxSize: params.assetStreamingMaxSize ?? 4718592\n });\n\n container.register(LocalAssetResolverImpl);\n container.register(LocalOutputStrategyImpl);\n container.register(LocalSharpTransformImpl).inSingletonScope();\n }\n });\n};\n"],"names":["createLocalAssetDeliveryFeature","params","createFeature","container","LocalStoragePath","process","LocalAssetDeliveryConfig","LocalAssetResolverImpl","LocalOutputStrategyImpl","LocalSharpTransformImpl"],"mappings":";;;;;AAQO,MAAMA,kCAAkC,CAACC,SAA8B,CAAC,CAAC,GACrEC,cAAc;QACjB,MAAM;QACN,UAASC,SAAS;YACdA,UAAU,gBAAgB,CACtBC,kBACAC,QAAQ,GAAG,CAAC,yBAAyB;YAEzCF,UAAU,gBAAgB,CAACG,0BAA0B;gBACjD,mBAAmBL,OAAO,iBAAiB,IAAI;oBAC3C;oBAAK;oBAAK;oBAAK;oBAAK;oBAAK;oBAAM;oBAAM;oBAAM;oBAAM;iBACpD;gBACD,cAAcA,OAAO,YAAY,IAAI,CAAC;gBACtC,uBAAuBA,OAAO,qBAAqB,IAAI;YAC3D;YAEAE,UAAU,QAAQ,CAACI;YACnBJ,UAAU,QAAQ,CAACK;YACnBL,UAAU,QAAQ,CAACM,yBAAyB,gBAAgB;QAChE;IACJ"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ImageFormat } from "@webiny/api-file-manager/features/assetDelivery/transformation/index.js";
|
|
2
|
+
export type AssetDeliveryParams = {
|
|
3
|
+
imageResizeWidths?: number[];
|
|
4
|
+
/** Per-format encoder quality (1-100). Merged over the built-in defaults. */
|
|
5
|
+
imageQuality?: Partial<Record<ImageFormat, number>>;
|
|
6
|
+
presignedUrlTtl?: number;
|
|
7
|
+
assetStreamingMaxSize?: number;
|
|
8
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
2
|
+
export interface CleanupStaleMultipartUploadsInput {
|
|
3
|
+
noop?: boolean;
|
|
4
|
+
}
|
|
5
|
+
declare class CleanupStaleMultipartUploadsTaskImpl implements TaskDefinition.Interface<CleanupStaleMultipartUploadsInput> {
|
|
6
|
+
readonly id = "fileManagerCleanupStaleMultipartUploads";
|
|
7
|
+
readonly title = "Clean up stale multipart upload directories";
|
|
8
|
+
readonly description = "Removes multipart upload directories that are older than 24 hours.";
|
|
9
|
+
readonly maxIterations = 1;
|
|
10
|
+
readonly isPrivate = true;
|
|
11
|
+
readonly databaseLogs = false;
|
|
12
|
+
readonly selfCleanup: ("onAbort" | "onSuccess")[];
|
|
13
|
+
run({ controller }: TaskDefinition.RunParams<CleanupStaleMultipartUploadsInput>): Promise<TaskDefinition.Result<CleanupStaleMultipartUploadsInput>>;
|
|
14
|
+
}
|
|
15
|
+
export declare const CleanupStaleMultipartUploadsTaskDefinition: typeof CleanupStaleMultipartUploadsTaskImpl & {
|
|
16
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskDefinition<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskInput, import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskOutput>>;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { promises } from "node:fs";
|
|
2
|
+
import node_path from "node:path";
|
|
3
|
+
import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
4
|
+
const STALE_THRESHOLD_MS = 86400000;
|
|
5
|
+
async function readdirSafe(dirPath) {
|
|
6
|
+
try {
|
|
7
|
+
return await promises.readdir(dirPath);
|
|
8
|
+
} catch (err) {
|
|
9
|
+
if ("ENOENT" === err.code) return [];
|
|
10
|
+
throw err;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
class CleanupStaleMultipartUploadsTaskImpl {
|
|
14
|
+
async run({ controller }) {
|
|
15
|
+
if (controller.runtime.isAborted()) return controller.response.aborted();
|
|
16
|
+
const storagePath = String(process.env.WEBINY_LOCAL_STORAGE_PATH);
|
|
17
|
+
const tenantsDir = node_path.join(storagePath, "tenants");
|
|
18
|
+
const now = Date.now();
|
|
19
|
+
const tenantDirs = await readdirSafe(tenantsDir);
|
|
20
|
+
for (const tenantId of tenantDirs){
|
|
21
|
+
const multipartDir = node_path.join(tenantsDir, tenantId, "multipart");
|
|
22
|
+
const uploadDirs = await readdirSafe(multipartDir);
|
|
23
|
+
for (const uploadId of uploadDirs){
|
|
24
|
+
const uploadPath = node_path.join(multipartDir, uploadId);
|
|
25
|
+
try {
|
|
26
|
+
const stat = await promises.stat(uploadPath);
|
|
27
|
+
const ageMs = now - stat.mtimeMs;
|
|
28
|
+
if (ageMs > STALE_THRESHOLD_MS) await promises.rm(uploadPath, {
|
|
29
|
+
recursive: true,
|
|
30
|
+
force: true
|
|
31
|
+
});
|
|
32
|
+
} catch (err) {
|
|
33
|
+
if ("ENOENT" !== err.code) throw err;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return controller.response.done();
|
|
38
|
+
}
|
|
39
|
+
constructor(){
|
|
40
|
+
this.id = "fileManagerCleanupStaleMultipartUploads";
|
|
41
|
+
this.title = "Clean up stale multipart upload directories";
|
|
42
|
+
this.description = "Removes multipart upload directories that are older than 24 hours.";
|
|
43
|
+
this.maxIterations = 1;
|
|
44
|
+
this.isPrivate = true;
|
|
45
|
+
this.databaseLogs = false;
|
|
46
|
+
this.selfCleanup = [
|
|
47
|
+
"onSuccess",
|
|
48
|
+
"onAbort"
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const CleanupStaleMultipartUploadsTaskDefinition = TaskDefinition.createImplementation({
|
|
53
|
+
implementation: CleanupStaleMultipartUploadsTaskImpl,
|
|
54
|
+
dependencies: []
|
|
55
|
+
});
|
|
56
|
+
export { CleanupStaleMultipartUploadsTaskDefinition };
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=CleanupStaleMultipartUploadsTask.js.map
|