@deenruv/asset-server-plugin 1.0.0

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.
Files changed (37) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +103 -0
  3. package/lib/index.d.ts +4 -0
  4. package/lib/index.js +21 -0
  5. package/lib/index.js.map +1 -0
  6. package/lib/src/common.d.ts +4 -0
  7. package/lib/src/common.js +42 -0
  8. package/lib/src/common.js.map +1 -0
  9. package/lib/src/constants.d.ts +2 -0
  10. package/lib/src/constants.js +6 -0
  11. package/lib/src/constants.js.map +1 -0
  12. package/lib/src/default-asset-storage-strategy-factory.d.ts +6 -0
  13. package/lib/src/default-asset-storage-strategy-factory.js +24 -0
  14. package/lib/src/default-asset-storage-strategy-factory.js.map +1 -0
  15. package/lib/src/file-icon.png +0 -0
  16. package/lib/src/hashed-asset-naming-strategy.d.ts +21 -0
  17. package/lib/src/hashed-asset-naming-strategy.js +39 -0
  18. package/lib/src/hashed-asset-naming-strategy.js.map +1 -0
  19. package/lib/src/local-asset-storage-strategy.d.ts +28 -0
  20. package/lib/src/local-asset-storage-strategy.js +68 -0
  21. package/lib/src/local-asset-storage-strategy.js.map +1 -0
  22. package/lib/src/plugin.d.ts +167 -0
  23. package/lib/src/plugin.js +394 -0
  24. package/lib/src/plugin.js.map +1 -0
  25. package/lib/src/s3-asset-storage-strategy.d.ts +159 -0
  26. package/lib/src/s3-asset-storage-strategy.js +289 -0
  27. package/lib/src/s3-asset-storage-strategy.js.map +1 -0
  28. package/lib/src/sharp-asset-preview-strategy.d.ts +99 -0
  29. package/lib/src/sharp-asset-preview-strategy.js +121 -0
  30. package/lib/src/sharp-asset-preview-strategy.js.map +1 -0
  31. package/lib/src/transform-image.d.ts +25 -0
  32. package/lib/src/transform-image.js +145 -0
  33. package/lib/src/transform-image.js.map +1 -0
  34. package/lib/src/types.d.ts +137 -0
  35. package/lib/src/types.js +3 -0
  36. package/lib/src/types.js.map +1 -0
  37. package/package.json +47 -0
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.resizeToFocalPoint = exports.transformImage = void 0;
7
+ const core_1 = require("@deenruv/core");
8
+ const sharp_1 = __importDefault(require("sharp"));
9
+ const common_1 = require("./common");
10
+ const constants_1 = require("./constants");
11
+ /**
12
+ * Applies transforms to the given image according to the query params passed.
13
+ */
14
+ async function transformImage(originalImage, queryParams, presets) {
15
+ let targetWidth = Math.round(+queryParams.w) || undefined;
16
+ let targetHeight = Math.round(+queryParams.h) || undefined;
17
+ const quality = queryParams.q != null
18
+ ? Math.round(Math.max(Math.min(+queryParams.q, 100), 1))
19
+ : undefined;
20
+ let mode = queryParams.mode || "crop";
21
+ const fpx = +queryParams.fpx || undefined;
22
+ const fpy = +queryParams.fpy || undefined;
23
+ const imageFormat = (0, common_1.getValidFormat)(queryParams.format);
24
+ if (queryParams.preset) {
25
+ const matchingPreset = presets.find((p) => p.name === queryParams.preset);
26
+ if (matchingPreset) {
27
+ targetWidth = matchingPreset.width;
28
+ targetHeight = matchingPreset.height;
29
+ mode = matchingPreset.mode;
30
+ }
31
+ }
32
+ const options = {};
33
+ if (mode === "crop") {
34
+ options.position = sharp_1.default.strategy.entropy;
35
+ }
36
+ else {
37
+ options.fit = "inside";
38
+ }
39
+ const image = (0, sharp_1.default)(originalImage);
40
+ try {
41
+ await applyFormat(image, imageFormat, quality);
42
+ }
43
+ catch (e) {
44
+ core_1.Logger.error(e.message, constants_1.loggerCtx, e.stack);
45
+ }
46
+ if (fpx && fpy && targetWidth && targetHeight && mode === "crop") {
47
+ const metadata = await image.metadata();
48
+ if (metadata.width && metadata.height) {
49
+ const xCenter = fpx * metadata.width;
50
+ const yCenter = fpy * metadata.height;
51
+ const { width, height, region } = resizeToFocalPoint({ w: metadata.width, h: metadata.height }, { w: targetWidth, h: targetHeight }, { x: xCenter, y: yCenter });
52
+ return image.resize(width, height).extract(region);
53
+ }
54
+ }
55
+ return image.resize(targetWidth, targetHeight, options);
56
+ }
57
+ exports.transformImage = transformImage;
58
+ async function applyFormat(image, format, quality) {
59
+ switch (format) {
60
+ case "jpg":
61
+ case "jpeg":
62
+ return image.jpeg({ quality });
63
+ case "png":
64
+ return image.png();
65
+ case "webp":
66
+ return image.webp({ quality });
67
+ case "avif":
68
+ return image.avif({ quality });
69
+ default: {
70
+ if (quality) {
71
+ // If a quality has been specified but no format, we need to determine the format from the image
72
+ // and apply the quality to that format.
73
+ const metadata = await image.metadata();
74
+ if (isImageTransformFormat(metadata.format)) {
75
+ return applyFormat(image, metadata.format, quality);
76
+ }
77
+ }
78
+ return image;
79
+ }
80
+ }
81
+ }
82
+ function isImageTransformFormat(input) {
83
+ return !!input && ["jpg", "jpeg", "webp", "avif"].includes(input);
84
+ }
85
+ /**
86
+ * Resize an image but keep it centered on the focal point.
87
+ * Based on the method outlined in https://github.com/lovell/sharp/issues/1198#issuecomment-384591756
88
+ */
89
+ function resizeToFocalPoint(original, target, focalPoint) {
90
+ const { width, height, factor } = getIntermediateDimensions(original, target);
91
+ const region = getExtractionRegion(factor, focalPoint, target, {
92
+ w: width,
93
+ h: height,
94
+ });
95
+ return { width, height, region };
96
+ }
97
+ exports.resizeToFocalPoint = resizeToFocalPoint;
98
+ /**
99
+ * Calculates the dimensions of the intermediate (resized) image.
100
+ */
101
+ function getIntermediateDimensions(original, target) {
102
+ const hRatio = original.h / target.h;
103
+ const wRatio = original.w / target.w;
104
+ let factor;
105
+ let width;
106
+ let height;
107
+ if (hRatio < wRatio) {
108
+ factor = hRatio;
109
+ height = Math.round(target.h);
110
+ width = Math.round(original.w / factor);
111
+ }
112
+ else {
113
+ factor = wRatio;
114
+ width = Math.round(target.w);
115
+ height = Math.round(original.h / factor);
116
+ }
117
+ return { width, height, factor };
118
+ }
119
+ /**
120
+ * Calculates the Region to extract from the intermediate image.
121
+ */
122
+ function getExtractionRegion(factor, focalPoint, target, intermediate) {
123
+ const newXCenter = focalPoint.x / factor;
124
+ const newYCenter = focalPoint.y / factor;
125
+ const region = {
126
+ left: 0,
127
+ top: 0,
128
+ width: target.w,
129
+ height: target.h,
130
+ };
131
+ if (intermediate.h < intermediate.w) {
132
+ region.left = clamp(0, intermediate.w - target.w, Math.round(newXCenter - target.w / 2));
133
+ }
134
+ else {
135
+ region.top = clamp(0, intermediate.h - target.h, Math.round(newYCenter - target.h / 2));
136
+ }
137
+ return region;
138
+ }
139
+ /**
140
+ * Limit the input value to the specified min and max values.
141
+ */
142
+ function clamp(min, max, input) {
143
+ return Math.min(Math.max(min, input), max);
144
+ }
145
+ //# sourceMappingURL=transform-image.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform-image.js","sourceRoot":"","sources":["../../src/transform-image.ts"],"names":[],"mappings":";;;;;;AAAA,wCAAuC;AACvC,kDAAiE;AAEjE,qCAA0C;AAC1C,2CAAwC;AAMxC;;GAEG;AACI,KAAK,UAAU,cAAc,CAClC,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,MAAM,OAAO,GACX,WAAW,CAAC,CAAC,IAAI,IAAI;QACnB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,WAAW,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;QACxD,CAAC,CAAC,SAAS,CAAC;IAChB,IAAI,IAAI,GAAG,WAAW,CAAC,IAAI,IAAI,MAAM,CAAC;IACtC,MAAM,GAAG,GAAG,CAAC,WAAW,C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AAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,SAAS,KAAK,CAAC,GAAW,EAAE,GAAW,EAAE,KAAa;IACpD,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,137 @@
1
+ import { AssetNamingStrategy, AssetPreviewStrategy, AssetStorageStrategy, RequestContext } from "@deenruv/core";
2
+ export type ImageTransformFormat = "jpg" | "jpeg" | "png" | "webp" | "avif";
3
+ /**
4
+ * @description
5
+ * Specifies the way in which an asset preview image will be resized to fit in the
6
+ * proscribed dimensions:
7
+ *
8
+ * * crop: crops the image to cover both provided dimensions
9
+ * * resize: Preserving aspect ratio, resizes the image to be as large as possible
10
+ * while ensuring its dimensions are less than or equal to both those specified.
11
+ *
12
+ * @docsCategory core plugins/AssetServerPlugin
13
+ */
14
+ export type ImageTransformMode = "crop" | "resize";
15
+ /**
16
+ * @description
17
+ * A configuration option for an image size preset for the AssetServerPlugin.
18
+ *
19
+ * Presets allow a shorthand way to generate a thumbnail preview of an asset. For example,
20
+ * the built-in "tiny" preset generates a 50px x 50px cropped preview, which can be accessed
21
+ * by appending the string `preset=tiny` to the asset url:
22
+ *
23
+ * `http://localhost:3000/assets/some-asset.jpg?preset=tiny`
24
+ *
25
+ * is equivalent to:
26
+ *
27
+ * `http://localhost:3000/assets/some-asset.jpg?w=50&h=50&mode=crop`
28
+ *
29
+ * @docsCategory core plugins/AssetServerPlugin
30
+ */
31
+ export interface ImageTransformPreset {
32
+ name: string;
33
+ width: number;
34
+ height: number;
35
+ mode: ImageTransformMode;
36
+ }
37
+ /**
38
+ * @description
39
+ * A configuration option for the Cache-Control header in the AssetServerPlugin asset response.
40
+ *
41
+ * @docsCategory core plugins/AssetServerPlugin
42
+ */
43
+ export type CacheConfig = {
44
+ /**
45
+ * @description
46
+ * The max-age=N response directive indicates that the response remains fresh until N seconds after the response is generated.
47
+ */
48
+ maxAge: number;
49
+ /**
50
+ * @description
51
+ * The `private` response directive indicates that the response can be stored only in a private cache (e.g. local caches in browsers).
52
+ * The `public` response directive indicates that the response can be stored in a shared cache.
53
+ */
54
+ restriction?: "public" | "private";
55
+ };
56
+ /**
57
+ * @description
58
+ * The configuration options for the AssetServerPlugin.
59
+ *
60
+ * @docsCategory core plugins/AssetServerPlugin
61
+ */
62
+ export interface AssetServerOptions {
63
+ /**
64
+ * @description
65
+ * The route to the asset server.
66
+ */
67
+ route: string;
68
+ /**
69
+ * @description
70
+ * The local directory to which assets will be uploaded when using the {@link LocalAssetStorageStrategy}.
71
+ */
72
+ assetUploadDir: string;
73
+ /**
74
+ * @description
75
+ * The complete URL prefix of the asset files. For example, "https://demo.deenruv.io/assets/". A
76
+ * function can also be provided to handle more complex cases, such as serving multiple domains
77
+ * from a single server. In this case, the function should return a string url prefix.
78
+ *
79
+ * If not provided, the plugin will attempt to guess based off the incoming
80
+ * request and the configured route. However, in all but the simplest cases,
81
+ * this guess may not yield correct results.
82
+ */
83
+ assetUrlPrefix?: string | ((ctx: RequestContext, identifier: string) => string);
84
+ /**
85
+ * @description
86
+ * The max width in pixels of a generated preview image.
87
+ *
88
+ * @default 1600
89
+ * @deprecated Use `previewStrategy: new SharpAssetPreviewStrategy({ maxWidth })` instead
90
+ */
91
+ previewMaxWidth?: number;
92
+ /**
93
+ * @description
94
+ * The max height in pixels of a generated preview image.
95
+ *
96
+ * @default 1600
97
+ * @deprecated Use `previewStrategy: new SharpAssetPreviewStrategy({ maxHeight })` instead
98
+ */
99
+ previewMaxHeight?: number;
100
+ /**
101
+ * @description
102
+ * An array of additional {@link ImageTransformPreset} objects.
103
+ */
104
+ presets?: ImageTransformPreset[];
105
+ /**
106
+ * @description
107
+ * Defines how asset files and preview images are named before being saved.
108
+ *
109
+ * @default HashedAssetNamingStrategy
110
+ */
111
+ namingStrategy?: AssetNamingStrategy;
112
+ /**
113
+ * @description
114
+ * Defines how previews are generated for a given Asset binary. By default, this uses
115
+ * the {@link SharpAssetPreviewStrategy}
116
+ *
117
+ * @since 1.7.0
118
+ */
119
+ previewStrategy?: AssetPreviewStrategy;
120
+ /**
121
+ * @description
122
+ * A function which can be used to configure an {@link AssetStorageStrategy}. This is useful e.g. if you wish to store your assets
123
+ * using a cloud storage provider. By default, the {@link LocalAssetStorageStrategy} is used.
124
+ *
125
+ * @default () => LocalAssetStorageStrategy
126
+ */
127
+ storageStrategyFactory?: (options: AssetServerOptions) => AssetStorageStrategy | Promise<AssetStorageStrategy>;
128
+ /**
129
+ * @description
130
+ * Configures the `Cache-Control` directive for response to control caching in browsers and shared caches (e.g. Proxies, CDNs).
131
+ * Defaults to publicly cached for 6 months.
132
+ *
133
+ * @default 'public, max-age=15552000'
134
+ * @since 1.9.3
135
+ */
136
+ cacheHeader?: CacheConfig | string;
137
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@deenruv/asset-server-plugin",
3
+ "version": "1.0.0",
4
+ "main": "lib/index.js",
5
+ "types": "lib/index.d.ts",
6
+ "files": [
7
+ "lib/**/*"
8
+ ],
9
+ "license": "MIT",
10
+ "homepage": "https://deenruv.com/",
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "peerDependencies": {
15
+ "@deenruv/core": "^0.1.0"
16
+ },
17
+ "devDependencies": {
18
+ "@aws-sdk/client-s3": "^3.529.1",
19
+ "@aws-sdk/lib-storage": "^3.529.1",
20
+ "@aws-sdk/types": "^3.664.0",
21
+ "@types/express": "^4.17.21",
22
+ "@types/fs-extra": "^11.0.4",
23
+ "@types/node-fetch": "^2.6.11",
24
+ "express": "^4.18.3",
25
+ "node-fetch": "^2.7.0",
26
+ "rimraf": "^5.0.5",
27
+ "typescript": "5.3.3",
28
+ "@deenruv/core": "^1.0.0",
29
+ "@deenruv/common": "^1.0.0"
30
+ },
31
+ "dependencies": {
32
+ "@aws-sdk/credential-provider-ini": "^3.664.0",
33
+ "@nestjs/common": "^10.3.10",
34
+ "file-type": "^19.0.0",
35
+ "fs-extra": "^11.2.0",
36
+ "sharp": "~0.33.2"
37
+ },
38
+ "scripts": {
39
+ "watch": "tsc -p ./tsconfig.build.json --watch",
40
+ "build": "rimraf lib && tsc -p ./tsconfig.build.json && node build.js",
41
+ "lint": "eslint .",
42
+ "lint:fix": "eslint --fix .",
43
+ "test": "vitest --run",
44
+ "e2e": "cross-env PACKAGE=asset-server-plugin vitest --config ../../e2e-common/vitest.config.mts --run",
45
+ "e2e:watch": "cross-env PACKAGE=asset-server-plugin vitest --config ../../e2e-common/vitest.config.mts"
46
+ }
47
+ }