@runnerpro/backend 1.12.25 → 1.13.0

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.
@@ -214,13 +214,17 @@ const getChatFile = ({ bucket, id, isClient, userid }) => __awaiter(void 0, void
214
214
  }
215
215
  });
216
216
  const sendMessage = (req, res, { sendNotification, firebaseMessaging, isClient }) => __awaiter(void 0, void 0, void 0, function* () {
217
- const { text, replyMessageId, new: newMessage } = req.body;
217
+ const { replyMessageId, new: newMessage } = req.body;
218
+ let { text } = req.body;
218
219
  const { userid } = req.session;
219
220
  const idCliente = isClient ? req.session.userid : req.body.idCliente;
220
221
  let idWorkout, type = 1;
221
- // Si es entrenador, se marca leído cuando se envía un mensaje
222
- if (!isClient)
222
+ if (!isClient) {
223
+ // Si es entrenador, se marca leído cuando se envía un mensaje
223
224
  yield markReadMessage({ isClient, idCliente });
225
+ // Cambiar el tono del texto a uno neutro y corregir la ortografía
226
+ text = cambiarTonoEntrenadorNeutro(text);
227
+ }
224
228
  // Devuelve el texto en el otro idioma si el cliente no habla español y el idioma del cliente
225
229
  const { textSpanish, textPreferredLanguage, preferredLanguage } = yield getPreferredLanguageForChat({
226
230
  text,
@@ -276,17 +280,10 @@ const sendFile = (req, res, { sendNotification, firebaseMessaging, isClient, buc
276
280
  const { userid } = req.session;
277
281
  const filePath = path_1.default.join('./uploads', req.file.filename);
278
282
  if (req.file.mimetype.includes('video')) {
279
- console.time('getVideoDuration');
280
283
  duration = yield getVideoDuration(filePath);
281
- console.timeEnd('getVideoDuration');
282
- console.time('getThumbnailFromVideo');
283
284
  thumbnail = yield getThumbnailFromVideo(filePath, duration);
284
- console.timeEnd('getThumbnailFromVideo');
285
285
  }
286
- console.time('query');
287
286
  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');
290
287
  const fileData = fs_1.default.readFileSync(filePath);
291
288
  const files = [];
292
289
  if (req.file.mimetype.includes('image')) {
@@ -307,13 +304,10 @@ const sendFile = (req, res, { sendNotification, firebaseMessaging, isClient, buc
307
304
  else {
308
305
  files.push({ data: fileData, id: idFile });
309
306
  }
310
- console.timeEnd('readFileSync');
311
307
  res.send({ idFile });
312
- console.time('saveFile');
313
308
  for (const file of files) {
314
309
  yield bucket.file(`Chat/${file.id}`).save(file.data);
315
310
  }
316
- console.timeEnd('saveFile');
317
311
  fs_1.default.unlinkSync(filePath);
318
312
  if (!isClient) {
319
313
  const [cliente] = yield (0, index_1.query)('SELECT [PREFERRED LANGUAGE] FROM [CLIENTE] WHERE [ID] = ?', [idCliente]);
@@ -328,7 +322,6 @@ const sendFile = (req, res, { sendNotification, firebaseMessaging, isClient, buc
328
322
  const getThumbnailFromVideo = (videoPath, duration) => __awaiter(void 0, void 0, void 0, function* () {
329
323
  const targetWidth = 500;
330
324
  const targetHeight = 400;
331
- const quality = 2;
332
325
  const tempDir = path_1.default.join('./uploads');
333
326
  const outputFilename = `thumbnail_${Date.now()}.png`;
334
327
  const outputPath = path_1.default.join(tempDir, outputFilename);
@@ -406,6 +399,9 @@ const markReadMessage = ({ isClient, idCliente }) => __awaiter(void 0, void 0, v
406
399
  if (!isClient)
407
400
  yield (0, saveResponseTime_1.saveResponseTime)(idCliente);
408
401
  });
402
+ const cambiarTonoEntrenadorNeutro = (text) => {
403
+ return text;
404
+ };
409
405
  const resizeImage = (data, filePath, mimetype) => __awaiter(void 0, void 0, void 0, function* () {
410
406
  if (mimetype.includes('webp'))
411
407
  return data;
@@ -423,27 +419,17 @@ const resizeImage = (data, filePath, mimetype) => __awaiter(void 0, void 0, void
423
419
  const rotateOrientationImage = (data, filePath, image = null, mimetype) => __awaiter(void 0, void 0, void 0, function* () {
424
420
  if (mimetype.includes('webp'))
425
421
  return data;
426
- let processedImage;
427
- if (image) {
428
- processedImage = image;
429
- }
430
- else {
431
- processedImage = yield jimp_1.default.read(filePath);
432
- }
422
+ if (!image)
423
+ image = yield jimp_1.default.read(filePath);
433
424
  const orientation = yield exifr_1.default.orientation(data);
434
- // Validar que orientation existe y es un número válido
435
- if (typeof orientation !== 'number') {
436
- return processedImage.getBufferAsync(jimp_1.default.MIME_JPEG);
437
- }
438
425
  let rotate;
439
426
  if ([7, 8].includes(orientation))
440
427
  rotate = 90;
441
428
  else if ([3].includes(orientation))
442
429
  rotate = 180;
443
- else if ([5, 6].includes(orientation))
430
+ else if ([5, 8].includes(orientation))
444
431
  rotate = -90;
445
- if (rotate) {
446
- processedImage = yield processedImage.rotate(rotate);
447
- }
448
- return processedImage.getBufferAsync(jimp_1.default.MIME_JPEG);
432
+ if (rotate)
433
+ image = yield image.rotate(rotate);
434
+ return image.getBufferAsync(jimp_1.default.MIME_JPEG);
449
435
  });
@@ -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;AAkbF,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;AAgaF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runnerpro/backend",
3
- "version": "1.12.25",
3
+ "version": "1.13.0",
4
4
  "description": "A collection of common backend functions",
5
5
  "exports": {
6
6
  ".": "./lib/cjs/index.js"
@@ -64,6 +64,7 @@
64
64
  "dependencies": {
65
65
  "@google-cloud/storage": "^7.11.3",
66
66
  "@google-cloud/translate": "^8.3.0",
67
+ "@google-cloud/vertexai": "^1.10.0",
67
68
  "@notionhq/client": "^2.2.15",
68
69
  "exifr": "^7.1.3",
69
70
  "ffmpeg-static": "^5.2.0",