@runnerpro/backend 1.12.24 → 1.12.26
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.
|
@@ -276,17 +276,10 @@ const sendFile = (req, res, { sendNotification, firebaseMessaging, isClient, buc
|
|
|
276
276
|
const { userid } = req.session;
|
|
277
277
|
const filePath = path_1.default.join('./uploads', req.file.filename);
|
|
278
278
|
if (req.file.mimetype.includes('video')) {
|
|
279
|
-
console.time('getVideoDuration');
|
|
280
279
|
duration = yield getVideoDuration(filePath);
|
|
281
|
-
console.timeEnd('getVideoDuration');
|
|
282
|
-
console.time('getThumbnailFromVideo');
|
|
283
280
|
thumbnail = yield getThumbnailFromVideo(filePath, duration);
|
|
284
|
-
console.timeEnd('getThumbnailFromVideo');
|
|
285
281
|
}
|
|
286
|
-
console.time('query');
|
|
287
282
|
const [{ id: idFile }] = yield (0, index_1.query)('INSERT INTO [CHAT MESSAGE] ([ID CLIENTE], [ID SENDER], [TEXT], [MIMETYPE], [DURATION], [TYPE]) VALUES (?, ?, ?, ?, ?, ?) RETURNING [ID]', [isClient ? userid : idCliente, userid, req.file.originalname, req.file.mimetype, duration || null, type || 2]);
|
|
288
|
-
console.timeEnd('query');
|
|
289
|
-
console.time('readFileSync');
|
|
290
283
|
const fileData = fs_1.default.readFileSync(filePath);
|
|
291
284
|
const files = [];
|
|
292
285
|
if (req.file.mimetype.includes('image')) {
|
|
@@ -307,13 +300,10 @@ const sendFile = (req, res, { sendNotification, firebaseMessaging, isClient, buc
|
|
|
307
300
|
else {
|
|
308
301
|
files.push({ data: fileData, id: idFile });
|
|
309
302
|
}
|
|
310
|
-
console.timeEnd('readFileSync');
|
|
311
303
|
res.send({ idFile });
|
|
312
|
-
console.time('saveFile');
|
|
313
304
|
for (const file of files) {
|
|
314
305
|
yield bucket.file(`Chat/${file.id}`).save(file.data);
|
|
315
306
|
}
|
|
316
|
-
console.timeEnd('saveFile');
|
|
317
307
|
fs_1.default.unlinkSync(filePath);
|
|
318
308
|
if (!isClient) {
|
|
319
309
|
const [cliente] = yield (0, index_1.query)('SELECT [PREFERRED LANGUAGE] FROM [CLIENTE] WHERE [ID] = ?', [idCliente]);
|
|
@@ -328,7 +318,6 @@ const sendFile = (req, res, { sendNotification, firebaseMessaging, isClient, buc
|
|
|
328
318
|
const getThumbnailFromVideo = (videoPath, duration) => __awaiter(void 0, void 0, void 0, function* () {
|
|
329
319
|
const targetWidth = 500;
|
|
330
320
|
const targetHeight = 400;
|
|
331
|
-
const quality = 2;
|
|
332
321
|
const tempDir = path_1.default.join('./uploads');
|
|
333
322
|
const outputFilename = `thumbnail_${Date.now()}.png`;
|
|
334
323
|
const outputPath = path_1.default.join(tempDir, outputFilename);
|
|
@@ -336,20 +325,16 @@ const getThumbnailFromVideo = (videoPath, duration) => __awaiter(void 0, void 0,
|
|
|
336
325
|
const timestamp = Math.min(Math.max(duration * 0.1, 1), 10);
|
|
337
326
|
return new Promise((resolve, reject) => {
|
|
338
327
|
(0, fluent_ffmpeg_1.default)(videoPath)
|
|
339
|
-
.
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
.videoFilters([
|
|
348
|
-
// Escalar manteniendo aspect ratio para que la dimensión menor coincida con el target
|
|
349
|
-
`scale=${targetWidth}:${targetHeight}:force_original_aspect_ratio=increase`,
|
|
350
|
-
// Hacer crop desde el centro para obtener exactamente el tamaño deseado
|
|
351
|
-
`crop=${targetWidth}:${targetHeight}`,
|
|
328
|
+
.seekInput(timestamp)
|
|
329
|
+
.outputOptions([
|
|
330
|
+
'-vf',
|
|
331
|
+
`scale=${targetWidth}:${targetHeight}:force_original_aspect_ratio=increase,crop=${targetWidth}:${targetHeight}`,
|
|
332
|
+
'-vframes',
|
|
333
|
+
'1',
|
|
334
|
+
'-f',
|
|
335
|
+
'image2',
|
|
352
336
|
])
|
|
337
|
+
.output(outputPath)
|
|
353
338
|
.on('end', () => {
|
|
354
339
|
try {
|
|
355
340
|
// Leer el archivo como buffer
|
|
@@ -374,7 +359,8 @@ const getThumbnailFromVideo = (videoPath, duration) => __awaiter(void 0, void 0,
|
|
|
374
359
|
console.error('Error limpiando archivo temporal:', cleanupError);
|
|
375
360
|
}
|
|
376
361
|
reject(error);
|
|
377
|
-
})
|
|
362
|
+
})
|
|
363
|
+
.run();
|
|
378
364
|
});
|
|
379
365
|
});
|
|
380
366
|
const getVideoDuration = (videoPath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -426,27 +412,17 @@ const resizeImage = (data, filePath, mimetype) => __awaiter(void 0, void 0, void
|
|
|
426
412
|
const rotateOrientationImage = (data, filePath, image = null, mimetype) => __awaiter(void 0, void 0, void 0, function* () {
|
|
427
413
|
if (mimetype.includes('webp'))
|
|
428
414
|
return data;
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
processedImage = image;
|
|
432
|
-
}
|
|
433
|
-
else {
|
|
434
|
-
processedImage = yield jimp_1.default.read(filePath);
|
|
435
|
-
}
|
|
415
|
+
if (!image)
|
|
416
|
+
image = yield jimp_1.default.read(filePath);
|
|
436
417
|
const orientation = yield exifr_1.default.orientation(data);
|
|
437
|
-
// Validar que orientation existe y es un número válido
|
|
438
|
-
if (typeof orientation !== 'number') {
|
|
439
|
-
return processedImage.getBufferAsync(jimp_1.default.MIME_JPEG);
|
|
440
|
-
}
|
|
441
418
|
let rotate;
|
|
442
419
|
if ([7, 8].includes(orientation))
|
|
443
420
|
rotate = 90;
|
|
444
421
|
else if ([3].includes(orientation))
|
|
445
422
|
rotate = 180;
|
|
446
|
-
else if ([5,
|
|
423
|
+
else if ([5, 8].includes(orientation))
|
|
447
424
|
rotate = -90;
|
|
448
|
-
if (rotate)
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
return processedImage.getBufferAsync(jimp_1.default.MIME_JPEG);
|
|
425
|
+
if (rotate)
|
|
426
|
+
image = yield image.rotate(rotate);
|
|
427
|
+
return image.getBufferAsync(jimp_1.default.MIME_JPEG);
|
|
452
428
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../../../src/chat/api/conversation.ts"],"names":[],"mappings":"AAkBA,QAAA,MAAM,iBAAiB,0BAA2B,GAAG,SAuBpD,CAAC;
|
|
1
|
+
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../../../src/chat/api/conversation.ts"],"names":[],"mappings":"AAkBA,QAAA,MAAM,iBAAiB,0BAA2B,GAAG,SAuBpD,CAAC;AAuZF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|