@runnerpro/backend 1.2.6 → 1.3.1

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.
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.generateShareMap = void 0;
16
+ // @ts-nocheck
17
+ const canvas_1 = require("@napi-rs/canvas");
18
+ const index_1 = require("../db/index");
19
+ const common_1 = require("@runnerpro/common");
20
+ const translation_1 = require("../translation");
21
+ const path_1 = __importDefault(require("path"));
22
+ const jimp_1 = __importDefault(require("jimp"));
23
+ const uuid_1 = require("uuid");
24
+ const fs_1 = __importDefault(require("fs"));
25
+ // install fonts
26
+ canvas_1.GlobalFonts.registerFromPath(path_1.default.join(__dirname, '../../..', 'static/fonts', 'SofiaSans-Bold.ttf'), 'SofiaSansBold');
27
+ canvas_1.GlobalFonts.registerFromPath(path_1.default.join(__dirname, '../../..', 'static/fonts', 'SofiaSans-Regular.ttf'), 'SofiaSans');
28
+ const generateShareMap = (image, idWorkout, options) => __awaiter(void 0, void 0, void 0, function* () {
29
+ const useDefaultPhoto = (options === null || options === void 0 ? void 0 : options.useDefaultPhoto) || false;
30
+ const [workout] = yield (0, index_1.query)('SELECT [ID], [ID CLIENTE], [TYPE], [DISTANCE], [DURATION], [DESNIVEL] FROM [WORKOUT] WHERE [ID] = ?', [idWorkout]);
31
+ const [cliente] = yield (0, index_1.query)('SELECT [PREFERRED LANGUAGE] FROM [CLIENTE] WHERE [ID] = ?', [workout.idCliente]);
32
+ if (!workout || !cliente)
33
+ return null;
34
+ const width = 1080;
35
+ const height = 1080;
36
+ const canvas = (0, canvas_1.createCanvas)(width, height);
37
+ const context = canvas.getContext('2d', { alpha: false });
38
+ yield addImageShareWorkoutmap(context, image);
39
+ yield addShadowShareWorkoutmap(context, useDefaultPhoto);
40
+ yield Promise.all([addTextShareWorkoutmap(context, workout, cliente), addLogoShareWorkoutmap(context)]);
41
+ return canvas.toBuffer('image/jpeg');
42
+ });
43
+ exports.generateShareMap = generateShareMap;
44
+ const addTextShareWorkoutmap = (context, workout, cliente) => __awaiter(void 0, void 0, void 0, function* () {
45
+ const { t } = (0, translation_1.useTranslation)(cliente.preferredLanguage, '/api/workout/workoutMap');
46
+ const heightTitle = 990;
47
+ const heightSubtitle = 1030;
48
+ const widthInitial = 50;
49
+ const widthSeparate = workout.type === common_1.WORKOUT_TYPE.SWIM ? 320 : 370;
50
+ const items = [];
51
+ if (workout.type !== common_1.WORKOUT_TYPE.FUERZA) {
52
+ items.push(...[
53
+ {
54
+ text: (Math.trunc(workout.distance / 100) / 10).toFixed(1) + 'km',
55
+ type: 'title',
56
+ },
57
+ {
58
+ text: t('Distancia'),
59
+ type: 'subtitle',
60
+ },
61
+ ]);
62
+ }
63
+ const h = Math.trunc(workout.duration / 3600);
64
+ const m = Math.trunc((workout.duration - h * 3600) / 60);
65
+ const s = workout.duration - h * 3600 - m * 60;
66
+ items.push(...[
67
+ {
68
+ text: `${h.toString().padStart(2, '0')}:${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}`,
69
+ type: 'title',
70
+ },
71
+ {
72
+ text: t('Tiempo'),
73
+ type: 'subtitle',
74
+ },
75
+ ]);
76
+ if (workout.type === common_1.WORKOUT_TYPE.TRAIL) {
77
+ items.push(...[
78
+ {
79
+ text: `+${workout.desnivel}m`,
80
+ type: 'title',
81
+ },
82
+ {
83
+ text: t('Desnivel'),
84
+ type: 'subtitle',
85
+ },
86
+ ]);
87
+ }
88
+ else if (workout.type !== common_1.WORKOUT_TYPE.FUERZA) {
89
+ items.push(...[
90
+ {
91
+ text: getPace(workout).value,
92
+ type: 'title',
93
+ },
94
+ {
95
+ text: (0, common_1.translateWorkoutParams)(getPace(workout).subtitle, cliente.preferredLanguage),
96
+ type: 'subtitle',
97
+ },
98
+ ]);
99
+ }
100
+ items.forEach((item, i) => {
101
+ context.font = item.type === 'title' ? '57px SofiaSansBold' : '35px SofiaSans';
102
+ context.fillStyle = '#ffffff';
103
+ context.fillText(item.text, widthInitial + widthSeparate * Math.trunc(i / 2), item.type === 'title' ? heightTitle : heightSubtitle);
104
+ });
105
+ });
106
+ const getPace = (workout) => {
107
+ return {
108
+ value: (0, common_1.getWorkoutParamsByType)(workout.type).pace.pretty((0, common_1.getWorkoutParamsByType)(workout.type).calculatePace({ duration: workout.duration, distance: workout.distance })),
109
+ subtitle: (0, common_1.getWorkoutParamsByType)(workout.type).pace.title,
110
+ };
111
+ };
112
+ const addLogoShareWorkoutmap = (context) => __awaiter(void 0, void 0, void 0, function* () {
113
+ const logoPath = path_1.default.join(process.cwd(), 'src', 'static', 'logo-large-primary.png');
114
+ const logo = yield (0, canvas_1.loadImage)(logoPath);
115
+ yield context.drawImage(logo, 304, 0, 473, 180);
116
+ });
117
+ const addShadowShareWorkoutmap = (context, useDefaultPhoto) => __awaiter(void 0, void 0, void 0, function* () {
118
+ const shadowHeight = 250;
119
+ const shadowColor = (opacity) => (useDefaultPhoto ? `rgba(0, 0, 0, ${opacity})` : `rgba(255, 255, 255, ${opacity})`);
120
+ const shadowColorDown = (opacity) => `rgba(0, 0, 0, ${opacity})`;
121
+ const gradient = context.createLinearGradient(0, 0, 0, shadowHeight);
122
+ gradient.addColorStop(0, shadowColor(0.3));
123
+ gradient.addColorStop(1, shadowColor(0.0));
124
+ context.fillStyle = gradient;
125
+ context.fillRect(0, 0, 1080, shadowHeight);
126
+ const gradientDown = context.createLinearGradient(0, 1080, 0, 1080 - shadowHeight);
127
+ gradientDown.addColorStop(0, shadowColorDown(0.6));
128
+ gradientDown.addColorStop(0.5, shadowColorDown(0.4));
129
+ gradientDown.addColorStop(1, shadowColorDown(0.0));
130
+ context.fillStyle = gradientDown;
131
+ context.fillRect(0, 1080 - shadowHeight, 1080, shadowHeight);
132
+ });
133
+ const addImageShareWorkoutmap = (context, data) => __awaiter(void 0, void 0, void 0, function* () {
134
+ const image = yield jimp_1.default.read(data);
135
+ const filename2 = `share-${(0, uuid_1.uuid)()}.jpeg`;
136
+ yield image.cover(1080, 1080).writeAsync(`./uploads/${filename2}`);
137
+ const imagePath2 = path_1.default.join(__dirname, '../../../../uploads', filename2);
138
+ const image2 = yield (0, canvas_1.loadImage)(imagePath2);
139
+ context.drawImage(image2, 0, 0, 1080, 1080);
140
+ context.fillStyle = 'rgba(0, 0, 0, 0.5)';
141
+ yield fs_1.default.promises.unlink(imagePath2);
142
+ });
package/lib/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.reduceSizeImage = exports.getLetter = exports.getNumberByLetter = exports.appendSheet = exports.writeSheet = exports.findCellByValue = exports.readSheet = exports.NOTION_DATABASES_ID = exports.notionEditPage = exports.notionAddPage = exports.notionGetDatabase = exports.notionGetUsers = exports.getCountNotificaciones = exports.chatExposed = exports.chatApi = exports.chat = exports.getExerciseTranslatedDescription = exports.useTranslation = exports.LANGUAGES = exports.translate = exports.CHANNEL_SLACK = exports.notifySlack = exports.fetchIA = exports.err = exports.sendMail = exports.batchQuery = exports.query = exports.sleep = exports.sendNotification = void 0;
3
+ exports.generateShareMap = exports.reduceSizeImage = exports.getLetter = exports.getNumberByLetter = exports.appendSheet = exports.writeSheet = exports.findCellByValue = exports.readSheet = exports.NOTION_DATABASES_ID = exports.notionEditPage = exports.notionAddPage = exports.notionGetDatabase = exports.notionGetUsers = exports.getCountNotificaciones = exports.chatExposed = exports.chatApi = exports.chat = exports.getExerciseTranslatedDescription = exports.useTranslation = exports.LANGUAGES = exports.translate = exports.CHANNEL_SLACK = exports.notifySlack = exports.fetchIA = exports.err = exports.sendMail = exports.batchQuery = exports.query = exports.sleep = exports.sendNotification = void 0;
4
4
  const sendNotification_1 = require("./sendNotification");
5
5
  Object.defineProperty(exports, "sendNotification", { enumerable: true, get: function () { return sendNotification_1.sendNotification; } });
6
6
  const sleep_1 = require("./sleep");
@@ -42,3 +42,5 @@ Object.defineProperty(exports, "getNumberByLetter", { enumerable: true, get: fun
42
42
  Object.defineProperty(exports, "getLetter", { enumerable: true, get: function () { return googleSheet_1.getLetter; } });
43
43
  const reduceSizeImage_1 = require("./image/reduceSizeImage");
44
44
  Object.defineProperty(exports, "reduceSizeImage", { enumerable: true, get: function () { return reduceSizeImage_1.reduceSizeImage; } });
45
+ const generateShareMap_1 = require("./image/generateShareMap");
46
+ Object.defineProperty(exports, "generateShareMap", { enumerable: true, get: function () { return generateShareMap_1.generateShareMap; } });
@@ -0,0 +1,4 @@
1
+ /// <reference types="node" />
2
+ declare const generateShareMap: (image: any, idWorkout: any, options: any) => Promise<Buffer>;
3
+ export { generateShareMap };
4
+ //# sourceMappingURL=generateShareMap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateShareMap.d.ts","sourceRoot":"","sources":["../../../../src/image/generateShareMap.ts"],"names":[],"mappings":";AAcA,QAAA,MAAM,gBAAgB,+DAkBrB,CAAA;AAyHD,OAAO,EACL,gBAAgB,EACjB,CAAA"}
@@ -10,5 +10,6 @@ import { chat, chatApi, chatExposed, getCountNotificaciones } from './chat';
10
10
  import { notionGetUsers, notionGetDatabase, notionAddPage, notionEditPage, NOTION_DATABASES_ID } from './notion';
11
11
  import { readSheet, findCellByValue, writeSheet, appendSheet, getNumberByLetter, getLetter } from './googleSheet';
12
12
  import { reduceSizeImage } from './image/reduceSizeImage';
13
- export { sendNotification, sleep, query, batchQuery, sendMail, err, fetchIA, notifySlack, CHANNEL_SLACK, translate, LANGUAGES, useTranslation, getExerciseTranslatedDescription, chat, chatApi, chatExposed, getCountNotificaciones, notionGetUsers, notionGetDatabase, notionAddPage, notionEditPage, NOTION_DATABASES_ID, readSheet, findCellByValue, writeSheet, appendSheet, getNumberByLetter, getLetter, reduceSizeImage, };
13
+ import { generateShareMap } from './image/generateShareMap';
14
+ export { sendNotification, sleep, query, batchQuery, sendMail, err, fetchIA, notifySlack, CHANNEL_SLACK, translate, LANGUAGES, useTranslation, getExerciseTranslatedDescription, chat, chatApi, chatExposed, getCountNotificaciones, notionGetUsers, notionGetDatabase, notionAddPage, notionEditPage, NOTION_DATABASES_ID, readSheet, findCellByValue, writeSheet, appendSheet, getNumberByLetter, getLetter, reduceSizeImage, generateShareMap, };
14
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,gCAAgC,EAAE,MAAM,eAAe,CAAC;AACvG,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAC;AAC5E,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AC;AAC5E,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,aAAa,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACjH,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,WAAW,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAClH,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,OAAO,EACL,gBAAgB,EAChB,KAAK,EACL,KAAK,EACL,UAAU,EACV,QAAQ,EACR,GAAG,EACH,OAAO,EACP,WAAW,EACX,aAAa,EACb,SAAS,EACT,SAAS,EACT,cAAc,EACd,gCAAgC,EAChC,IAAI,EACJ,OAAO,EACP,WAAW,EACX,sBAAsB,EACtB,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,SAAS,EACT,eAAe,EACf,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,SAAS,EACT,eAAe,EACf,gBAAgB,GACjB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runnerpro/backend",
3
- "version": "1.2.6",
3
+ "version": "1.3.1",
4
4
  "description": "A collection of common backend functions",
5
5
  "exports": {
6
6
  ".": "./lib/cjs/index.js"
@@ -57,14 +57,16 @@
57
57
  "axios": "^1.6.7",
58
58
  "jimp": "^0.22.10",
59
59
  "nodemailer": "6.9.9",
60
- "pg": "8.11.3"
60
+ "pg": "8.11.3",
61
+ "uuidv4": "^6.2.13",
62
+ "image-size": "^1.0.2",
63
+ "@napi-rs/canvas": "^0.1.53"
61
64
  },
62
65
  "dependencies": {
63
66
  "@google-cloud/translate": "^8.3.0",
64
67
  "@notionhq/client": "^2.2.15",
65
68
  "exifr": "^7.1.3",
66
69
  "googleapis": "^144.0.0",
67
- "image-size": "^1.0.2",
68
70
  "multer": "^1.4.5-lts.1",
69
71
  "socket.io": "^4.7.2"
70
72
  }