aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar Vijay A <vraravam@users.noreply.github.com>2022-05-15 20:51:02 -0500
committerLibravatar Vijay A <vraravam@users.noreply.github.com>2022-05-15 20:51:02 -0500
commitb697c160e64ecb614d96bd89c5572b93d91189a3 (patch)
treecaf616e5db63a5c64e30ea88b538235969964ab1 /src
parentUpdate submodules, browserslist data updates and linter fixes [skip ci] (diff)
downloadferdium-app-b697c160e64ecb614d96bd89c5572b93d91189a3.tar.gz
ferdium-app-b697c160e64ecb614d96bd89c5572b93d91189a3.tar.zst
ferdium-app-b697c160e64ecb614d96bd89c5572b93d91189a3.zip
Use DEFAULT_SERVICE_SETTINGS for default values (remove duplication)
Added TODO comments, notes, debug logs.
Diffstat (limited to 'src')
-rw-r--r--src/internal-server/app/Controllers/Http/ServiceController.js47
-rw-r--r--src/models/Service.js1
-rw-r--r--src/stores/SettingsStore.js9
3 files changed, 34 insertions, 23 deletions
diff --git a/src/internal-server/app/Controllers/Http/ServiceController.js b/src/internal-server/app/Controllers/Http/ServiceController.js
index 81c03e5ff..26571323d 100644
--- a/src/internal-server/app/Controllers/Http/ServiceController.js
+++ b/src/internal-server/app/Controllers/Http/ServiceController.js
@@ -3,7 +3,7 @@ const { validateAll } = use('Validator');
3const Env = use('Env'); 3const Env = use('Env');
4 4
5const { v4: uuid } = require('uuid'); 5const { v4: uuid } = require('uuid');
6const { LOCAL_HOSTNAME, DEFAULT_SERVICE_ORDER } = require('../../../../config'); 6const { LOCAL_HOSTNAME, DEFAULT_SERVICE_ORDER, DEFAULT_SERVICE_SETTINGS } = require('../../../../config');
7const { convertToJSON } = require('../../../../jsUtils'); 7const { convertToJSON } = require('../../../../jsUtils');
8const { API_VERSION } = require('../../../../environment-remote'); 8const { API_VERSION } = require('../../../../environment-remote');
9const moveIcon = require('../../ImageHelper'); 9const moveIcon = require('../../ImageHelper');
@@ -14,8 +14,10 @@ const port = Env.get('PORT');
14class ServiceController { 14class ServiceController {
15 // Create a new service for user 15 // Create a new service for user
16 async create({ request, response }) { 16 async create({ request, response }) {
17 const data = request.all();
18
17 // Validate user input 19 // Validate user input
18 const validation = await validateAll(request.all(), { 20 const validation = await validateAll(data, {
19 name: 'required|string', 21 name: 'required|string',
20 recipeId: 'required', 22 recipeId: 'required',
21 }); 23 });
@@ -27,16 +29,13 @@ class ServiceController {
27 }); 29 });
28 } 30 }
29 31
30 const data = request.all();
31
32 // Get new, unused uuid 32 // Get new, unused uuid
33 let serviceId; 33 let serviceId;
34 do { 34 do {
35 serviceId = uuid(); 35 serviceId = uuid();
36 } while ( 36 } while (
37 // eslint-disable-next-line no-await-in-loop, unicorn/no-await-expression-member 37 // eslint-disable-next-line no-await-in-loop, unicorn/no-await-expression-member
38 (await Service.query().where('serviceId', serviceId).fetch()).rows 38 (await Service.query().where('serviceId', serviceId).fetch()).rows.length > 0
39 .length > 0
40 ); 39 );
41 40
42 await Service.create({ 41 await Service.create({
@@ -46,21 +45,23 @@ class ServiceController {
46 settings: JSON.stringify(data), 45 settings: JSON.stringify(data),
47 }); 46 });
48 47
48 // TODO: Remove duplication
49 return response.send({ 49 return response.send({
50 data: { 50 data: {
51 userId: 1, 51 userId: 1,
52 id: serviceId, 52 id: serviceId,
53 isEnabled: true, 53 isEnabled: DEFAULT_SERVICE_SETTINGS.isEnabled,
54 isNotificationEnabled: true, 54 isNotificationEnabled: DEFAULT_SERVICE_SETTINGS.isNotificationEnabled,
55 isBadgeEnabled: true, 55 isBadgeEnabled: DEFAULT_SERVICE_SETTINGS.isBadgeEnabled,
56 isMuted: false, 56 isMuted: DEFAULT_SERVICE_SETTINGS.isMuted,
57 isDarkModeEnabled: '', // TODO: This should ideally be a boolean (false). But, changing it caused the sidebar toggle to not work. 57 isDarkModeEnabled: '', // TODO: This should ideally be a boolean (false). But, changing it caused the sidebar toggle to not work.
58 spellcheckerLanguage: '', 58 spellcheckerLanguage: '',
59 order: DEFAULT_SERVICE_ORDER, 59 order: DEFAULT_SERVICE_ORDER,
60 customRecipe: false, 60 customRecipe: false,
61 hasCustomIcon: false, 61 hasCustomIcon: DEFAULT_SERVICE_SETTINGS.customIcon,
62 workspaces: [], 62 workspaces: [],
63 iconUrl: null, 63 iconUrl: null,
64 // Overwrite previous default settings with what's obtained from the request
64 ...data, 65 ...data,
65 }, 66 },
66 status: ['created'], 67 status: ['created'],
@@ -75,18 +76,21 @@ class ServiceController {
75 const servicesArray = services.map(service => { 76 const servicesArray = services.map(service => {
76 const settings = convertToJSON(service.settings); 77 const settings = convertToJSON(service.settings);
77 78
79 // TODO: Remove duplication
78 return { 80 return {
79 customRecipe: false, 81 customRecipe: false,
80 hasCustomIcon: false, 82 hasCustomIcon: false,
81 isBadgeEnabled: true, 83 isBadgeEnabled: DEFAULT_SERVICE_SETTINGS.isBadgeEnabled,
82 isDarkModeEnabled: '', // TODO: This should ideally be a boolean (false). But, changing it caused the sidebar toggle to not work. 84 isDarkModeEnabled: '', // TODO: This should ideally be a boolean (false). But, changing it caused the sidebar toggle to not work.
83 isEnabled: true, 85 isEnabled: DEFAULT_SERVICE_SETTINGS.isEnabled,
84 isMuted: false, 86 isMuted: DEFAULT_SERVICE_SETTINGS.isMuted,
85 isNotificationEnabled: true, 87 isNotificationEnabled: DEFAULT_SERVICE_SETTINGS.isNotificationEnabled,
86 order: DEFAULT_SERVICE_ORDER, 88 order: DEFAULT_SERVICE_ORDER,
87 spellcheckerLanguage: '', 89 spellcheckerLanguage: '',
88 workspaces: [], 90 workspaces: [],
91 // Overwrite previous default settings with what's obtained from the db
89 ...settings, 92 ...settings,
93 // Overwrite even after the spread operator with specific values
90 iconUrl: settings.iconId 94 iconUrl: settings.iconId
91 ? `http://${hostname}:${port}/${API_VERSION}/icon/${settings.iconId}` 95 ? `http://${hostname}:${port}/${API_VERSION}/icon/${settings.iconId}`
92 : null, 96 : null,
@@ -217,18 +221,21 @@ class ServiceController {
217 const servicesArray = services.map(service => { 221 const servicesArray = services.map(service => {
218 const settings = convertToJSON(service.settings); 222 const settings = convertToJSON(service.settings);
219 223
224 // TODO: Remove duplication
220 return { 225 return {
221 customRecipe: false, 226 customRecipe: false,
222 hasCustomIcon: false, 227 hasCustomIcon: DEFAULT_SERVICE_SETTINGS.customIcon,
223 isBadgeEnabled: true, 228 isBadgeEnabled: DEFAULT_SERVICE_SETTINGS.isBadgeEnabled,
224 isDarkModeEnabled: '', // TODO: This should ideally be a boolean (false). But, changing it caused the sidebar toggle to not work. 229 isDarkModeEnabled: '', // TODO: This should ideally be a boolean (false). But, changing it caused the sidebar toggle to not work.
225 isEnabled: true, 230 isEnabled: DEFAULT_SERVICE_SETTINGS.isEnabled,
226 isMuted: false, 231 isMuted: DEFAULT_SERVICE_SETTINGS.isMuted,
227 isNotificationEnabled: true, 232 isNotificationEnabled: DEFAULT_SERVICE_SETTINGS.isNotificationEnabled,
228 order: DEFAULT_SERVICE_ORDER, 233 order: DEFAULT_SERVICE_ORDER,
229 spellcheckerLanguage: '', 234 spellcheckerLanguage: '',
230 workspaces: [], 235 workspaces: [],
236 // Overwrite previous default settings with what's obtained from the db
231 ...settings, 237 ...settings,
238 // Overwrite even after the spread operator with specific values
232 iconUrl: settings.iconId 239 iconUrl: settings.iconId
233 ? `http://${hostname}:${port}/${API_VERSION}/icon/${settings.iconId}` 240 ? `http://${hostname}:${port}/${API_VERSION}/icon/${settings.iconId}`
234 : null, 241 : null,
diff --git a/src/models/Service.js b/src/models/Service.js
index 1fca034bc..af42f9548 100644
--- a/src/models/Service.js
+++ b/src/models/Service.js
@@ -16,6 +16,7 @@ import {
16 16
17const debug = require('../preload-safe-debug')('Ferdium:Service'); 17const debug = require('../preload-safe-debug')('Ferdium:Service');
18 18
19// TODO: Shouldn't most of these values default to what's defined in DEFAULT_SERVICE_SETTINGS?
19export default class Service { 20export default class Service {
20 id = ''; 21 id = '';
21 22
diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js
index 6b6b77454..7afecd9df 100644
--- a/src/stores/SettingsStore.js
+++ b/src/stores/SettingsStore.js
@@ -188,10 +188,9 @@ export default class SettingsStore extends Store {
188 188
189 // Helper 189 // Helper
190 async _migrate() { 190 async _migrate() {
191 const legacySettings = localStorage.getItem('app') || {};
192
193 this._ensureMigrationAndMarkDone('password-hashing', () => { 191 this._ensureMigrationAndMarkDone('password-hashing', () => {
194 if (this.stores.settings.app.lockedPassword !== '') { 192 if (this.stores.settings.app.lockedPassword !== '') {
193 const legacySettings = localStorage.getItem('app') || {};
195 this.actions.settings.update({ 194 this.actions.settings.update({
196 type: 'app', 195 type: 'app',
197 data: { 196 data: {
@@ -200,7 +199,7 @@ export default class SettingsStore extends Store {
200 }); 199 });
201 } 200 }
202 201
203 debug('Migrated updates settings'); 202 debug('Migrated password-hashing settings');
204 }); 203 });
205 204
206 this._ensureMigrationAndMarkDone('5.6.0-beta.6-settings', () => { 205 this._ensureMigrationAndMarkDone('5.6.0-beta.6-settings', () => {
@@ -210,6 +209,8 @@ export default class SettingsStore extends Store {
210 searchEngine: DEFAULT_APP_SETTINGS.searchEngine, 209 searchEngine: DEFAULT_APP_SETTINGS.searchEngine,
211 }, 210 },
212 }); 211 });
212
213 debug('Migrated default search engine settings');
213 }); 214 });
214 215
215 this._ensureMigrationAndMarkDone('user-agent-settings', () => { 216 this._ensureMigrationAndMarkDone('user-agent-settings', () => {
@@ -219,6 +220,8 @@ export default class SettingsStore extends Store {
219 userAgentPref: DEFAULT_APP_SETTINGS.userAgentPref, 220 userAgentPref: DEFAULT_APP_SETTINGS.userAgentPref,
220 }, 221 },
221 }); 222 });
223
224 debug('Migrated default user-agent settings');
222 }); 225 });
223 } 226 }
224} 227}