diff options
author | Vijay A <vraravam@users.noreply.github.com> | 2022-05-16 17:29:24 -0500 |
---|---|---|
committer | Vijay Aravamudhan <vraravam@users.noreply.github.com> | 2022-05-16 19:25:46 -0500 |
commit | ad48962c335f6cec25bcedb92b4c34b6e4b0522c (patch) | |
tree | 8a96d9f83943170e37c7418fe51c212c8e1c2e40 /src/internal-server | |
parent | Fix recipes github link (#165) (diff) | |
download | ferdium-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/internal-server')
-rw-r--r-- | src/internal-server/app/Controllers/Http/ServiceController.js | 21 | ||||
-rw-r--r-- | src/internal-server/app/ImageHelper.js | 7 | ||||
-rw-r--r-- | src/internal-server/env.ini | 1 |
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 @@ | |||
1 | const Service = use('App/Models/Service'); | 1 | const Service = use('App/Models/Service'); |
2 | const { validateAll } = use('Validator'); | 2 | const { validateAll } = use('Validator'); |
3 | const Env = use('Env'); | ||
4 | 3 | ||
5 | const { v4: uuid } = require('uuid'); | 4 | const { v4: uuid } = require('uuid'); |
6 | const { LOCAL_HOSTNAME, DEFAULT_SERVICE_ORDER, DEFAULT_SERVICE_SETTINGS } = require('../../../../config'); | 5 | const { DEFAULT_SERVICE_ORDER, DEFAULT_SERVICE_SETTINGS } = require('../../../../config'); |
7 | const { convertToJSON } = require('../../../../jsUtils'); | 6 | const { convertToJSON } = require('../../../../jsUtils'); |
8 | const { API_VERSION } = require('../../../../environment-remote'); | 7 | const { deduceIconUrl, moveIcon } = require('../../ImageHelper'); |
9 | const moveIcon = require('../../ImageHelper'); | ||
10 | |||
11 | const hostname = LOCAL_HOSTNAME; | ||
12 | const port = Env.get('PORT'); | ||
13 | 8 | ||
14 | class ServiceController { | 9 | class 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 | ||
5 | const path = require('path'); | 5 | const path = require('path'); |
6 | const fs = require('fs-extra'); | 6 | const fs = require('fs-extra'); |
7 | const { API_VERSION } = require('../../environment-remote'); | ||
7 | 8 | ||
8 | module.exports = async (icon) => { | 9 | const 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 | |||
27 | const deduceIconUrl = (iconId) => iconId ? `http://${Env.get('HOST')}:${Env.get('PORT')}/${API_VERSION}/icon/${iconId}` : null | ||
28 | |||
29 | module.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 | |||
2 | PORT=45569 | 2 | PORT=45569 |
3 | NODE_ENV=development | 3 | NODE_ENV=development |
4 | APP_NAME=Ferdium Internal Server | 4 | APP_NAME=Ferdium Internal Server |
5 | APP_URL=http://${HOST}:${PORT} | ||
6 | CACHE_VIEWS=false | 5 | CACHE_VIEWS=false |
7 | APP_KEY=FERDIUMINTERNALSERVER | 6 | APP_KEY=FERDIUMINTERNALSERVER |
8 | DB_CONNECTION=sqlite | 7 | DB_CONNECTION=sqlite |