@vendure/asset-server-plugin 2.0.0-next.2 → 2.0.0-next.20
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/lib/src/common.d.ts +2 -1
- package/lib/src/common.js +22 -2
- package/lib/src/common.js.map +1 -1
- package/lib/src/plugin.d.ts +16 -0
- package/lib/src/plugin.js +43 -15
- package/lib/src/plugin.js.map +1 -1
- package/lib/src/s3-asset-storage-strategy.d.ts +10 -0
- package/lib/src/s3-asset-storage-strategy.js +10 -0
- package/lib/src/s3-asset-storage-strategy.js.map +1 -1
- package/lib/src/sharp-asset-preview-strategy.d.ts +92 -5
- package/lib/src/sharp-asset-preview-strategy.js +77 -19
- package/lib/src/sharp-asset-preview-strategy.js.map +1 -1
- package/lib/src/transform-image.js +18 -0
- package/lib/src/transform-image.js.map +1 -1
- package/lib/src/types.d.ts +12 -1
- package/package.json +6 -6
package/lib/src/common.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { Request } from 'express';
|
|
2
|
-
import { AssetServerOptions } from './types';
|
|
2
|
+
import { AssetServerOptions, ImageTransformFormat } from './types';
|
|
3
3
|
export declare function getAssetUrlPrefixFn(options: AssetServerOptions): ((request: Request, identifier: string) => string) | ((...args: any[]) => string);
|
|
4
|
+
export declare function getValidFormat(format?: unknown): ImageTransformFormat | undefined;
|
package/lib/src/common.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAssetUrlPrefixFn = void 0;
|
|
3
|
+
exports.getValidFormat = exports.getAssetUrlPrefixFn = void 0;
|
|
4
4
|
const constants_1 = require("@vendure/core/dist/common/constants");
|
|
5
5
|
function getAssetUrlPrefixFn(options) {
|
|
6
6
|
const { assetUrlPrefix, route } = options;
|
|
7
7
|
if (assetUrlPrefix == null) {
|
|
8
|
-
return (request, identifier) =>
|
|
8
|
+
return (request, identifier) => {
|
|
9
|
+
var _a;
|
|
10
|
+
const protocol = (_a = request.headers['x-forwarded-proto']) !== null && _a !== void 0 ? _a : request.protocol;
|
|
11
|
+
return `${protocol}://${request.get('host')}/${route}/`;
|
|
12
|
+
};
|
|
9
13
|
}
|
|
10
14
|
if (typeof assetUrlPrefix === 'string') {
|
|
11
15
|
return (...args) => assetUrlPrefix;
|
|
@@ -19,4 +23,20 @@ function getAssetUrlPrefixFn(options) {
|
|
|
19
23
|
throw new Error(`The assetUrlPrefix option was of an unexpected type: ${JSON.stringify(assetUrlPrefix)}`);
|
|
20
24
|
}
|
|
21
25
|
exports.getAssetUrlPrefixFn = getAssetUrlPrefixFn;
|
|
26
|
+
function getValidFormat(format) {
|
|
27
|
+
if (typeof format !== 'string') {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
switch (format) {
|
|
31
|
+
case 'jpg':
|
|
32
|
+
case 'jpeg':
|
|
33
|
+
case 'png':
|
|
34
|
+
case 'webp':
|
|
35
|
+
case 'avif':
|
|
36
|
+
return format;
|
|
37
|
+
default:
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.getValidFormat = getValidFormat;
|
|
22
42
|
//# sourceMappingURL=common.js.map
|
package/lib/src/common.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/common.ts"],"names":[],"mappings":";;;AAAA,mEAA0E;AAK1E,SAAgB,mBAAmB,CAAC,OAA2B;IAC3D,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;IAC1C,IAAI,cAAc,IAAI,IAAI,EAAE;QACxB,OAAO,CAAC,OAAgB,EAAE,UAAkB,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/common.ts"],"names":[],"mappings":";;;AAAA,mEAA0E;AAK1E,SAAgB,mBAAmB,CAAC,OAA2B;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59
59
|
*
|
|
60
60
|
* `http://localhost:3000/assets/landscape.jpg?w=150&h=150&mode=crop&fpx=0.2&fpy=0.7`
|
|
61
61
|
*
|
|
62
|
+
* ### Format
|
|
63
|
+
*
|
|
64
|
+
* Since v1.7.0, the image format can be specified by adding the `format` query parameter:
|
|
65
|
+
*
|
|
66
|
+
* `http://localhost:3000/assets/some-asset.jpg?format=webp`
|
|
67
|
+
*
|
|
68
|
+
* This means that, no matter the format of your original asset files, you can use more modern formats in your storefront if the browser
|
|
69
|
+
* supports them. Supported values for `format` are:
|
|
70
|
+
*
|
|
71
|
+
* * `jpeg` or `jpg`
|
|
72
|
+
* * `png`
|
|
73
|
+
* * `webp`
|
|
74
|
+
* * `avif`
|
|
75
|
+
*
|
|
76
|
+
* The `format` parameter can also be combined with presets (see below).
|
|
77
|
+
*
|
|
62
78
|
* ### Transform presets
|
|
63
79
|
*
|
|
64
80
|
* Presets can be defined which allow a single preset name to be used instead of specifying the width, height and mode. Presets are
|
package/lib/src/plugin.js
CHANGED
|
@@ -20,6 +20,7 @@ const express_1 = __importDefault(require("express"));
|
|
|
20
20
|
const file_type_1 = require("file-type");
|
|
21
21
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
22
22
|
const path_1 = __importDefault(require("path"));
|
|
23
|
+
const common_1 = require("./common");
|
|
23
24
|
const constants_1 = require("./constants");
|
|
24
25
|
const default_asset_storage_strategy_factory_1 = require("./default-asset-storage-strategy-factory");
|
|
25
26
|
const hashed_asset_naming_strategy_1 = require("./hashed-asset-naming-strategy");
|
|
@@ -82,6 +83,22 @@ const transform_image_1 = require("./transform-image");
|
|
|
82
83
|
*
|
|
83
84
|
* `http://localhost:3000/assets/landscape.jpg?w=150&h=150&mode=crop&fpx=0.2&fpy=0.7`
|
|
84
85
|
*
|
|
86
|
+
* ### Format
|
|
87
|
+
*
|
|
88
|
+
* Since v1.7.0, the image format can be specified by adding the `format` query parameter:
|
|
89
|
+
*
|
|
90
|
+
* `http://localhost:3000/assets/some-asset.jpg?format=webp`
|
|
91
|
+
*
|
|
92
|
+
* This means that, no matter the format of your original asset files, you can use more modern formats in your storefront if the browser
|
|
93
|
+
* supports them. Supported values for `format` are:
|
|
94
|
+
*
|
|
95
|
+
* * `jpeg` or `jpg`
|
|
96
|
+
* * `png`
|
|
97
|
+
* * `webp`
|
|
98
|
+
* * `avif`
|
|
99
|
+
*
|
|
100
|
+
* The `format` parameter can also be combined with presets (see below).
|
|
101
|
+
*
|
|
85
102
|
* ### Transform presets
|
|
86
103
|
*
|
|
87
104
|
* Presets can be defined which allow a single preset name to be used instead of specifying the width, height and mode. Presets are
|
|
@@ -144,12 +161,14 @@ let AssetServerPlugin = AssetServerPlugin_1 = class AssetServerPlugin {
|
|
|
144
161
|
}
|
|
145
162
|
/** @internal */
|
|
146
163
|
static async configure(config) {
|
|
164
|
+
var _a;
|
|
147
165
|
const storageStrategyFactory = this.options.storageStrategyFactory || default_asset_storage_strategy_factory_1.defaultAssetStorageStrategyFactory;
|
|
148
166
|
this.assetStorage = await storageStrategyFactory(this.options);
|
|
149
|
-
config.assetOptions.assetPreviewStrategy =
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
167
|
+
config.assetOptions.assetPreviewStrategy =
|
|
168
|
+
(_a = this.options.previewStrategy) !== null && _a !== void 0 ? _a : new sharp_asset_preview_strategy_1.SharpAssetPreviewStrategy({
|
|
169
|
+
maxWidth: this.options.previewMaxWidth,
|
|
170
|
+
maxHeight: this.options.previewMaxHeight,
|
|
171
|
+
});
|
|
153
172
|
config.assetOptions.assetStorageStrategy = this.assetStorage;
|
|
154
173
|
config.assetOptions.assetNamingStrategy =
|
|
155
174
|
this.options.namingStrategy || new hashed_asset_naming_strategy_1.HashedAssetNamingStrategy();
|
|
@@ -204,6 +223,7 @@ let AssetServerPlugin = AssetServerPlugin_1 = class AssetServerPlugin {
|
|
|
204
223
|
mimeType = ((_a = (await (0, file_type_1.fromBuffer)(file))) === null || _a === void 0 ? void 0 : _a.mime) || 'application/octet-stream';
|
|
205
224
|
}
|
|
206
225
|
res.contentType(mimeType);
|
|
226
|
+
res.setHeader('content-security-policy', `default-src 'self'`);
|
|
207
227
|
res.send(file);
|
|
208
228
|
}
|
|
209
229
|
catch (e) {
|
|
@@ -220,6 +240,7 @@ let AssetServerPlugin = AssetServerPlugin_1 = class AssetServerPlugin {
|
|
|
220
240
|
*/
|
|
221
241
|
generateTransformedImage() {
|
|
222
242
|
return async (err, req, res, next) => {
|
|
243
|
+
var _a;
|
|
223
244
|
if (err && (err.status === 404 || err.statusCode === 404)) {
|
|
224
245
|
if (req.query) {
|
|
225
246
|
const decodedReqPath = decodeURIComponent(req.path);
|
|
@@ -235,17 +256,22 @@ let AssetServerPlugin = AssetServerPlugin_1 = class AssetServerPlugin {
|
|
|
235
256
|
const image = await (0, transform_image_1.transformImage)(file, req.query, this.presets || []);
|
|
236
257
|
try {
|
|
237
258
|
const imageBuffer = await image.toBuffer();
|
|
259
|
+
const cachedFileName = this.getFileNameFromRequest(req);
|
|
238
260
|
if (!req.query.cache || req.query.cache === 'true') {
|
|
239
|
-
const cachedFileName = this.getFileNameFromRequest(req);
|
|
240
261
|
await AssetServerPlugin_1.assetStorage.writeFileFromBuffer(cachedFileName, imageBuffer);
|
|
241
262
|
core_1.Logger.debug(`Saved cached asset: ${cachedFileName}`, constants_1.loggerCtx);
|
|
242
263
|
}
|
|
243
|
-
|
|
264
|
+
let mimeType = this.getMimeType(cachedFileName);
|
|
265
|
+
if (!mimeType) {
|
|
266
|
+
mimeType = ((_a = (await (0, file_type_1.fromBuffer)(imageBuffer))) === null || _a === void 0 ? void 0 : _a.mime) || 'image/jpeg';
|
|
267
|
+
}
|
|
268
|
+
res.set('Content-Type', mimeType);
|
|
269
|
+
res.setHeader('content-security-policy', `default-src 'self'`);
|
|
244
270
|
res.send(imageBuffer);
|
|
245
271
|
return;
|
|
246
272
|
}
|
|
247
273
|
catch (e) {
|
|
248
|
-
core_1.Logger.error(e,
|
|
274
|
+
core_1.Logger.error(e, constants_1.loggerCtx, e.stack);
|
|
249
275
|
res.status(500).send(e.message);
|
|
250
276
|
return;
|
|
251
277
|
}
|
|
@@ -255,22 +281,23 @@ let AssetServerPlugin = AssetServerPlugin_1 = class AssetServerPlugin {
|
|
|
255
281
|
};
|
|
256
282
|
}
|
|
257
283
|
getFileNameFromRequest(req) {
|
|
258
|
-
const { w, h, mode, preset, fpx, fpy } = req.query;
|
|
284
|
+
const { w, h, mode, preset, fpx, fpy, format } = req.query;
|
|
259
285
|
const focalPoint = fpx && fpy ? `_fpx${fpx}_fpy${fpy}` : '';
|
|
286
|
+
const imageFormat = (0, common_1.getValidFormat)(format);
|
|
260
287
|
let imageParamHash = null;
|
|
261
288
|
if (w || h) {
|
|
262
289
|
const width = w || '';
|
|
263
290
|
const height = h || '';
|
|
264
|
-
imageParamHash = this.md5(`_transform_w${width}_h${height}_m${mode}${focalPoint}`);
|
|
291
|
+
imageParamHash = this.md5(`_transform_w${width}_h${height}_m${mode}${focalPoint}${imageFormat}`);
|
|
265
292
|
}
|
|
266
293
|
else if (preset) {
|
|
267
294
|
if (this.presets && !!this.presets.find(p => p.name === preset)) {
|
|
268
|
-
imageParamHash = this.md5(`_transform_pre_${preset}${focalPoint}`);
|
|
295
|
+
imageParamHash = this.md5(`_transform_pre_${preset}${focalPoint}${imageFormat}`);
|
|
269
296
|
}
|
|
270
297
|
}
|
|
271
298
|
const decodedReqPath = decodeURIComponent(req.path);
|
|
272
299
|
if (imageParamHash) {
|
|
273
|
-
return path_1.default.join(this.cacheDir, this.addSuffix(decodedReqPath, imageParamHash));
|
|
300
|
+
return path_1.default.join(this.cacheDir, this.addSuffix(decodedReqPath, imageParamHash, imageFormat));
|
|
274
301
|
}
|
|
275
302
|
else {
|
|
276
303
|
return decodedReqPath;
|
|
@@ -279,11 +306,12 @@ let AssetServerPlugin = AssetServerPlugin_1 = class AssetServerPlugin {
|
|
|
279
306
|
md5(input) {
|
|
280
307
|
return (0, crypto_1.createHash)('md5').update(input).digest('hex');
|
|
281
308
|
}
|
|
282
|
-
addSuffix(fileName, suffix) {
|
|
283
|
-
const
|
|
284
|
-
const
|
|
309
|
+
addSuffix(fileName, suffix, ext) {
|
|
310
|
+
const originalExt = path_1.default.extname(fileName);
|
|
311
|
+
const effectiveExt = ext ? `.${ext}` : originalExt;
|
|
312
|
+
const baseName = path_1.default.basename(fileName, originalExt);
|
|
285
313
|
const dirName = path_1.default.dirname(fileName);
|
|
286
|
-
return path_1.default.join(dirName, `${baseName}${suffix}${
|
|
314
|
+
return path_1.default.join(dirName, `${baseName}${suffix}${effectiveExt}`);
|
|
287
315
|
}
|
|
288
316
|
/**
|
|
289
317
|
* Attempt to get the mime type from the file name.
|
package/lib/src/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAEA,wCAQuB;AACvB,mCAAoC;AACpC,sDAAmE;AACnE,yCAAuC;AACvC,wDAA0B;AAC1B,gDAAwB;AAExB,2CAAwC;AACxC,qGAA8F;AAC9F,iFAA2E;AAC3E,iFAA2E;AAC3E,uDAAmD;AAGnD
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAEA,wCAQuB;AACvB,mCAAoC;AACpC,sDAAmE;AACnE,yCAAuC;AACvC,wDAA0B;AAC1B,gDAAwB;AAExB,qCAA0C;AAC1C,2CAAwC;AACxC,qGAA8F;AAC9F,iFAA2E;AAC3E,iFAA2E;AAC3E,uDAAmD;AAGnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgHG;AAKH,IAAa,iBAAiB,yBAA9B,MAAa,iBAAiB;IAsC1B,YAAoB,c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E,CAAC,CAAC;IACrE,CAAC;IAED;;OAEG;IACK,WAAW,CAAC,QAAgB;QAChC,MAAM,GAAG,GAAG,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACnC,QAAQ,GAAG,EAAE;YACT,KAAK,MAAM,CAAC;YACZ,KAAK,OAAO;gBACR,OAAO,YAAY,CAAC;YACxB,KAAK,MAAM;gBACP,OAAO,WAAW,CAAC;YACvB,KAAK,MAAM;gBACP,OAAO,WAAW,CAAC;YACvB,KAAK,MAAM;gBACP,OAAO,eAAe,CAAC;YAC3B,KAAK,OAAO;gBACR,OAAO,YAAY,CAAC;YACxB,KAAK,OAAO;gBACR,OAAO,YAAY,CAAC;SAC3B;IACL,CAAC;CACJ,CAAA;AA7MY,iBAAiB;IAJ7B,IAAA,oBAAa,EAAC;QACX,OAAO,EAAE,CAAC,yBAAkB,CAAC;QAC7B,aAAa,EAAE,MAAM,CAAC,EAAE,CAAC,mBAAiB,CAAC,SAAS,CAAC,MAAM,CAAC;KAC/D,CAAC;qCAuCsC,qBAAc;GAtCzC,iBAAiB,CA6M7B;AA7MY,8CAAiB"}
|
|
@@ -59,6 +59,11 @@ export interface S3Config {
|
|
|
59
59
|
*
|
|
60
60
|
* @example
|
|
61
61
|
* ```TypeScript
|
|
62
|
+
* import { AssetServerPlugin, configureS3AssetStorage } from '\@vendure/asset-server-plugin';
|
|
63
|
+
* import { DefaultAssetNamingStrategy } from '\@vendure/core';
|
|
64
|
+
*
|
|
65
|
+
* // ...
|
|
66
|
+
*
|
|
62
67
|
* plugins: [
|
|
63
68
|
* AssetServerPlugin.init({
|
|
64
69
|
* route: 'assets',
|
|
@@ -81,6 +86,11 @@ export interface S3Config {
|
|
|
81
86
|
*
|
|
82
87
|
* @example
|
|
83
88
|
* ```TypeScript
|
|
89
|
+
* import { AssetServerPlugin, configureS3AssetStorage } from '\@vendure/asset-server-plugin';
|
|
90
|
+
* import { DefaultAssetNamingStrategy } from '\@vendure/core';
|
|
91
|
+
*
|
|
92
|
+
* // ...
|
|
93
|
+
*
|
|
84
94
|
* plugins: [
|
|
85
95
|
* AssetServerPlugin.init({
|
|
86
96
|
* route: 'assets',
|
|
@@ -38,6 +38,11 @@ const constants_1 = require("./constants");
|
|
|
38
38
|
*
|
|
39
39
|
* @example
|
|
40
40
|
* ```TypeScript
|
|
41
|
+
* import { AssetServerPlugin, configureS3AssetStorage } from '\@vendure/asset-server-plugin';
|
|
42
|
+
* import { DefaultAssetNamingStrategy } from '\@vendure/core';
|
|
43
|
+
*
|
|
44
|
+
* // ...
|
|
45
|
+
*
|
|
41
46
|
* plugins: [
|
|
42
47
|
* AssetServerPlugin.init({
|
|
43
48
|
* route: 'assets',
|
|
@@ -60,6 +65,11 @@ const constants_1 = require("./constants");
|
|
|
60
65
|
*
|
|
61
66
|
* @example
|
|
62
67
|
* ```TypeScript
|
|
68
|
+
* import { AssetServerPlugin, configureS3AssetStorage } from '\@vendure/asset-server-plugin';
|
|
69
|
+
* import { DefaultAssetNamingStrategy } from '\@vendure/core';
|
|
70
|
+
*
|
|
71
|
+
* // ...
|
|
72
|
+
*
|
|
63
73
|
* plugins: [
|
|
64
74
|
* AssetServerPlugin.init({
|
|
65
75
|
* route: 'assets',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"s3-asset-storage-strategy.js","sourceRoot":"","sources":["../../src/s3-asset-storage-strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,wCAA6D;AAE7D,2CAA6B;AAC7B,mCAA0C;AAE1C,qCAA+C;AAC/C,2CAAwC;AAiDxC
|
|
1
|
+
{"version":3,"file":"s3-asset-storage-strategy.js","sourceRoot":"","sources":["../../src/s3-asset-storage-strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,wCAA6D;AAE7D,2CAA6B;AAC7B,mCAA0C;AAE1C,qCAA+C;AAC/C,2CAAwC;AAiDxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;YACrE,YAAY,GAAG,IAAI,CAAC;YACpB,aAAM,CAAC,OAAO,CAAC,oBAAoB,MAAM,GAAG,EAAE,qBAAS,CAAC,CAAC;SAC5D;QAAC,OAAO,CAAM,EAAE;YACb,aAAM,CAAC,OAAO,CAAC,0BAA0B,MAAM,4BAA4B,CAAC,CAAC;SAChF;QACD,IAAI,CAAC,YAAY,EAAE;YACf,IAAI;gBACA,MAAM,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;gBACzE,aAAM,CAAC,OAAO,CAAC,sBAAsB,MAAM,GAAG,EAAE,qBAAS,CAAC,CAAC;aAC9D;YAAC,OAAO,CAAM,EAAE;gBACb,aAAM,CAAC,KAAK,CAAC,4CAA4C,MAAM,GAAG,EAAE,qBAAS,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;aAC3F;SACJ;IACL,CAAC;IAEO,oBAAoB,CACxB,WAAiD;QAEjD,OAAO,WAAW,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IACjD,CAAC;CACJ;AAzJD,wDAyJC"}
|
|
@@ -1,11 +1,98 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { AssetPreviewStrategy, RequestContext } from '@vendure/core';
|
|
3
|
+
import sharp from 'sharp';
|
|
4
|
+
/**
|
|
5
|
+
* @description
|
|
6
|
+
* This {@link AssetPreviewStrategy} uses the [Sharp library](https://sharp.pixelplumbing.com/) to generate
|
|
7
|
+
* preview images of uploaded binary files. For non-image binaries, a generic "file" icon with the mime type
|
|
8
|
+
* overlay will be generated.
|
|
9
|
+
*
|
|
10
|
+
* @docsCategory AssetServerPlugin
|
|
11
|
+
* @docsPage SharpAssetPreviewStrategy
|
|
12
|
+
*/
|
|
13
|
+
interface SharpAssetPreviewConfig {
|
|
14
|
+
/**
|
|
15
|
+
* @description
|
|
16
|
+
* The max height in pixels of a generated preview image.
|
|
17
|
+
*
|
|
18
|
+
* @default 1600
|
|
19
|
+
*/
|
|
20
|
+
maxHeight?: number;
|
|
21
|
+
/**
|
|
22
|
+
* @description
|
|
23
|
+
* The max width in pixels of a generated preview image.
|
|
24
|
+
*
|
|
25
|
+
* @default 1600
|
|
26
|
+
*/
|
|
27
|
+
maxWidth?: number;
|
|
28
|
+
/**
|
|
29
|
+
* @description
|
|
30
|
+
* Set Sharp's options for encoding jpeg files: https://sharp.pixelplumbing.com/api-output#jpeg
|
|
31
|
+
*
|
|
32
|
+
* @since 1.7.0
|
|
33
|
+
*/
|
|
34
|
+
jpegOptions?: sharp.JpegOptions;
|
|
35
|
+
/**
|
|
36
|
+
* @description
|
|
37
|
+
* Set Sharp's options for encoding png files: https://sharp.pixelplumbing.com/api-output#png
|
|
38
|
+
*
|
|
39
|
+
* @since 1.7.0
|
|
40
|
+
*/
|
|
41
|
+
pngOptions?: sharp.PngOptions;
|
|
42
|
+
/**
|
|
43
|
+
* @description
|
|
44
|
+
* Set Sharp's options for encoding webp files: https://sharp.pixelplumbing.com/api-output#webp
|
|
45
|
+
*
|
|
46
|
+
* @since 1.7.0
|
|
47
|
+
*/
|
|
48
|
+
webpOptions?: sharp.WebpOptions;
|
|
49
|
+
/**
|
|
50
|
+
* @description
|
|
51
|
+
* Set Sharp's options for encoding gif files: https://sharp.pixelplumbing.com/api-output#gif
|
|
52
|
+
*
|
|
53
|
+
* @since 1.7.0
|
|
54
|
+
*/
|
|
55
|
+
gifOptions?: sharp.GifOptions;
|
|
56
|
+
/**
|
|
57
|
+
* @description
|
|
58
|
+
* Set Sharp's options for encoding avif files: https://sharp.pixelplumbing.com/api-output#avif
|
|
59
|
+
*
|
|
60
|
+
* @since 1.7.0
|
|
61
|
+
*/
|
|
62
|
+
avifOptions?: sharp.AvifOptions;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* @description
|
|
66
|
+
* This {@link AssetPreviewStrategy} uses the [Sharp library](https://sharp.pixelplumbing.com/) to generate
|
|
67
|
+
* preview images of uploaded binary files. For non-image binaries, a generic "file" icon with the mime type
|
|
68
|
+
* overlay will be generated.
|
|
69
|
+
*
|
|
70
|
+
* By default, this strategy will produce previews up to maximum dimensions of 1600 x 1600 pixels. The created
|
|
71
|
+
* preview images will match the input format - so a source file in jpeg format will output a jpeg preview,
|
|
72
|
+
* a webp source file will output a webp preview, and so on.
|
|
73
|
+
*
|
|
74
|
+
* The settings for the outputs will default to Sharp's defaults (https://sharp.pixelplumbing.com/api-output).
|
|
75
|
+
* However, it is possible to pass your own configurations to control the output of each format:
|
|
76
|
+
*
|
|
77
|
+
* ```TypeScript
|
|
78
|
+
* AssetServerPlugin.init({
|
|
79
|
+
* previewStrategy: new SharpAssetPreviewStrategy({
|
|
80
|
+
* jpegOptions: { quality: 95 },
|
|
81
|
+
* webpOptions: { quality: 95 },
|
|
82
|
+
* }),
|
|
83
|
+
* }),
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @docsCategory AssetServerPlugin
|
|
87
|
+
* @docsPage SharpAssetPreviewStrategy
|
|
88
|
+
* @docsWeight 0
|
|
89
|
+
*/
|
|
3
90
|
export declare class SharpAssetPreviewStrategy implements AssetPreviewStrategy {
|
|
4
|
-
private
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
maxWidth: number;
|
|
8
|
-
});
|
|
91
|
+
private readonly defaultConfig;
|
|
92
|
+
private readonly config;
|
|
93
|
+
constructor(config?: SharpAssetPreviewConfig);
|
|
9
94
|
generatePreviewImage(ctx: RequestContext, mimeType: string, data: Buffer): Promise<Buffer>;
|
|
10
95
|
private generateMimeTypeOverlay;
|
|
96
|
+
private generateBinaryFilePreview;
|
|
11
97
|
}
|
|
98
|
+
export {};
|
|
@@ -8,41 +8,88 @@ const generated_types_1 = require("@vendure/common/lib/generated-types");
|
|
|
8
8
|
const core_1 = require("@vendure/core");
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
10
|
const sharp_1 = __importDefault(require("sharp"));
|
|
11
|
+
const constants_1 = require("./constants");
|
|
12
|
+
/**
|
|
13
|
+
* @description
|
|
14
|
+
* This {@link AssetPreviewStrategy} uses the [Sharp library](https://sharp.pixelplumbing.com/) to generate
|
|
15
|
+
* preview images of uploaded binary files. For non-image binaries, a generic "file" icon with the mime type
|
|
16
|
+
* overlay will be generated.
|
|
17
|
+
*
|
|
18
|
+
* By default, this strategy will produce previews up to maximum dimensions of 1600 x 1600 pixels. The created
|
|
19
|
+
* preview images will match the input format - so a source file in jpeg format will output a jpeg preview,
|
|
20
|
+
* a webp source file will output a webp preview, and so on.
|
|
21
|
+
*
|
|
22
|
+
* The settings for the outputs will default to Sharp's defaults (https://sharp.pixelplumbing.com/api-output).
|
|
23
|
+
* However, it is possible to pass your own configurations to control the output of each format:
|
|
24
|
+
*
|
|
25
|
+
* ```TypeScript
|
|
26
|
+
* AssetServerPlugin.init({
|
|
27
|
+
* previewStrategy: new SharpAssetPreviewStrategy({
|
|
28
|
+
* jpegOptions: { quality: 95 },
|
|
29
|
+
* webpOptions: { quality: 95 },
|
|
30
|
+
* }),
|
|
31
|
+
* }),
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @docsCategory AssetServerPlugin
|
|
35
|
+
* @docsPage SharpAssetPreviewStrategy
|
|
36
|
+
* @docsWeight 0
|
|
37
|
+
*/
|
|
11
38
|
class SharpAssetPreviewStrategy {
|
|
12
39
|
constructor(config) {
|
|
13
|
-
this.
|
|
40
|
+
this.defaultConfig = {
|
|
41
|
+
maxHeight: 1600,
|
|
42
|
+
maxWidth: 1600,
|
|
43
|
+
jpegOptions: {},
|
|
44
|
+
pngOptions: {},
|
|
45
|
+
webpOptions: {},
|
|
46
|
+
gifOptions: {},
|
|
47
|
+
avifOptions: {},
|
|
48
|
+
};
|
|
49
|
+
this.config = Object.assign(Object.assign({}, this.defaultConfig), (config !== null && config !== void 0 ? config : {}));
|
|
14
50
|
}
|
|
15
51
|
async generatePreviewImage(ctx, mimeType, data) {
|
|
52
|
+
var _a;
|
|
16
53
|
const assetType = (0, core_1.getAssetType)(mimeType);
|
|
17
54
|
const { maxWidth, maxHeight } = this.config;
|
|
18
55
|
if (assetType === generated_types_1.AssetType.IMAGE) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
56
|
+
try {
|
|
57
|
+
const image = (0, sharp_1.default)(data).rotate();
|
|
58
|
+
const metadata = await image.metadata();
|
|
59
|
+
const width = metadata.width || 0;
|
|
60
|
+
const height = metadata.height || 0;
|
|
61
|
+
if (maxWidth < width || maxHeight < height) {
|
|
62
|
+
image.resize(maxWidth, maxHeight, { fit: 'inside' });
|
|
63
|
+
}
|
|
27
64
|
if (mimeType === 'image/svg+xml') {
|
|
28
65
|
// Convert the SVG to a raster for the preview
|
|
29
66
|
return image.toBuffer();
|
|
30
67
|
}
|
|
31
68
|
else {
|
|
32
|
-
|
|
69
|
+
switch (metadata.format) {
|
|
70
|
+
case 'jpeg':
|
|
71
|
+
case 'jpg':
|
|
72
|
+
return image.jpeg(this.config.jpegOptions).toBuffer();
|
|
73
|
+
case 'png':
|
|
74
|
+
return image.png(this.config.pngOptions).toBuffer();
|
|
75
|
+
case 'webp':
|
|
76
|
+
return image.webp(this.config.webpOptions).toBuffer();
|
|
77
|
+
case 'gif':
|
|
78
|
+
return image.gif(this.config.jpegOptions).toBuffer();
|
|
79
|
+
case 'avif':
|
|
80
|
+
return image.avif(this.config.avifOptions).toBuffer();
|
|
81
|
+
default:
|
|
82
|
+
return image.toBuffer();
|
|
83
|
+
}
|
|
33
84
|
}
|
|
34
85
|
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
core_1.Logger.error(`An error occurred when generating preview for image with mimeType ${mimeType}: ${(_a = err.message) !== null && _a !== void 0 ? _a : err.toString()}`, constants_1.loggerCtx);
|
|
88
|
+
return this.generateBinaryFilePreview(mimeType);
|
|
89
|
+
}
|
|
35
90
|
}
|
|
36
91
|
else {
|
|
37
|
-
return
|
|
38
|
-
.resize(800, 800, { fit: 'outside' })
|
|
39
|
-
.composite([
|
|
40
|
-
{
|
|
41
|
-
input: this.generateMimeTypeOverlay(mimeType),
|
|
42
|
-
gravity: sharp_1.default.gravity.center,
|
|
43
|
-
},
|
|
44
|
-
])
|
|
45
|
-
.toBuffer();
|
|
92
|
+
return this.generateBinaryFilePreview(mimeType);
|
|
46
93
|
}
|
|
47
94
|
}
|
|
48
95
|
generateMimeTypeOverlay(mimeType) {
|
|
@@ -59,6 +106,17 @@ class SharpAssetPreviewStrategy {
|
|
|
59
106
|
<text x="400" y="110" text-anchor="middle" width="800">${mimeType}</text>
|
|
60
107
|
</svg>`);
|
|
61
108
|
}
|
|
109
|
+
generateBinaryFilePreview(mimeType) {
|
|
110
|
+
return (0, sharp_1.default)(path_1.default.join(__dirname, 'file-icon.png'))
|
|
111
|
+
.resize(800, 800, { fit: 'outside' })
|
|
112
|
+
.composite([
|
|
113
|
+
{
|
|
114
|
+
input: this.generateMimeTypeOverlay(mimeType),
|
|
115
|
+
gravity: sharp_1.default.gravity.center,
|
|
116
|
+
},
|
|
117
|
+
])
|
|
118
|
+
.toBuffer();
|
|
119
|
+
}
|
|
62
120
|
}
|
|
63
121
|
exports.SharpAssetPreviewStrategy = SharpAssetPreviewStrategy;
|
|
64
122
|
//# sourceMappingURL=sharp-asset-preview-strategy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sharp-asset-preview-strategy.js","sourceRoot":"","sources":["../../src/sharp-asset-preview-strategy.ts"],"names":[],"mappings":";;;;;;AAAA,yEAAgE;AAChE,
|
|
1
|
+
{"version":3,"file":"sharp-asset-preview-strategy.js","sourceRoot":"","sources":["../../src/sharp-asset-preview-strategy.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D,CAAC,CAAC;IACjB,CAAC;IAEO,yBAAyB,CAAC,QAAgB;QAC9C,OAAO,IAAA,eAAK,EAAC,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;aAC9C,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC;aACpC,SAAS,CAAC;YACP;gBACI,KAAK,EAAE,IAAI,CAAC,uBAAuB,CAAC,QAAQ,CAAC;gBAC7C,OAAO,EAAE,eAAK,CAAC,OAAO,CAAC,MAAM;aAChC;SACJ,CAAC;aACD,QAAQ,EAAE,CAAC;IACpB,CAAC;CACJ;AA7FD,8DA6FC"}
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.resizeToFocalPoint = exports.transformImage = void 0;
|
|
7
7
|
const sharp_1 = __importDefault(require("sharp"));
|
|
8
|
+
const common_1 = require("./common");
|
|
8
9
|
/**
|
|
9
10
|
* Applies transforms to the given image according to the query params passed.
|
|
10
11
|
*/
|
|
@@ -14,6 +15,7 @@ async function transformImage(originalImage, queryParams, presets) {
|
|
|
14
15
|
let mode = queryParams.mode || 'crop';
|
|
15
16
|
const fpx = +queryParams.fpx || undefined;
|
|
16
17
|
const fpy = +queryParams.fpy || undefined;
|
|
18
|
+
const imageFormat = (0, common_1.getValidFormat)(queryParams.format);
|
|
17
19
|
if (queryParams.preset) {
|
|
18
20
|
const matchingPreset = presets.find(p => p.name === queryParams.preset);
|
|
19
21
|
if (matchingPreset) {
|
|
@@ -30,6 +32,7 @@ async function transformImage(originalImage, queryParams, presets) {
|
|
|
30
32
|
options.fit = 'inside';
|
|
31
33
|
}
|
|
32
34
|
const image = (0, sharp_1.default)(originalImage);
|
|
35
|
+
applyFormat(image, imageFormat);
|
|
33
36
|
if (fpx && fpy && targetWidth && targetHeight && mode === 'crop') {
|
|
34
37
|
const metadata = await image.metadata();
|
|
35
38
|
if (metadata.width && metadata.height) {
|
|
@@ -42,6 +45,21 @@ async function transformImage(originalImage, queryParams, presets) {
|
|
|
42
45
|
return image.resize(targetWidth, targetHeight, options);
|
|
43
46
|
}
|
|
44
47
|
exports.transformImage = transformImage;
|
|
48
|
+
function applyFormat(image, format) {
|
|
49
|
+
switch (format) {
|
|
50
|
+
case 'jpg':
|
|
51
|
+
case 'jpeg':
|
|
52
|
+
return image.jpeg();
|
|
53
|
+
case 'png':
|
|
54
|
+
return image.png();
|
|
55
|
+
case 'webp':
|
|
56
|
+
return image.webp();
|
|
57
|
+
case 'avif':
|
|
58
|
+
return image.avif();
|
|
59
|
+
default:
|
|
60
|
+
return image;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
45
63
|
/**
|
|
46
64
|
* Resize an image but keep it centered on the focal point.
|
|
47
65
|
* Based on the method outlined in https://github.com/lovell/sharp/issues/1198#issuecomment-384591756
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform-image.js","sourceRoot":"","sources":["../../src/transform-image.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAqD;
|
|
1
|
+
{"version":3,"file":"transform-image.js","sourceRoot":"","sources":["../../src/transform-image.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAqD;AAErD,qCAA0C;AAM1C;;GAEG;AACI,KAAK,UAAU,cAAc,CAChC,aAAqB,EACrB,WAAmC,EACnC,OAA+B;IAE/B,IAAI,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC;IAC1D,IAAI,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC;IAC3D,IAAI,IAAI,GAAG,WAAW,CAAC,IAAI,IAAI,MAAM,CAAC;IACtC,MAAM,GAAG,GAAG,CAAC,WAAW,CAAC,GAAG,IAAI,SAAS,CAAC;IAC1C,MAAM,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AAK,CAAC,UAAU,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;KAC5F;SAAM;QACH,MAAM,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;KAC3F;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,SAAS,KAAK,CAAC,GAAW,EAAE,GAAW,EAAE,KAAa;IAClD,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC;AAC/C,CAAC"}
|
package/lib/src/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { AssetNamingStrategy, AssetStorageStrategy, RequestContext } from '@vendure/core';
|
|
1
|
+
import { AssetNamingStrategy, AssetPreviewStrategy, AssetStorageStrategy, RequestContext } from '@vendure/core';
|
|
2
|
+
export declare type ImageTransformFormat = 'jpg' | 'jpeg' | 'png' | 'webp' | 'avif';
|
|
2
3
|
/**
|
|
3
4
|
* @description
|
|
4
5
|
* Specifies the way in which an asset preview image will be resized to fit in the
|
|
@@ -66,6 +67,7 @@ export interface AssetServerOptions {
|
|
|
66
67
|
* The max width in pixels of a generated preview image.
|
|
67
68
|
*
|
|
68
69
|
* @default 1600
|
|
70
|
+
* @deprecated Use `previewStrategy: new SharpAssetPreviewStrategy({ maxWidth })` instead
|
|
69
71
|
*/
|
|
70
72
|
previewMaxWidth?: number;
|
|
71
73
|
/**
|
|
@@ -73,6 +75,7 @@ export interface AssetServerOptions {
|
|
|
73
75
|
* The max height in pixels of a generated preview image.
|
|
74
76
|
*
|
|
75
77
|
* @default 1600
|
|
78
|
+
* @deprecated Use `previewStrategy: new SharpAssetPreviewStrategy({ maxHeight })` instead
|
|
76
79
|
*/
|
|
77
80
|
previewMaxHeight?: number;
|
|
78
81
|
/**
|
|
@@ -87,6 +90,14 @@ export interface AssetServerOptions {
|
|
|
87
90
|
* @default HashedAssetNamingStrategy
|
|
88
91
|
*/
|
|
89
92
|
namingStrategy?: AssetNamingStrategy;
|
|
93
|
+
/**
|
|
94
|
+
* @description
|
|
95
|
+
* Defines how previews are generated for a given Asset binary. By default, this uses
|
|
96
|
+
* the {@link SharpAssetPreviewStrategy}
|
|
97
|
+
*
|
|
98
|
+
* @since 1.7.0
|
|
99
|
+
*/
|
|
100
|
+
previewStrategy?: AssetPreviewStrategy;
|
|
90
101
|
/**
|
|
91
102
|
* @description
|
|
92
103
|
* A function which can be used to configure an {@link AssetStorageStrategy}. This is useful e.g. if you wish to store your assets
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vendure/asset-server-plugin",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.20",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"@types/express": "^4.17.8",
|
|
24
24
|
"@types/fs-extra": "^9.0.8",
|
|
25
25
|
"@types/node-fetch": "^2.5.8",
|
|
26
|
-
"@types/sharp": "^0.
|
|
27
|
-
"@vendure/common": "^2.0.0-next.
|
|
28
|
-
"@vendure/core": "^2.0.0-next.
|
|
26
|
+
"@types/sharp": "^0.30.4",
|
|
27
|
+
"@vendure/common": "^2.0.0-next.20",
|
|
28
|
+
"@vendure/core": "^2.0.0-next.20",
|
|
29
29
|
"aws-sdk": "^2.856.0",
|
|
30
30
|
"express": "^4.17.1",
|
|
31
31
|
"node-fetch": "^2.6.7",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"file-type": "^16.5.3",
|
|
37
37
|
"fs-extra": "^10.0.0",
|
|
38
|
-
"sharp": "~0.30.
|
|
38
|
+
"sharp": "~0.30.7"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "f0766a7fa72cc56e647d3b4c3f213920c3fc7316"
|
|
41
41
|
}
|