diff options
author | 2022-05-16 17:29:24 -0500 | |
---|---|---|
committer | 2022-05-16 19:25:46 -0500 | |
commit | ad48962c335f6cec25bcedb92b4c34b6e4b0522c (patch) | |
tree | 8a96d9f83943170e37c7418fe51c212c8e1c2e40 /src/internal-server/app/Controllers/Http | |
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/app/Controllers/Http')
-rw-r--r-- | src/internal-server/app/Controllers/Http/ServiceController.js | 21 |
1 files changed, 6 insertions, 15 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, |