@runnerpro/backend 1.12.0 → 1.12.2
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,11 @@ 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
|
|
38
|
+
const fluent_ffmpeg_1 = __importDefault(require("fluent-ffmpeg"));
|
|
39
|
+
const ffmpeg_static_1 = __importDefault(require("ffmpeg-static"));
|
|
40
|
+
const ffprobe_static_1 = __importDefault(require("ffprobe-static"));
|
|
41
|
+
fluent_ffmpeg_1.default.setFfmpegPath(ffmpeg_static_1.default);
|
|
42
|
+
fluent_ffmpeg_1.default.setFfprobePath(ffprobe_static_1.default.path);
|
|
39
43
|
const conversationRoute = (_a) => {
|
|
40
44
|
var { router } = _a, params = __rest(_a, ["router"]);
|
|
41
45
|
const uploadFile = (0, multer_1.default)({
|
|
@@ -249,17 +253,11 @@ const sendFile = (req, res, { sendNotification, firebaseMessaging, isClient, buc
|
|
|
249
253
|
const { idCliente, type } = req.body;
|
|
250
254
|
let { duration } = req.body;
|
|
251
255
|
const { userid } = req.session;
|
|
256
|
+
const filePath = path_1.default.join('./uploads', req.file.filename);
|
|
252
257
|
if (req.file.mimetype.includes('video')) {
|
|
253
|
-
(
|
|
254
|
-
to: ['david.jimenez@runnerpro.app'],
|
|
255
|
-
subject: 'Video',
|
|
256
|
-
body: JSON.stringify(req.file),
|
|
257
|
-
title: '',
|
|
258
|
-
});
|
|
259
|
-
duration = yield getDurationFromVideo(req.file.buffer, req.file.mimetype);
|
|
258
|
+
duration = yield getDurationFromVideo(filePath);
|
|
260
259
|
}
|
|
261
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]);
|
|
262
|
-
const filePath = path_1.default.join('./uploads', req.file.filename);
|
|
263
261
|
const fileData = fs_1.default.readFileSync(filePath);
|
|
264
262
|
const files = [];
|
|
265
263
|
if (req.file.mimetype.includes('image')) {
|
|
@@ -275,7 +273,7 @@ const sendFile = (req, res, { sendNotification, firebaseMessaging, isClient, buc
|
|
|
275
273
|
}
|
|
276
274
|
else if (req.file.mimetype.includes('video')) {
|
|
277
275
|
// Si es vídeo, se guarda el vídeo original, la duración y un thumbnail
|
|
278
|
-
const thumbnail = yield getThumbnailFromVideo(
|
|
276
|
+
const thumbnail = yield getThumbnailFromVideo(filePath);
|
|
279
277
|
files.push({ data: fileData, id: idFile });
|
|
280
278
|
files.push({ data: thumbnail, id: `${idFile}-thumbnail` });
|
|
281
279
|
}
|
|
@@ -297,13 +295,52 @@ const sendFile = (req, res, { sendNotification, firebaseMessaging, isClient, buc
|
|
|
297
295
|
}
|
|
298
296
|
res.send({ idFile });
|
|
299
297
|
});
|
|
300
|
-
const getThumbnailFromVideo = (
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
const
|
|
304
|
-
|
|
298
|
+
const getThumbnailFromVideo = (videoPath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
299
|
+
const timestamp = 10;
|
|
300
|
+
const size = '640x480';
|
|
301
|
+
const quality = 2;
|
|
302
|
+
const tempDir = path_1.default.join('./uploads');
|
|
303
|
+
const outputFilename = `thumbnail_${Date.now()}.png`;
|
|
304
|
+
const outputPath = path_1.default.join(tempDir, outputFilename);
|
|
305
|
+
return new Promise((resolve, reject) => {
|
|
306
|
+
(0, fluent_ffmpeg_1.default)(videoPath)
|
|
307
|
+
.screenshots({
|
|
308
|
+
timestamps: [timestamp],
|
|
309
|
+
filename: outputFilename,
|
|
310
|
+
folder: tempDir,
|
|
311
|
+
size,
|
|
312
|
+
quality,
|
|
313
|
+
})
|
|
314
|
+
.on('end', () => {
|
|
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
|
+
}
|
|
327
|
+
})
|
|
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
|
+
}
|
|
338
|
+
console.error('Error generando thumbnail:', err);
|
|
339
|
+
reject(err);
|
|
340
|
+
});
|
|
341
|
+
});
|
|
305
342
|
});
|
|
306
|
-
const getDurationFromVideo = (
|
|
343
|
+
const getDurationFromVideo = (filePath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
307
344
|
return 10;
|
|
308
345
|
});
|
|
309
346
|
const readMessage = (req, res, { isClient }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -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":"AAmBA,QAAA,MAAM,iBAAiB,0BAA2B,GAAG,SAoBpD,CAAC;AAyWF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runnerpro/backend",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.2",
|
|
4
4
|
"description": "A collection of common backend functions",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./lib/cjs/index.js"
|
|
@@ -66,11 +66,13 @@
|
|
|
66
66
|
"@google-cloud/translate": "^8.3.0",
|
|
67
67
|
"@notionhq/client": "^2.2.15",
|
|
68
68
|
"exifr": "^7.1.3",
|
|
69
|
+
"ffmpeg-static": "^5.2.0",
|
|
70
|
+
"ffprobe-static": "^3.1.0",
|
|
69
71
|
"firebase-admin": "^11.10.1",
|
|
72
|
+
"fluent-ffmpeg": "^2.1.3",
|
|
70
73
|
"googleapis": "^144.0.0",
|
|
71
74
|
"multer": "^1.4.5-lts.1",
|
|
72
75
|
"oauth-signature": "1.5.0",
|
|
73
76
|
"socket.io": "^4.7.2"
|
|
74
77
|
}
|
|
75
78
|
}
|
|
76
|
-
|