@runnerpro/backend 1.12.1 → 1.12.3
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.
|
@@ -35,7 +35,6 @@ const index_2 = require("../../locale/index");
|
|
|
35
35
|
const multer_1 = __importDefault(require("multer"));
|
|
36
36
|
const axios_1 = __importDefault(require("axios"));
|
|
37
37
|
const saveResponseTime_1 = require("../saveResponseTime");
|
|
38
|
-
const sendMail_1 = require("../../sendMail");
|
|
39
38
|
const fluent_ffmpeg_1 = __importDefault(require("fluent-ffmpeg"));
|
|
40
39
|
const ffmpeg_static_1 = __importDefault(require("ffmpeg-static"));
|
|
41
40
|
const ffprobe_static_1 = __importDefault(require("ffprobe-static"));
|
|
@@ -256,13 +255,7 @@ const sendFile = (req, res, { sendNotification, firebaseMessaging, isClient, buc
|
|
|
256
255
|
const { userid } = req.session;
|
|
257
256
|
const filePath = path_1.default.join('./uploads', req.file.filename);
|
|
258
257
|
if (req.file.mimetype.includes('video')) {
|
|
259
|
-
(
|
|
260
|
-
to: ['david.jimenez@runnerpro.app'],
|
|
261
|
-
subject: 'Video',
|
|
262
|
-
body: JSON.stringify(req.file),
|
|
263
|
-
title: '',
|
|
264
|
-
});
|
|
265
|
-
duration = yield getDurationFromVideo(filePath);
|
|
258
|
+
duration = yield getVideoDuration(filePath);
|
|
266
259
|
}
|
|
267
260
|
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]);
|
|
268
261
|
const fileData = fs_1.default.readFileSync(filePath);
|
|
@@ -281,12 +274,6 @@ const sendFile = (req, res, { sendNotification, firebaseMessaging, isClient, buc
|
|
|
281
274
|
else if (req.file.mimetype.includes('video')) {
|
|
282
275
|
// Si es vídeo, se guarda el vídeo original, la duración y un thumbnail
|
|
283
276
|
const thumbnail = yield getThumbnailFromVideo(filePath);
|
|
284
|
-
(0, sendMail_1.sendMail)({
|
|
285
|
-
to: ['david.jimenez@runnerpro.app'],
|
|
286
|
-
subject: 'Video 4',
|
|
287
|
-
body: JSON.stringify(thumbnail),
|
|
288
|
-
title: '',
|
|
289
|
-
});
|
|
290
277
|
files.push({ data: fileData, id: idFile });
|
|
291
278
|
files.push({ data: thumbnail, id: `${idFile}-thumbnail` });
|
|
292
279
|
}
|
|
@@ -312,21 +299,9 @@ const getThumbnailFromVideo = (videoPath) => __awaiter(void 0, void 0, void 0, f
|
|
|
312
299
|
const timestamp = 10;
|
|
313
300
|
const size = '640x480';
|
|
314
301
|
const quality = 2;
|
|
315
|
-
(0, sendMail_1.sendMail)({
|
|
316
|
-
to: ['david.jimenez@runnerpro.app'],
|
|
317
|
-
subject: 'Video 2',
|
|
318
|
-
body: JSON.stringify(videoPath),
|
|
319
|
-
title: '',
|
|
320
|
-
});
|
|
321
302
|
const tempDir = path_1.default.join('./uploads');
|
|
322
303
|
const outputFilename = `thumbnail_${Date.now()}.png`;
|
|
323
304
|
const outputPath = path_1.default.join(tempDir, outputFilename);
|
|
324
|
-
(0, sendMail_1.sendMail)({
|
|
325
|
-
to: ['david.jimenez@runnerpro.app'],
|
|
326
|
-
subject: 'Video 3',
|
|
327
|
-
body: JSON.stringify({ tempDir, outputFilename, outputPath }),
|
|
328
|
-
title: '',
|
|
329
|
-
});
|
|
330
305
|
return new Promise((resolve, reject) => {
|
|
331
306
|
(0, fluent_ffmpeg_1.default)(videoPath)
|
|
332
307
|
.screenshots({
|
|
@@ -337,17 +312,57 @@ const getThumbnailFromVideo = (videoPath) => __awaiter(void 0, void 0, void 0, f
|
|
|
337
312
|
quality,
|
|
338
313
|
})
|
|
339
314
|
.on('end', () => {
|
|
340
|
-
|
|
341
|
-
|
|
315
|
+
try {
|
|
316
|
+
// Leer el archivo como buffer
|
|
317
|
+
const buffer = fs_1.default.readFileSync(outputPath);
|
|
318
|
+
// Limpiar archivo temporal
|
|
319
|
+
fs_1.default.unlinkSync(outputPath);
|
|
320
|
+
console.log(`Thumbnail generado: ${buffer.length} bytes`);
|
|
321
|
+
resolve(buffer);
|
|
322
|
+
}
|
|
323
|
+
catch (error) {
|
|
324
|
+
console.error('Error leyendo archivo temporal:', error);
|
|
325
|
+
reject(error);
|
|
326
|
+
}
|
|
342
327
|
})
|
|
343
328
|
.on('error', (err) => {
|
|
329
|
+
// Limpiar archivo temporal en caso de error
|
|
330
|
+
try {
|
|
331
|
+
if (fs_1.default.existsSync(outputPath)) {
|
|
332
|
+
fs_1.default.unlinkSync(outputPath);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
catch (cleanupError) {
|
|
336
|
+
console.error('Error limpiando archivo temporal:', cleanupError);
|
|
337
|
+
}
|
|
344
338
|
console.error('Error generando thumbnail:', err);
|
|
345
339
|
reject(err);
|
|
346
340
|
});
|
|
347
341
|
});
|
|
348
342
|
});
|
|
349
|
-
const
|
|
350
|
-
return
|
|
343
|
+
const getVideoDuration = (videoPath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
344
|
+
return new Promise((resolve, reject) => {
|
|
345
|
+
fluent_ffmpeg_1.default.ffprobe(videoPath, (err, metadata) => {
|
|
346
|
+
if (err) {
|
|
347
|
+
console.error('Error con ffprobe:', err);
|
|
348
|
+
reject(err);
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
try {
|
|
352
|
+
const duration = metadata.format.duration;
|
|
353
|
+
if (!duration || isNaN(duration)) {
|
|
354
|
+
throw new Error('No se pudo obtener la duración del video');
|
|
355
|
+
}
|
|
356
|
+
const durationInSeconds = parseFloat(duration);
|
|
357
|
+
console.log(`Duración del video: ${durationInSeconds} segundos`);
|
|
358
|
+
resolve(durationInSeconds);
|
|
359
|
+
}
|
|
360
|
+
catch (error) {
|
|
361
|
+
console.error('Error procesando metadata:', error);
|
|
362
|
+
reject(error);
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
});
|
|
351
366
|
});
|
|
352
367
|
const readMessage = (req, res, { isClient }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
353
368
|
const { idCliente } = req.body;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../../../src/chat/api/conversation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../../../src/chat/api/conversation.ts"],"names":[],"mappings":"AAkBA,QAAA,MAAM,iBAAiB,0BAA2B,GAAG,SAoBpD,CAAC;AAiYF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|