@appweaver/core 1.0.21 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appweaver/core",
3
- "version": "1.0.21",
3
+ "version": "1.0.22",
4
4
  "description": "Appweaver - the backend framework for AI-first development (@core)",
5
5
  "author": "Luka Matosevic",
6
6
  "license": "MIT",
@@ -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 (fileConfig.image && (0, utils_1.isProcessableImage)(data.mimetype)) {
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);
@@ -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 it and compressing it based on the provided configuration.
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: ImageConfig): Readable;
19
+ export declare function processImage(stream: Readable, mimeType: string, config?: ImageConfig): Readable;
@@ -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 it and compressing it based on the provided configuration.
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
- const width = config.width ?? config.maxWidth;
40
- const height = config.height ?? config.maxHeight;
41
- const fit = config.fit ?? 'inside';
42
- if (width || height) {
43
- pipeline = pipeline.resize({
44
- width: width ?? undefined,
45
- height: height ?? undefined,
46
- fit,
47
- withoutEnlargement: !config.width && !config.height
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
  }