5htp-core 0.5.1-7 → 0.5.1-8
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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "5htp-core",
|
|
3
3
|
"description": "Convenient TypeScript framework designed for Performance and Productivity.",
|
|
4
|
-
"version": "0.5.1-
|
|
4
|
+
"version": "0.5.1-8",
|
|
5
5
|
"author": "Gaetan Le Gac (https://github.com/gaetanlegac)",
|
|
6
6
|
"repository": "git://github.com/gaetanlegac/5htp-core.git",
|
|
7
7
|
"license": "MIT",
|
|
@@ -73,7 +73,6 @@
|
|
|
73
73
|
"react-textarea-autosize": "^8.3.3",
|
|
74
74
|
"regenerator-runtime": "^0.13.9",
|
|
75
75
|
"request": "^2.88.2",
|
|
76
|
-
"sharp": "^0.29.1",
|
|
77
76
|
"slugify": "^1.6.6",
|
|
78
77
|
"sql-formatter": "^4.0.2",
|
|
79
78
|
"stopword": "^3.1.1",
|
|
@@ -85,7 +84,8 @@
|
|
|
85
84
|
"yaml": "^1.10.2",
|
|
86
85
|
"yargs-parser": "^21.1.1",
|
|
87
86
|
"youch": "^3.3.3",
|
|
88
|
-
"youch-terminal": "^2.2.3"
|
|
87
|
+
"youch-terminal": "^2.2.3",
|
|
88
|
+
"zod": "^3.24.2"
|
|
89
89
|
},
|
|
90
90
|
"devDependencies": {
|
|
91
91
|
"@types/cookie": "^0.4.1",
|
|
@@ -99,7 +99,8 @@
|
|
|
99
99
|
"@types/webpack-env": "^1.16.2",
|
|
100
100
|
"@types/ws": "^7.4.7",
|
|
101
101
|
"@types/yargs-parser": "^21.0.0",
|
|
102
|
-
"schema-dts": "^1.1.2"
|
|
102
|
+
"schema-dts": "^1.1.2",
|
|
103
|
+
"sharp": "^0.33.5"
|
|
103
104
|
},
|
|
104
105
|
"peerDependencies": {
|
|
105
106
|
"5htp": "0.4.5"
|
|
@@ -318,9 +318,11 @@ export default abstract class Service<
|
|
|
318
318
|
return Promise.all(
|
|
319
319
|
callbacks.map(
|
|
320
320
|
cb => cb(...args).catch(e => {
|
|
321
|
-
|
|
321
|
+
|
|
322
322
|
if (name !== 'error')
|
|
323
323
|
this.runHook('error', e);
|
|
324
|
+
else
|
|
325
|
+
console.error(`[hook] Error while executing hook ${name}:`, e);
|
|
324
326
|
})
|
|
325
327
|
)
|
|
326
328
|
).then(() => {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
----------------------------------*/
|
|
4
4
|
|
|
5
5
|
// Npm
|
|
6
|
-
import sharp from 'sharp';
|
|
6
|
+
import type { default as sharp, Sharp } from 'sharp';
|
|
7
7
|
import fs from 'fs-extra';
|
|
8
8
|
import got, { Method, Options } from 'got';
|
|
9
9
|
|
|
@@ -43,6 +43,7 @@ export type Services = {
|
|
|
43
43
|
----------------------------------*/
|
|
44
44
|
|
|
45
45
|
export type TImageConfig = {
|
|
46
|
+
sharp: typeof sharp,
|
|
46
47
|
width: number,
|
|
47
48
|
height: number,
|
|
48
49
|
fit: keyof sharp.FitEnum,
|
|
@@ -172,7 +173,7 @@ export default class FetchService extends Service<Config, Hooks, Application, Se
|
|
|
172
173
|
|
|
173
174
|
public async image(
|
|
174
175
|
imageFileUrl: string,
|
|
175
|
-
|
|
176
|
+
imageMod: TImageConfig,
|
|
176
177
|
saveToBucket: string,
|
|
177
178
|
saveToPath?: string,
|
|
178
179
|
disk?: string
|
|
@@ -183,7 +184,7 @@ export default class FetchService extends Service<Config, Hooks, Application, Se
|
|
|
183
184
|
throw new Error(`Please provide a Disks service in order to download files.`);
|
|
184
185
|
|
|
185
186
|
// Download
|
|
186
|
-
let imageBuffer: Buffer;
|
|
187
|
+
let imageBuffer: Buffer | null;
|
|
187
188
|
try {
|
|
188
189
|
imageBuffer = await this.toBuffer( imageFileUrl );
|
|
189
190
|
} catch (error) {
|
|
@@ -191,21 +192,27 @@ export default class FetchService extends Service<Config, Hooks, Application, Se
|
|
|
191
192
|
return null;
|
|
192
193
|
}
|
|
193
194
|
|
|
194
|
-
|
|
195
|
-
const processing = sharp( imageBuffer )
|
|
196
|
-
// Max dimensions (save space)
|
|
197
|
-
.resize(width, height, { fit })
|
|
195
|
+
if (imageMod) {
|
|
198
196
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
197
|
+
const { sharp, width, height, fit, quality } = imageMod;
|
|
198
|
+
|
|
199
|
+
// Resize
|
|
200
|
+
const processing = sharp( imageBuffer )
|
|
201
|
+
// Max dimensions (save space)
|
|
202
|
+
.resize(width, height, { fit })
|
|
203
|
+
|
|
204
|
+
// Convert to webp and finalize
|
|
205
|
+
imageBuffer = await processing.webp({ quality }).toBuffer().catch(e => {
|
|
206
|
+
console.error(LogPrefix, `Error while processing image at ${imageFileUrl}:`, e);
|
|
207
|
+
return null;
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
}
|
|
204
211
|
|
|
205
212
|
// Save file
|
|
206
|
-
if (saveToPath !== undefined &&
|
|
213
|
+
if (saveToPath !== undefined && imageBuffer !== null) {
|
|
207
214
|
console.log(LogPrefix, `Saving ${imageFileUrl} logo to ${saveToPath}`);
|
|
208
|
-
await this.disk.outputFile(saveToBucket, saveToPath,
|
|
215
|
+
await this.disk.outputFile(saveToBucket, saveToPath, imageBuffer);
|
|
209
216
|
}
|
|
210
217
|
|
|
211
218
|
// We return the original, because Vibrant.js doesn't support webp
|
|
@@ -164,7 +164,7 @@ export default class HttpServer {
|
|
|
164
164
|
// Décodage des données post
|
|
165
165
|
express.json({
|
|
166
166
|
// TODO: prendre en considération les upload de fichiers
|
|
167
|
-
limit:
|
|
167
|
+
limit: bytes(this.config.upload.maxSize),
|
|
168
168
|
verify: (req, res, buf, encoding) => {
|
|
169
169
|
// Store the raw request body so we can access it later
|
|
170
170
|
req.rawBody = buf;
|