@runnerpro/backend 1.12.20 → 1.12.22

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.
@@ -227,7 +227,6 @@ const sendMessage = (req, res, { sendNotification, firebaseMessaging, isClient }
227
227
  idCliente,
228
228
  isClient,
229
229
  });
230
- console.log(req.body);
231
230
  // Enviado cuando es un mensaje de comentario sobre intelligence
232
231
  if (newMessage) {
233
232
  type = 6;
@@ -277,11 +276,17 @@ const sendFile = (req, res, { sendNotification, firebaseMessaging, isClient, buc
277
276
  const { userid } = req.session;
278
277
  const filePath = path_1.default.join('./uploads', req.file.filename);
279
278
  if (req.file.mimetype.includes('video')) {
280
- console.log('es video');
281
- [duration, thumbnail] = yield Promise.all([getVideoDuration(filePath), getThumbnailFromVideo(filePath)]);
282
- console.log('duration and thumbnail done');
279
+ console.time('getVideoDuration');
280
+ duration = yield getVideoDuration(filePath);
281
+ console.timeEnd('getVideoDuration');
282
+ console.time('getThumbnailFromVideo');
283
+ thumbnail = yield getThumbnailFromVideo(filePath, duration);
284
+ console.timeEnd('getThumbnailFromVideo');
283
285
  }
286
+ console.time('query');
284
287
  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');
285
290
  const fileData = fs_1.default.readFileSync(filePath);
286
291
  const files = [];
287
292
  if (req.file.mimetype.includes('image')) {
@@ -302,10 +307,13 @@ const sendFile = (req, res, { sendNotification, firebaseMessaging, isClient, buc
302
307
  else {
303
308
  files.push({ data: fileData, id: idFile });
304
309
  }
310
+ console.timeEnd('readFileSync');
311
+ res.send({ idFile });
312
+ console.time('saveFile');
305
313
  for (const file of files) {
306
314
  yield bucket.file(`Chat/${file.id}`).save(file.data);
307
315
  }
308
- res.send({ idFile });
316
+ console.timeEnd('saveFile');
309
317
  fs_1.default.unlinkSync(filePath);
310
318
  if (!isClient) {
311
319
  const [cliente] = yield (0, index_1.query)('SELECT [PREFERRED LANGUAGE] FROM [CLIENTE] WHERE [ID] = ?', [idCliente]);
@@ -317,59 +325,47 @@ const sendFile = (req, res, { sendNotification, firebaseMessaging, isClient, buc
317
325
  });
318
326
  }
319
327
  });
320
- const getThumbnailFromVideo = (videoPath) => __awaiter(void 0, void 0, void 0, function* () {
328
+ const getThumbnailFromVideo = (videoPath, duration) => __awaiter(void 0, void 0, void 0, function* () {
321
329
  const size = '640x480';
322
330
  const quality = 2;
323
331
  const tempDir = path_1.default.join('./uploads');
324
332
  const outputFilename = `thumbnail_${Date.now()}.png`;
325
333
  const outputPath = path_1.default.join(tempDir, outputFilename);
326
- console.log('getThumbnailFromVideo', { outputPath, outputFilename, tempDir });
334
+ // Usar el 10% de la duración o máximo 10 segundos, mínimo 1 segundo
335
+ const timestamp = Math.min(Math.max(duration * 0.1, 1), 10);
327
336
  return new Promise((resolve, reject) => {
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) {
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
+ const buffer = fs_1.default.readFileSync(outputPath);
349
+ // Limpiar archivo temporal
350
+ fs_1.default.unlinkSync(outputPath);
351
+ resolve(buffer);
352
+ }
353
+ catch (error) {
331
354
  reject(error);
332
- return;
333
355
  }
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
+ })
357
+ .on('error', (error) => {
358
+ // Limpiar archivo temporal en caso de error
359
+ try {
360
+ if (fs_1.default.existsSync(outputPath)) {
352
361
  fs_1.default.unlinkSync(outputPath);
353
- console.log('remove done');
354
- resolve(buffer);
355
362
  }
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
- });
363
+ }
364
+ catch (cleanupError) {
365
+ // eslint-disable-next-line no-console
366
+ console.error('Error limpiando archivo temporal:', cleanupError);
367
+ }
368
+ reject(error);
373
369
  });
374
370
  });
375
371
  });
@@ -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;AAubF,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;AA6aF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runnerpro/backend",
3
- "version": "1.12.20",
3
+ "version": "1.12.22",
4
4
  "description": "A collection of common backend functions",
5
5
  "exports": {
6
6
  ".": "./lib/cjs/index.js"