@runnerpro/backend 1.12.19 → 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.
@@ -318,49 +318,58 @@ const sendFile = (req, res, { sendNotification, firebaseMessaging, isClient, buc
318
318
  }
319
319
  });
320
320
  const getThumbnailFromVideo = (videoPath) => __awaiter(void 0, void 0, void 0, function* () {
321
- const timestamp = 10;
322
321
  const size = '640x480';
323
322
  const quality = 2;
324
323
  const tempDir = path_1.default.join('./uploads');
325
324
  const outputFilename = `thumbnail_${Date.now()}.png`;
326
325
  const outputPath = path_1.default.join(tempDir, outputFilename);
327
- console.log('getThumbnailFromVideo');
326
+ console.log('getThumbnailFromVideo', { outputPath, outputFilename, tempDir });
328
327
  return new Promise((resolve, reject) => {
329
- (0, fluent_ffmpeg_1.default)(videoPath)
330
- .screenshots({
331
- timestamps: [timestamp],
332
- filename: outputFilename,
333
- folder: tempDir,
334
- size,
335
- quality,
336
- })
337
- .on('end', () => {
338
- try {
339
- // Leer el archivo como buffer
340
- console.log('leer archivo como buffer');
341
- const buffer = fs_1.default.readFileSync(outputPath);
342
- console.log('leer archivo como buffer done');
343
- // Limpiar archivo temporal
344
- fs_1.default.unlinkSync(outputPath);
345
- console.log('remove done');
346
- resolve(buffer);
347
- }
348
- 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) {
349
331
  reject(error);
332
+ return;
350
333
  }
351
- })
352
- .on('error', (error) => {
353
- // Limpiar archivo temporal en caso de error
354
- try {
355
- if (fs_1.default.existsSync(outputPath)) {
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
356
352
  fs_1.default.unlinkSync(outputPath);
353
+ console.log('remove done');
354
+ resolve(buffer);
357
355
  }
358
- }
359
- catch (cleanupError) {
360
- // eslint-disable-next-line no-console
361
- console.error('Error limpiando archivo temporal:', cleanupError);
362
- }
363
- reject(error);
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
+ });
364
373
  });
365
374
  });
366
375
  });
@@ -413,17 +422,27 @@ const resizeImage = (data, filePath, mimetype) => __awaiter(void 0, void 0, void
413
422
  const rotateOrientationImage = (data, filePath, image = null, mimetype) => __awaiter(void 0, void 0, void 0, function* () {
414
423
  if (mimetype.includes('webp'))
415
424
  return data;
416
- if (!image)
417
- image = yield jimp_1.default.read(filePath);
425
+ let processedImage;
426
+ if (image) {
427
+ processedImage = image;
428
+ }
429
+ else {
430
+ processedImage = yield jimp_1.default.read(filePath);
431
+ }
418
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
+ }
419
437
  let rotate;
420
438
  if ([7, 8].includes(orientation))
421
439
  rotate = 90;
422
440
  else if ([3].includes(orientation))
423
441
  rotate = 180;
424
- else if ([5, 8].includes(orientation))
442
+ else if ([5, 6].includes(orientation))
425
443
  rotate = -90;
426
- if (rotate)
427
- image = yield image.rotate(rotate);
428
- return image.getBufferAsync(jimp_1.default.MIME_JPEG);
444
+ if (rotate) {
445
+ processedImage = yield processedImage.rotate(rotate);
446
+ }
447
+ return processedImage.getBufferAsync(jimp_1.default.MIME_JPEG);
429
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;AA4ZF,OAAO,EAAE,iBAAiB,EAAE,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runnerpro/backend",
3
- "version": "1.12.19",
3
+ "version": "1.12.20",
4
4
  "description": "A collection of common backend functions",
5
5
  "exports": {
6
6
  ".": "./lib/cjs/index.js"