aptechka 0.11.4 → 0.11.5
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/server-lib/optimizer/index.js +11 -26
- package/server-lib/{server/optimizer → optimizer}/types.d.ts +2 -28
- package/server-lib/optimizer/utils.d.ts +1 -0
- package/server-lib/{server/utils → utils}/index.d.ts +1 -0
- package/server-lib/utils/index.js +4 -0
- package/server-lib/utils/math.d.ts +1 -0
- package/server-lib/server/optimizer/utils.d.ts +0 -4
- /package/server-lib/{server/optimizer → optimizer}/FFmpeg.d.ts +0 -0
- /package/server-lib/{server/optimizer → optimizer}/generateFavicon.d.ts +0 -0
- /package/server-lib/{server/optimizer → optimizer}/generateSequence.d.ts +0 -0
- /package/server-lib/{server/optimizer → optimizer}/generateSprite.d.ts +0 -0
- /package/server-lib/{server/optimizer → optimizer}/index.d.ts +0 -0
- /package/server-lib/{server/optimizer → optimizer}/inputFiles.d.ts +0 -0
- /package/server-lib/{server/optimizer → optimizer}/optimize.d.ts +0 -0
- /package/server-lib/{server/optimizer → optimizer}/optimizeImage.d.ts +0 -0
- /package/server-lib/{server/optimizer → optimizer}/optimizeVideo.d.ts +0 -0
- /package/server-lib/{server/optimizer → optimizer}/optimizer.d.ts +0 -0
- /package/server-lib/{server/utils → utils}/buffer.d.ts +0 -0
- /package/server-lib/{server/utils → utils}/fs.d.ts +0 -0
- /package/server-lib/{server/utils → utils}/path.d.ts +0 -0
- /package/server-lib/{server/utils → utils}/types.d.ts +0 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mkdir, readFile, readdir } from "fs/promises";
|
|
2
2
|
import { dirname, join, sep, extname } from "path";
|
|
3
3
|
import Ffmpeg from "fluent-ffmpeg";
|
|
4
|
-
import { getTmpPath, outputFile, getFolderFiles, removeExtension, clear, getBuffer, replaceExtension, outputFiles } from "../utils/index.js";
|
|
4
|
+
import { getTmpPath, outputFile, getFolderFiles, removeExtension, clear, getBuffer, clamp, replaceExtension, outputFiles } from "../utils/index.js";
|
|
5
5
|
import favicons from "favicons";
|
|
6
6
|
import { parse } from "node-html-parser";
|
|
7
7
|
import { statSync } from "fs";
|
|
@@ -236,10 +236,6 @@ async function inputFiles({
|
|
|
236
236
|
webp: false,
|
|
237
237
|
destinationPath,
|
|
238
238
|
...(_d = settings == null ? void 0 : settings.image) == null ? void 0 : _d.call(settings, { destinationPath })
|
|
239
|
-
},
|
|
240
|
-
restrictions: {
|
|
241
|
-
quality: { min: 0, max: 100 },
|
|
242
|
-
scale: { min: 0, max: 1 }
|
|
243
239
|
}
|
|
244
240
|
});
|
|
245
241
|
} else if (ALLOWED_VIDEO_EXTENSIONS.includes(
|
|
@@ -254,11 +250,6 @@ async function inputFiles({
|
|
|
254
250
|
fps: 0,
|
|
255
251
|
destinationPath,
|
|
256
252
|
...(_e = settings == null ? void 0 : settings.video) == null ? void 0 : _e.call(settings, { destinationPath })
|
|
257
|
-
},
|
|
258
|
-
restrictions: {
|
|
259
|
-
quality: { min: 0, max: 100 },
|
|
260
|
-
scale: { min: 0, max: 1 },
|
|
261
|
-
fps: { min: 0, max: 300 }
|
|
262
253
|
}
|
|
263
254
|
});
|
|
264
255
|
} else {
|
|
@@ -273,17 +264,14 @@ async function inputFiles({
|
|
|
273
264
|
}
|
|
274
265
|
return sources;
|
|
275
266
|
}
|
|
276
|
-
function
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
function getNumberSetting(value, restricstions) {
|
|
280
|
-
if (typeof value === "number" && restricstions) {
|
|
281
|
-
return clamp(value, restricstions.min, restricstions.max);
|
|
267
|
+
function getNumberSetting(value, min, max) {
|
|
268
|
+
if (typeof value === "number") {
|
|
269
|
+
return clamp(value, min, max);
|
|
282
270
|
}
|
|
283
271
|
return value;
|
|
284
272
|
}
|
|
285
273
|
async function optimizeImage(source) {
|
|
286
|
-
const { settings
|
|
274
|
+
const { settings } = source;
|
|
287
275
|
const content = await getBuffer(source.content);
|
|
288
276
|
const ext = extname(settings.destinationPath).toLowerCase();
|
|
289
277
|
const image = sharp(content);
|
|
@@ -291,8 +279,8 @@ async function optimizeImage(source) {
|
|
|
291
279
|
const width = meta.width;
|
|
292
280
|
const height = meta.height;
|
|
293
281
|
const output = [];
|
|
294
|
-
const scale = getNumberSetting(settings.scale,
|
|
295
|
-
const quality = getNumberSetting(settings.quality,
|
|
282
|
+
const scale = getNumberSetting(settings.scale, 0, 1);
|
|
283
|
+
const quality = getNumberSetting(settings.quality, 0, 100);
|
|
296
284
|
if (width && height) {
|
|
297
285
|
if (scale) {
|
|
298
286
|
image.resize(Math.floor(width * scale), Math.floor(height * scale));
|
|
@@ -339,14 +327,11 @@ async function optimizeImage(source) {
|
|
|
339
327
|
return output;
|
|
340
328
|
}
|
|
341
329
|
async function optimizeVideo(source) {
|
|
342
|
-
const { settings
|
|
330
|
+
const { settings } = source;
|
|
343
331
|
const buffer = await getBuffer(source.content);
|
|
344
|
-
const quality = getNumberSetting(
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
);
|
|
348
|
-
const fps = getNumberSetting((settings == null ? void 0 : settings.fps) || 0, restrictions == null ? void 0 : restrictions.fps);
|
|
349
|
-
const scale = getNumberSetting((settings == null ? void 0 : settings.scale) || 1, restrictions == null ? void 0 : restrictions.scale);
|
|
332
|
+
const quality = getNumberSetting((settings == null ? void 0 : settings.quality) || 80, 0, 100);
|
|
333
|
+
const fps = getNumberSetting((settings == null ? void 0 : settings.fps) || 0, 0, 300);
|
|
334
|
+
const scale = getNumberSetting((settings == null ? void 0 : settings.scale) || 1, 0, 1);
|
|
350
335
|
return FFmpeg({
|
|
351
336
|
inputPath: settings.destinationPath,
|
|
352
337
|
fileContent: buffer,
|
|
@@ -6,15 +6,11 @@ export type SourceDefaultSettings = {
|
|
|
6
6
|
export type SourceSetting = {
|
|
7
7
|
value: any;
|
|
8
8
|
};
|
|
9
|
-
export type Source<B = Buffer | File, T extends string = string, S extends SourceDefaultSettings = {}
|
|
10
|
-
[K in keyof S]: any;
|
|
11
|
-
}> | undefined = undefined> = {
|
|
9
|
+
export type Source<B = Buffer | File, T extends string = string, S extends SourceDefaultSettings = {}> = {
|
|
12
10
|
content: B;
|
|
13
11
|
type: T;
|
|
14
12
|
settings: S;
|
|
15
|
-
}
|
|
16
|
-
restrictions?: Partial<R>;
|
|
17
|
-
});
|
|
13
|
+
};
|
|
18
14
|
export type SkipSource = Source<Buffer | File, 'skip', {
|
|
19
15
|
destinationPath: string;
|
|
20
16
|
}>;
|
|
@@ -24,34 +20,12 @@ export type ImageSource = Source<Buffer | File, 'image', {
|
|
|
24
20
|
scale?: number;
|
|
25
21
|
placeholder?: boolean;
|
|
26
22
|
webp?: boolean;
|
|
27
|
-
}, {
|
|
28
|
-
quality: {
|
|
29
|
-
min: 0;
|
|
30
|
-
max: 100;
|
|
31
|
-
};
|
|
32
|
-
scale: {
|
|
33
|
-
min: 0;
|
|
34
|
-
max: 1;
|
|
35
|
-
};
|
|
36
23
|
}>;
|
|
37
24
|
export type VideoSource = Source<Buffer | File, 'video', {
|
|
38
25
|
destinationPath: string;
|
|
39
26
|
quality?: number;
|
|
40
27
|
scale?: number;
|
|
41
28
|
fps?: number;
|
|
42
|
-
}, {
|
|
43
|
-
quality: {
|
|
44
|
-
min: 0;
|
|
45
|
-
max: 100;
|
|
46
|
-
};
|
|
47
|
-
scale: {
|
|
48
|
-
min: 0;
|
|
49
|
-
max: 1;
|
|
50
|
-
};
|
|
51
|
-
fps: {
|
|
52
|
-
min: 0;
|
|
53
|
-
max: 300;
|
|
54
|
-
};
|
|
55
29
|
}>;
|
|
56
30
|
export type FaviconSource = Source<Buffer | File, 'favicon', {
|
|
57
31
|
destinationPath: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getNumberSetting<T extends number | undefined>(value: T, min: number, max: number): number | T;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { getBuffer } from './buffer';
|
|
2
2
|
export { removeExtension, replaceExtension, getTmpPath } from './path';
|
|
3
3
|
export { outputFile, outputFiles, clear, getFolderFiles } from './fs';
|
|
4
|
+
export { clamp } from './math';
|
|
4
5
|
export type { WriteFileData, OutputItem, Output } from './types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function clamp(number: number, min?: number, max?: number): number;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|