aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar Vijay A <vraravam@users.noreply.github.com>2022-05-16 17:29:24 -0500
committerLibravatar Vijay Aravamudhan <vraravam@users.noreply.github.com>2022-05-16 19:25:46 -0500
commitad48962c335f6cec25bcedb92b4c34b6e4b0522c (patch)
tree8a96d9f83943170e37c7418fe51c212c8e1c2e40 /src
parentFix recipes github link (#165) (diff)
downloadferdium-app-ad48962c335f6cec25bcedb92b4c34b6e4b0522c.tar.gz
ferdium-app-ad48962c335f6cec25bcedb92b4c34b6e4b0522c.tar.zst
ferdium-app-ad48962c335f6cec25bcedb92b4c34b6e4b0522c.zip
Minor refactoring to extract common function to deduce icon url
Diffstat (limited to 'src')
-rw-r--r--src/internal-server/app/Controllers/Http/ServiceController.js21
-rw-r--r--src/internal-server/app/ImageHelper.js7
-rw-r--r--src/internal-server/env.ini1
3 files changed, 12 insertions, 17 deletions
diff --git a/src/internal-server/app/Controllers/Http/ServiceController.js b/src/internal-server/app/Controllers/Http/ServiceController.js
index 26571323d..8be5aa9c5 100644
--- a/src/internal-server/app/Controllers/Http/ServiceController.js
+++ b/src/internal-server/app/Controllers/Http/ServiceController.js
@@ -1,15 +1,10 @@
1const Service = use('App/Models/Service'); 1const Service = use('App/Models/Service');
2const { validateAll } = use('Validator'); 2const { validateAll } = use('Validator');
3const Env = use('Env');
4 3
5const { v4: uuid } = require('uuid'); 4const { v4: uuid } = require('uuid');
6const { LOCAL_HOSTNAME, DEFAULT_SERVICE_ORDER, DEFAULT_SERVICE_SETTINGS } = require('../../../../config'); 5const { DEFAULT_SERVICE_ORDER, DEFAULT_SERVICE_SETTINGS } = require('../../../../config');
7const { convertToJSON } = require('../../../../jsUtils'); 6const { convertToJSON } = require('../../../../jsUtils');
8const { API_VERSION } = require('../../../../environment-remote'); 7const { deduceIconUrl, moveIcon } = require('../../ImageHelper');
9const moveIcon = require('../../ImageHelper');
10
11const hostname = LOCAL_HOSTNAME;
12const port = Env.get('PORT');
13 8
14class ServiceController { 9class ServiceController {
15 // Create a new service for user 10 // Create a new service for user
@@ -91,9 +86,7 @@ class ServiceController {
91 // Overwrite previous default settings with what's obtained from the db 86 // Overwrite previous default settings with what's obtained from the db
92 ...settings, 87 ...settings,
93 // Overwrite even after the spread operator with specific values 88 // Overwrite even after the spread operator with specific values
94 iconUrl: settings.iconId 89 iconUrl: deduceIconUrl(settings.iconId),
95 ? `http://${hostname}:${port}/${API_VERSION}/icon/${settings.iconId}`
96 : null,
97 id: service.serviceId, 90 id: service.serviceId,
98 name: service.name, 91 name: service.name,
99 recipeId: service.recipeId, 92 recipeId: service.recipeId,
@@ -144,7 +137,7 @@ class ServiceController {
144 id, 137 id,
145 name: service.name, 138 name: service.name,
146 ...newSettings, 139 ...newSettings,
147 iconUrl: `http://${hostname}:${port}/${API_VERSION}/icon/${newSettings.iconId}`, 140 iconUrl: deduceIconUrl(newSettings.iconId),
148 userId: 1, 141 userId: 1,
149 }, 142 },
150 status: ['updated'], 143 status: ['updated'],
@@ -182,7 +175,7 @@ class ServiceController {
182 id, 175 id,
183 name: service.name, 176 name: service.name,
184 ...settings, 177 ...settings,
185 iconUrl: `${Env.get('APP_URL')}/${API_VERSION}/icon/${settings.iconId}`, 178 iconUrl: deduceIconUrl(settings.iconId),
186 userId: 1, 179 userId: 1,
187 }, 180 },
188 status: ['updated'], 181 status: ['updated'],
@@ -236,9 +229,7 @@ class ServiceController {
236 // Overwrite previous default settings with what's obtained from the db 229 // Overwrite previous default settings with what's obtained from the db
237 ...settings, 230 ...settings,
238 // Overwrite even after the spread operator with specific values 231 // Overwrite even after the spread operator with specific values
239 iconUrl: settings.iconId 232 iconUrl: deduceIconUrl(settings.iconId),
240 ? `http://${hostname}:${port}/${API_VERSION}/icon/${settings.iconId}`
241 : null,
242 id: service.serviceId, 233 id: service.serviceId,
243 name: service.name, 234 name: service.name,
244 recipeId: service.recipeId, 235 recipeId: service.recipeId,
diff --git a/src/internal-server/app/ImageHelper.js b/src/internal-server/app/ImageHelper.js
index b399d08c4..e7c981a1d 100644
--- a/src/internal-server/app/ImageHelper.js
+++ b/src/internal-server/app/ImageHelper.js
@@ -4,8 +4,9 @@ const { v4: uuid } = require('uuid');
4 4
5const path = require('path'); 5const path = require('path');
6const fs = require('fs-extra'); 6const fs = require('fs-extra');
7const { API_VERSION } = require('../../environment-remote');
7 8
8module.exports = async (icon) => { 9const moveIcon = async (icon) => {
9 const iconsPath = path.join(Env.get('USER_PATH'), 'icons'); 10 const iconsPath = path.join(Env.get('USER_PATH'), 'icons');
10 await fs.ensureDir(iconsPath); 11 await fs.ensureDir(iconsPath);
11 12
@@ -22,3 +23,7 @@ module.exports = async (icon) => {
22 }); 23 });
23 return !icon.moved() ? '-1' : iconId; 24 return !icon.moved() ? '-1' : iconId;
24}; 25};
26
27const deduceIconUrl = (iconId) => iconId ? `http://${Env.get('HOST')}:${Env.get('PORT')}/${API_VERSION}/icon/${iconId}` : null
28
29module.exports = { moveIcon, deduceIconUrl };
diff --git a/src/internal-server/env.ini b/src/internal-server/env.ini
index 87a347921..d8224e91e 100644
--- a/src/internal-server/env.ini
+++ b/src/internal-server/env.ini
@@ -2,7 +2,6 @@ HOST=localhost
2PORT=45569 2PORT=45569
3NODE_ENV=development 3NODE_ENV=development
4APP_NAME=Ferdium Internal Server 4APP_NAME=Ferdium Internal Server
5APP_URL=http://${HOST}:${PORT}
6CACHE_VIEWS=false 5CACHE_VIEWS=false
7APP_KEY=FERDIUMINTERNALSERVER 6APP_KEY=FERDIUMINTERNALSERVER
8DB_CONNECTION=sqlite 7DB_CONNECTION=sqlite