@appweaver/core 1.0.20 → 1.0.22
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/package.json +1 -1
- package/storage/file-service.js +1 -1
- package/utils/image-util.d.ts +4 -3
- package/utils/image-util.js +18 -15
package/package.json
CHANGED
package/storage/file-service.js
CHANGED
|
@@ -166,7 +166,7 @@ class FileService {
|
|
|
166
166
|
throw new errors_1.HttpError('Creating file is forbidden', 403);
|
|
167
167
|
}
|
|
168
168
|
let fileStream = data.file;
|
|
169
|
-
if (
|
|
169
|
+
if ((0, utils_1.isProcessableImage)(data.mimetype)) {
|
|
170
170
|
fileStream = (0, utils_1.processImage)(data.file, data.mimetype, fileConfig.image);
|
|
171
171
|
}
|
|
172
172
|
const fileName = await this._storage.store(generatedName, fileStream);
|
package/utils/image-util.d.ts
CHANGED
|
@@ -8,11 +8,12 @@ import { ImageConfig } from '@appweaver/common';
|
|
|
8
8
|
*/
|
|
9
9
|
export declare function isProcessableImage(mimeType: string): boolean;
|
|
10
10
|
/**
|
|
11
|
-
* Processes an image stream by resizing
|
|
11
|
+
* Processes an image stream by applying EXIF-based autorotation, resizing, and compressing based on the
|
|
12
|
+
* provided configuration. When no config is provided, only EXIF-based autorotation is applied.
|
|
12
13
|
*
|
|
13
14
|
* @param {Readable} stream - The readable stream representing the input image.
|
|
14
15
|
* @param {string} mimeType - The MIME type of the input image (e.g., "image/jpeg", "image/png").
|
|
15
|
-
* @param {ImageConfig} config - Configuration for image processing, including dimensions, quality, and other options.
|
|
16
|
+
* @param {ImageConfig} [config] - Configuration for image processing, including dimensions, quality, and other options.
|
|
16
17
|
* @return {Readable} A readable stream of the processed image.
|
|
17
18
|
*/
|
|
18
|
-
export declare function processImage(stream: Readable, mimeType: string, config
|
|
19
|
+
export declare function processImage(stream: Readable, mimeType: string, config?: ImageConfig): Readable;
|
package/utils/image-util.js
CHANGED
|
@@ -23,11 +23,12 @@ function isProcessableImage(mimeType) {
|
|
|
23
23
|
return mimeType in IMAGE_MIME_FORMATS;
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
|
-
* Processes an image stream by resizing
|
|
26
|
+
* Processes an image stream by applying EXIF-based autorotation, resizing, and compressing based on the
|
|
27
|
+
* provided configuration. When no config is provided, only EXIF-based autorotation is applied.
|
|
27
28
|
*
|
|
28
29
|
* @param {Readable} stream - The readable stream representing the input image.
|
|
29
30
|
* @param {string} mimeType - The MIME type of the input image (e.g., "image/jpeg", "image/png").
|
|
30
|
-
* @param {ImageConfig} config - Configuration for image processing, including dimensions, quality, and other options.
|
|
31
|
+
* @param {ImageConfig} [config] - Configuration for image processing, including dimensions, quality, and other options.
|
|
31
32
|
* @return {Readable} A readable stream of the processed image.
|
|
32
33
|
*/
|
|
33
34
|
function processImage(stream, mimeType, config) {
|
|
@@ -35,19 +36,21 @@ function processImage(stream, mimeType, config) {
|
|
|
35
36
|
if (!format) {
|
|
36
37
|
return stream;
|
|
37
38
|
}
|
|
38
|
-
let pipeline = (0, sharp_1.default)();
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
39
|
+
let pipeline = (0, sharp_1.default)().rotate();
|
|
40
|
+
if (config) {
|
|
41
|
+
const width = config.width ?? config.maxWidth;
|
|
42
|
+
const height = config.height ?? config.maxHeight;
|
|
43
|
+
const fit = config.fit ?? 'inside';
|
|
44
|
+
if (width || height) {
|
|
45
|
+
pipeline = pipeline.resize({
|
|
46
|
+
width: width ?? undefined,
|
|
47
|
+
height: height ?? undefined,
|
|
48
|
+
fit,
|
|
49
|
+
withoutEnlargement: !config.width && !config.height
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const opts = config.quality ? { quality: config.quality } : {};
|
|
53
|
+
pipeline = pipeline.toFormat(format, opts);
|
|
49
54
|
}
|
|
50
|
-
const opts = config.quality ? { quality: config.quality } : {};
|
|
51
|
-
pipeline = pipeline.toFormat(format, opts);
|
|
52
55
|
return stream.pipe(pipeline);
|
|
53
56
|
}
|