@runnerpro/backend 1.12.18 → 1.12.20
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.
|
@@ -277,7 +277,9 @@ const sendFile = (req, res, { sendNotification, firebaseMessaging, isClient, buc
|
|
|
277
277
|
const { userid } = req.session;
|
|
278
278
|
const filePath = path_1.default.join('./uploads', req.file.filename);
|
|
279
279
|
if (req.file.mimetype.includes('video')) {
|
|
280
|
+
console.log('es video');
|
|
280
281
|
[duration, thumbnail] = yield Promise.all([getVideoDuration(filePath), getThumbnailFromVideo(filePath)]);
|
|
282
|
+
console.log('duration and thumbnail done');
|
|
281
283
|
}
|
|
282
284
|
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]);
|
|
283
285
|
const fileData = fs_1.default.readFileSync(filePath);
|
|
@@ -316,45 +318,58 @@ const sendFile = (req, res, { sendNotification, firebaseMessaging, isClient, buc
|
|
|
316
318
|
}
|
|
317
319
|
});
|
|
318
320
|
const getThumbnailFromVideo = (videoPath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
319
|
-
const timestamp = 10;
|
|
320
321
|
const size = '640x480';
|
|
321
322
|
const quality = 2;
|
|
322
323
|
const tempDir = path_1.default.join('./uploads');
|
|
323
324
|
const outputFilename = `thumbnail_${Date.now()}.png`;
|
|
324
325
|
const outputPath = path_1.default.join(tempDir, outputFilename);
|
|
326
|
+
console.log('getThumbnailFromVideo', { outputPath, outputFilename, tempDir });
|
|
325
327
|
return new Promise((resolve, reject) => {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
filename: outputFilename,
|
|
330
|
-
folder: tempDir,
|
|
331
|
-
size,
|
|
332
|
-
quality,
|
|
333
|
-
})
|
|
334
|
-
.on('end', () => {
|
|
335
|
-
try {
|
|
336
|
-
// Leer el archivo como buffer
|
|
337
|
-
const buffer = fs_1.default.readFileSync(outputPath);
|
|
338
|
-
// Limpiar archivo temporal
|
|
339
|
-
fs_1.default.unlinkSync(outputPath);
|
|
340
|
-
resolve(buffer);
|
|
341
|
-
}
|
|
342
|
-
catch (error) {
|
|
328
|
+
// Primero obtenemos la duración del video para calcular un timestamp seguro
|
|
329
|
+
fluent_ffmpeg_1.default.ffprobe(videoPath, (error, metadata) => {
|
|
330
|
+
if (error) {
|
|
343
331
|
reject(error);
|
|
332
|
+
return;
|
|
344
333
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
334
|
+
const duration = metadata.format.duration || 0;
|
|
335
|
+
// Usar el 10% de la duración o máximo 10 segundos, mínimo 1 segundo
|
|
336
|
+
const timestamp = Math.min(Math.max(duration * 0.1, 1), 10);
|
|
337
|
+
(0, fluent_ffmpeg_1.default)(videoPath)
|
|
338
|
+
.screenshots({
|
|
339
|
+
timestamps: [timestamp],
|
|
340
|
+
filename: outputFilename,
|
|
341
|
+
folder: tempDir,
|
|
342
|
+
size,
|
|
343
|
+
quality,
|
|
344
|
+
})
|
|
345
|
+
.on('end', () => {
|
|
346
|
+
try {
|
|
347
|
+
// Leer el archivo como buffer
|
|
348
|
+
console.log('leer archivo como buffer');
|
|
349
|
+
const buffer = fs_1.default.readFileSync(outputPath);
|
|
350
|
+
console.log('leer archivo como buffer done');
|
|
351
|
+
// Limpiar archivo temporal
|
|
350
352
|
fs_1.default.unlinkSync(outputPath);
|
|
353
|
+
console.log('remove done');
|
|
354
|
+
resolve(buffer);
|
|
351
355
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
356
|
+
catch (error) {
|
|
357
|
+
reject(error);
|
|
358
|
+
}
|
|
359
|
+
})
|
|
360
|
+
.on('error', (error) => {
|
|
361
|
+
// Limpiar archivo temporal en caso de error
|
|
362
|
+
try {
|
|
363
|
+
if (fs_1.default.existsSync(outputPath)) {
|
|
364
|
+
fs_1.default.unlinkSync(outputPath);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
catch (cleanupError) {
|
|
368
|
+
// eslint-disable-next-line no-console
|
|
369
|
+
console.error('Error limpiando archivo temporal:', cleanupError);
|
|
370
|
+
}
|
|
371
|
+
reject(error);
|
|
372
|
+
});
|
|
358
373
|
});
|
|
359
374
|
});
|
|
360
375
|
});
|
|
@@ -407,17 +422,27 @@ const resizeImage = (data, filePath, mimetype) => __awaiter(void 0, void 0, void
|
|
|
407
422
|
const rotateOrientationImage = (data, filePath, image = null, mimetype) => __awaiter(void 0, void 0, void 0, function* () {
|
|
408
423
|
if (mimetype.includes('webp'))
|
|
409
424
|
return data;
|
|
410
|
-
|
|
411
|
-
|
|
425
|
+
let processedImage;
|
|
426
|
+
if (image) {
|
|
427
|
+
processedImage = image;
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
processedImage = yield jimp_1.default.read(filePath);
|
|
431
|
+
}
|
|
412
432
|
const orientation = yield exifr_1.default.orientation(data);
|
|
433
|
+
// Validar que orientation existe y es un número válido
|
|
434
|
+
if (typeof orientation !== 'number') {
|
|
435
|
+
return processedImage.getBufferAsync(jimp_1.default.MIME_JPEG);
|
|
436
|
+
}
|
|
413
437
|
let rotate;
|
|
414
438
|
if ([7, 8].includes(orientation))
|
|
415
439
|
rotate = 90;
|
|
416
440
|
else if ([3].includes(orientation))
|
|
417
441
|
rotate = 180;
|
|
418
|
-
else if ([5,
|
|
442
|
+
else if ([5, 6].includes(orientation))
|
|
419
443
|
rotate = -90;
|
|
420
|
-
if (rotate)
|
|
421
|
-
|
|
422
|
-
|
|
444
|
+
if (rotate) {
|
|
445
|
+
processedImage = yield processedImage.rotate(rotate);
|
|
446
|
+
}
|
|
447
|
+
return processedImage.getBufferAsync(jimp_1.default.MIME_JPEG);
|
|
423
448
|
});
|
|
@@ -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;AAubF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|