@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.
|
|
281
|
-
|
|
282
|
-
console.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
329
|
-
|
|
330
|
-
|
|
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
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
.
|
|
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
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
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;
|
|
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"}
|