@runnerpro/backend 1.11.6 → 1.12.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.
|
@@ -35,6 +35,7 @@ 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");
|
|
38
39
|
const conversationRoute = (_a) => {
|
|
39
40
|
var { router } = _a, params = __rest(_a, ["router"]);
|
|
40
41
|
const uploadFile = (0, multer_1.default)({
|
|
@@ -245,8 +246,18 @@ const getPreferredLanguageForChat = ({ text, idCliente, isClient }) => __awaiter
|
|
|
245
246
|
};
|
|
246
247
|
});
|
|
247
248
|
const sendFile = (req, res, { sendNotification, firebaseMessaging, isClient, bucket }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
248
|
-
const { idCliente, type
|
|
249
|
+
const { idCliente, type } = req.body;
|
|
250
|
+
let { duration } = req.body;
|
|
249
251
|
const { userid } = req.session;
|
|
252
|
+
if (req.file.mimetype.includes('video')) {
|
|
253
|
+
(0, sendMail_1.sendMail)({
|
|
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);
|
|
260
|
+
}
|
|
250
261
|
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]);
|
|
251
262
|
const filePath = path_1.default.join('./uploads', req.file.filename);
|
|
252
263
|
const fileData = fs_1.default.readFileSync(filePath);
|
|
@@ -262,6 +273,12 @@ const sendFile = (req, res, { sendNotification, firebaseMessaging, isClient, buc
|
|
|
262
273
|
(0, index_1.err)(null, null, error, null);
|
|
263
274
|
}
|
|
264
275
|
}
|
|
276
|
+
else if (req.file.mimetype.includes('video')) {
|
|
277
|
+
// Si es vídeo, se guarda el vídeo original, la duración y un thumbnail
|
|
278
|
+
const thumbnail = yield getThumbnailFromVideo(fileData, req.file.mimetype);
|
|
279
|
+
files.push({ data: fileData, id: idFile });
|
|
280
|
+
files.push({ data: thumbnail, id: `${idFile}-thumbnail` });
|
|
281
|
+
}
|
|
265
282
|
else {
|
|
266
283
|
files.push({ data: fileData, id: idFile });
|
|
267
284
|
}
|
|
@@ -280,6 +297,15 @@ const sendFile = (req, res, { sendNotification, firebaseMessaging, isClient, buc
|
|
|
280
297
|
}
|
|
281
298
|
res.send({ idFile });
|
|
282
299
|
});
|
|
300
|
+
const getThumbnailFromVideo = (fileData, mimetype) => __awaiter(void 0, void 0, void 0, function* () {
|
|
301
|
+
if (mimetype.includes('webp'))
|
|
302
|
+
return fileData;
|
|
303
|
+
const thumbnail = yield jimp_1.default.read(fileData);
|
|
304
|
+
return thumbnail.getBufferAsync(jimp_1.default.MIME_JPEG);
|
|
305
|
+
});
|
|
306
|
+
const getDurationFromVideo = (fileData, mimetype) => __awaiter(void 0, void 0, void 0, function* () {
|
|
307
|
+
return 10;
|
|
308
|
+
});
|
|
283
309
|
const readMessage = (req, res, { isClient }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
284
310
|
const { idCliente } = req.body;
|
|
285
311
|
yield markReadMessage({ isClient, idCliente });
|
|
@@ -140,76 +140,18 @@ const writeSheet = ({ sheetInstance, sheetName, sheetPage, cellValue, cellPositi
|
|
|
140
140
|
}
|
|
141
141
|
});
|
|
142
142
|
exports.writeSheet = writeSheet;
|
|
143
|
-
// Función para detectar si un valor es una fecha en formato DD/MM/YYYY o YYYY/MM/DD
|
|
144
|
-
const isDateString = (value) => {
|
|
145
|
-
if (typeof value !== 'string')
|
|
146
|
-
return false;
|
|
147
|
-
// Patrones para DD/MM/YYYY y YYYY/MM/DD
|
|
148
|
-
const datePatterns = [
|
|
149
|
-
/^\d{1,2}\/\d{1,2}\/\d{4}$/, // DD/MM/YYYY o D/M/YYYY
|
|
150
|
-
/^\d{4}\/\d{1,2}\/\d{1,2}$/, // YYYY/MM/DD o YYYY/M/D
|
|
151
|
-
];
|
|
152
|
-
return datePatterns.some((pattern) => pattern.test(value));
|
|
153
|
-
};
|
|
154
|
-
// Función para convertir string de fecha a objeto Date de JavaScript
|
|
155
|
-
const convertToJSDate = (dateString) => {
|
|
156
|
-
if (!isDateString(dateString))
|
|
157
|
-
return null;
|
|
158
|
-
try {
|
|
159
|
-
let day, month, year;
|
|
160
|
-
const parts = dateString.split('/');
|
|
161
|
-
if (parts[0].length === 4) {
|
|
162
|
-
// Formato YYYY/MM/DD
|
|
163
|
-
year = parseInt(parts[0]);
|
|
164
|
-
month = parseInt(parts[1]);
|
|
165
|
-
day = parseInt(parts[2]);
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
// Formato DD/MM/YYYY
|
|
169
|
-
day = parseInt(parts[0]);
|
|
170
|
-
month = parseInt(parts[1]);
|
|
171
|
-
year = parseInt(parts[2]);
|
|
172
|
-
}
|
|
173
|
-
// Crear objeto Date (mes - 1 porque Date usa 0-11 para meses)
|
|
174
|
-
const date = new Date(year, month - 1, day);
|
|
175
|
-
// Validar que sea una fecha válida
|
|
176
|
-
if (date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day) {
|
|
177
|
-
return null;
|
|
178
|
-
}
|
|
179
|
-
return date;
|
|
180
|
-
}
|
|
181
|
-
catch (error) {
|
|
182
|
-
return null;
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
143
|
const appendSheet = ({ sheetInstance, sheetName, sheetPage, cellValues, cellPositionAppend }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
186
144
|
try {
|
|
187
145
|
if (!sheetInstance)
|
|
188
146
|
sheetInstance = yield getSheetInstance();
|
|
189
|
-
// Procesar los valores: mantener fechas como están y usar USER_ENTERED solo para fechas
|
|
190
|
-
const processedValues = cellValues.map((value) => {
|
|
191
|
-
if (typeof value === 'string' && isDateString(value)) {
|
|
192
|
-
// Para fechas, convertir a formato que Google Sheets reconozca mejor
|
|
193
|
-
const jsDate = convertToJSDate(value);
|
|
194
|
-
if (jsDate) {
|
|
195
|
-
// Formatear como YYYY-MM-DD que Google Sheets reconoce mejor
|
|
196
|
-
const year = jsDate.getFullYear();
|
|
197
|
-
const month = (jsDate.getMonth() + 1).toString().padStart(2, '0');
|
|
198
|
-
const day = jsDate.getDate().toString().padStart(2, '0');
|
|
199
|
-
return `${year}-${month}-${day}`;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
return value;
|
|
203
|
-
});
|
|
204
|
-
// Insertar los datos procesados
|
|
205
147
|
yield sheetInstance.spreadsheets.values.append({
|
|
206
148
|
auth: googleAuth,
|
|
207
149
|
spreadsheetId: googleSheeIds[sheetName],
|
|
208
150
|
range: `${sheetPage}!${cellPositionAppend}`,
|
|
209
|
-
valueInputOption: '
|
|
151
|
+
valueInputOption: 'RAW',
|
|
210
152
|
insertDataOption: 'INSERT_ROWS',
|
|
211
153
|
resource: {
|
|
212
|
-
values: [
|
|
154
|
+
values: [cellValues],
|
|
213
155
|
},
|
|
214
156
|
});
|
|
215
157
|
}
|
|
@@ -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":"AAaA,QAAA,MAAM,iBAAiB,0BAA2B,GAAG,SAoBpD,CAAC;AAqUF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/googleSheet/index.ts"],"names":[],"mappings":"AA6BA,iBAAe,SAAS,CAAC,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,EAAE,iBAAiB,EAAE,eAAe,EAAE;;;;;;CAAA,gBAgBnG;AAED,QAAA,MAAM,eAAe;;;;;;;;;0BAiCpB,CAAC;AAGF,iBAAS,SAAS,CAAC,MAAM,KAAA,UAaxB;AAED,iBAAS,iBAAiB,CAAC,MAAM,KAAA,UAOhC;AAED,QAAA,MAAM,UAAU;;;;;;mBAkBf,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/googleSheet/index.ts"],"names":[],"mappings":"AA6BA,iBAAe,SAAS,CAAC,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,EAAE,iBAAiB,EAAE,eAAe,EAAE;;;;;;CAAA,gBAgBnG;AAED,QAAA,MAAM,eAAe;;;;;;;;;0BAiCpB,CAAC;AAGF,iBAAS,SAAS,CAAC,MAAM,KAAA,UAaxB;AAED,iBAAS,iBAAiB,CAAC,MAAM,KAAA,UAOhC;AAED,QAAA,MAAM,UAAU;;;;;;mBAkBf,CAAC;AAEF,QAAA,MAAM,WAAW;;;;;;mBAmBhB,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,WAAW,EAAE,iBAAiB,EAAE,SAAS,EAAE,CAAC"}
|