diff options
Diffstat (limited to 'src/internal-server/app/Controllers/Http')
3 files changed, 28 insertions, 24 deletions
diff --git a/src/internal-server/app/Controllers/Http/RecipeController.js b/src/internal-server/app/Controllers/Http/RecipeController.js index 8a6b4f684..1a7595a9d 100644 --- a/src/internal-server/app/Controllers/Http/RecipeController.js +++ b/src/internal-server/app/Controllers/Http/RecipeController.js | |||
@@ -6,8 +6,11 @@ const { | |||
6 | const Env = use('Env'); | 6 | const Env = use('Env'); |
7 | 7 | ||
8 | const fetch = require('node-fetch'); | 8 | const fetch = require('node-fetch'); |
9 | const debug = require('debug')('Ferdi:internalServer:RecipeController'); | ||
10 | const { LIVE_FERDI_API } = require('../../../../config'); | ||
11 | const { API_VERSION } = require('../../../../environment'); | ||
9 | 12 | ||
10 | const RECIPES_URL = 'https://api.getferdi.com/v1/recipes'; | 13 | const RECIPES_URL = `${LIVE_FERDI_API}/${API_VERSION}/recipes`; |
11 | 14 | ||
12 | class RecipeController { | 15 | class RecipeController { |
13 | // List official and custom recipes | 16 | // List official and custom recipes |
@@ -64,6 +67,9 @@ class RecipeController { | |||
64 | if (Env.get('CONNECT_WITH_FRANZ') == 'true') { // eslint-disable-line eqeqeq | 67 | if (Env.get('CONNECT_WITH_FRANZ') == 'true') { // eslint-disable-line eqeqeq |
65 | remoteResults = JSON.parse(await (await fetch(`${RECIPES_URL}/search?needle=${encodeURIComponent(needle)}`)).text()); | 68 | remoteResults = JSON.parse(await (await fetch(`${RECIPES_URL}/search?needle=${encodeURIComponent(needle)}`)).text()); |
66 | } | 69 | } |
70 | |||
71 | debug('remoteResults:', remoteResults); | ||
72 | |||
67 | const localResultsArray = (await Recipe.query().where('name', 'LIKE', `%${needle}%`).fetch()).toJSON(); | 73 | const localResultsArray = (await Recipe.query().where('name', 'LIKE', `%${needle}%`).fetch()).toJSON(); |
68 | const localResults = localResultsArray.map(recipe => ({ | 74 | const localResults = localResultsArray.map(recipe => ({ |
69 | id: recipe.recipeId, | 75 | id: recipe.recipeId, |
@@ -71,6 +77,8 @@ class RecipeController { | |||
71 | ...JSON.parse(recipe.data), | 77 | ...JSON.parse(recipe.data), |
72 | })); | 78 | })); |
73 | 79 | ||
80 | debug('localResults:', localResults); | ||
81 | |||
74 | results = [ | 82 | results = [ |
75 | ...localResults, | 83 | ...localResults, |
76 | ...remoteResults || [], | 84 | ...remoteResults || [], |
diff --git a/src/internal-server/app/Controllers/Http/ServiceController.js b/src/internal-server/app/Controllers/Http/ServiceController.js index c76a287f7..f2af9d411 100644 --- a/src/internal-server/app/Controllers/Http/ServiceController.js +++ b/src/internal-server/app/Controllers/Http/ServiceController.js | |||
@@ -5,7 +5,8 @@ const Env = use('Env'); | |||
5 | const uuid = require('uuid/v4'); | 5 | const uuid = require('uuid/v4'); |
6 | const path = require('path'); | 6 | const path = require('path'); |
7 | const fs = require('fs-extra'); | 7 | const fs = require('fs-extra'); |
8 | const { LOCAL_HOSTNAME } = require('../../../../config'); | 8 | const { LOCAL_HOSTNAME, DEFAULT_SERVICE_ORDER } = require('../../../../config'); |
9 | const { API_VERSION } = require('../../../../environment'); | ||
9 | 10 | ||
10 | const hostname = LOCAL_HOSTNAME; | 11 | const hostname = LOCAL_HOSTNAME; |
11 | const port = Env.get('PORT'); | 12 | const port = Env.get('PORT'); |
@@ -54,7 +55,7 @@ class ServiceController { | |||
54 | isMuted: false, | 55 | isMuted: false, |
55 | isDarkModeEnabled: '', // TODO: This should ideally be a boolean (false). But, changing it caused the sidebar toggle to not work. | 56 | isDarkModeEnabled: '', // TODO: This should ideally be a boolean (false). But, changing it caused the sidebar toggle to not work. |
56 | spellcheckerLanguage: '', | 57 | spellcheckerLanguage: '', |
57 | order: 1, | 58 | order: DEFAULT_SERVICE_ORDER, |
58 | customRecipe: false, | 59 | customRecipe: false, |
59 | hasCustomIcon: false, | 60 | hasCustomIcon: false, |
60 | workspaces: [], | 61 | workspaces: [], |
@@ -83,12 +84,12 @@ class ServiceController { | |||
83 | isEnabled: true, | 84 | isEnabled: true, |
84 | isMuted: false, | 85 | isMuted: false, |
85 | isNotificationEnabled: true, | 86 | isNotificationEnabled: true, |
86 | order: 1, | 87 | order: DEFAULT_SERVICE_ORDER, |
87 | spellcheckerLanguage: '', | 88 | spellcheckerLanguage: '', |
88 | workspaces: [], | 89 | workspaces: [], |
89 | ...JSON.parse(service.settings), | 90 | ...JSON.parse(service.settings), |
90 | iconUrl: settings.iconId | 91 | iconUrl: settings.iconId |
91 | ? `http://${hostname}:${port}/v1/icon/${settings.iconId}` | 92 | ? `http://${hostname}:${port}/${API_VERSION}/icon/${settings.iconId}` |
92 | : null, | 93 | : null, |
93 | id: service.serviceId, | 94 | id: service.serviceId, |
94 | name: service.name, | 95 | name: service.name, |
@@ -156,7 +157,7 @@ class ServiceController { | |||
156 | id, | 157 | id, |
157 | name: service.name, | 158 | name: service.name, |
158 | ...newSettings, | 159 | ...newSettings, |
159 | iconUrl: `http://${hostname}:${port}/v1/icon/${ | 160 | iconUrl: `http://${hostname}:${port}/${API_VERSION}/icon/${ |
160 | newSettings.iconId | 161 | newSettings.iconId |
161 | }`, | 162 | }`, |
162 | userId: 1, | 163 | userId: 1, |
@@ -196,7 +197,7 @@ class ServiceController { | |||
196 | id, | 197 | id, |
197 | name: service.name, | 198 | name: service.name, |
198 | ...settings, | 199 | ...settings, |
199 | iconUrl: `${Env.get('APP_URL')}/v1/icon/${settings.iconId}`, | 200 | iconUrl: `${Env.get('APP_URL')}/${API_VERSION}/icon/${settings.iconId}`, |
200 | userId: 1, | 201 | userId: 1, |
201 | }, | 202 | }, |
202 | status: ['updated'], | 203 | status: ['updated'], |
@@ -257,12 +258,12 @@ class ServiceController { | |||
257 | isEnabled: true, | 258 | isEnabled: true, |
258 | isMuted: false, | 259 | isMuted: false, |
259 | isNotificationEnabled: true, | 260 | isNotificationEnabled: true, |
260 | order: 1, | 261 | order: DEFAULT_SERVICE_ORDER, |
261 | spellcheckerLanguage: '', | 262 | spellcheckerLanguage: '', |
262 | workspaces: [], | 263 | workspaces: [], |
263 | ...JSON.parse(service.settings), | 264 | ...JSON.parse(service.settings), |
264 | iconUrl: settings.iconId | 265 | iconUrl: settings.iconId |
265 | ? `http://${hostname}:${port}/v1/icon/${settings.iconId}` | 266 | ? `http://${hostname}:${port}/${API_VERSION}/icon/${settings.iconId}` |
266 | : null, | 267 | : null, |
267 | id: service.serviceId, | 268 | id: service.serviceId, |
268 | name: service.name, | 269 | name: service.name, |
diff --git a/src/internal-server/app/Controllers/Http/UserController.js b/src/internal-server/app/Controllers/Http/UserController.js index a3ad736fa..57aea6fc1 100644 --- a/src/internal-server/app/Controllers/Http/UserController.js +++ b/src/internal-server/app/Controllers/Http/UserController.js | |||
@@ -9,18 +9,16 @@ const btoa = require('btoa'); | |||
9 | const fetch = require('node-fetch'); | 9 | const fetch = require('node-fetch'); |
10 | const uuid = require('uuid/v4'); | 10 | const uuid = require('uuid/v4'); |
11 | const crypto = require('crypto'); | 11 | const crypto = require('crypto'); |
12 | const { DEFAULT_APP_SETTINGS } = require('../../../../environment'); | 12 | const { DEFAULT_APP_SETTINGS, API_VERSION } = require('../../../../environment'); |
13 | const { default: userAgent } = require('../../../../helpers/userAgent-helpers'); | ||
13 | 14 | ||
14 | const apiRequest = (url, route, method, auth) => new Promise((resolve, reject) => { | 15 | const apiRequest = (url, route, method, auth) => new Promise((resolve, reject) => { |
15 | const base = `${url}/v1/`; | ||
16 | const user = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Ferdi/5.3.0-beta.1 Chrome/69.0.3497.128 Electron/4.2.4 Safari/537.36'; | ||
17 | |||
18 | try { | 16 | try { |
19 | fetch(base + route, { | 17 | fetch(`${url}/${API_VERSION}/${route}`, { |
20 | method, | 18 | method, |
21 | headers: { | 19 | headers: { |
22 | Authorization: `Bearer ${auth}`, | 20 | Authorization: `Bearer ${auth}`, |
23 | 'User-Agent': user, | 21 | 'User-Agent': userAgent(), |
24 | }, | 22 | }, |
25 | }) | 23 | }) |
26 | .then(data => data.json()) | 24 | .then(data => data.json()) |
@@ -30,6 +28,8 @@ const apiRequest = (url, route, method, auth) => new Promise((resolve, reject) = | |||
30 | } | 28 | } |
31 | }); | 29 | }); |
32 | 30 | ||
31 | const LOGIN_SUCCESS_TOKEN = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJGZXJkaSBJbnRlcm5hbCBTZXJ2ZXIiLCJpYXQiOjE1NzEwNDAyMTUsImV4cCI6MjUzMzk1NDE3ODQ0LCJhdWQiOiJnZXRmZXJkaS5jb20iLCJzdWIiOiJmZXJkaUBsb2NhbGhvc3QiLCJ1c2VySWQiOiIxIn0.9_TWFGp6HROv8Yg82Rt6i1-95jqWym40a-HmgrdMC6M'; | ||
32 | |||
33 | class UserController { | 33 | class UserController { |
34 | // Register a new user | 34 | // Register a new user |
35 | async signup({ | 35 | async signup({ |
@@ -52,7 +52,7 @@ class UserController { | |||
52 | 52 | ||
53 | return response.send({ | 53 | return response.send({ |
54 | message: 'Successfully created account', | 54 | message: 'Successfully created account', |
55 | token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJGZXJkaSBJbnRlcm5hbCBTZXJ2ZXIiLCJpYXQiOjE1NzEwNDAyMTUsImV4cCI6MjUzMzk1NDE3ODQ0LCJhdWQiOiJnZXRmZXJkaS5jb20iLCJzdWIiOiJmZXJkaUBsb2NhbGhvc3QiLCJ1c2VySWQiOiIxIn0.9_TWFGp6HROv8Yg82Rt6i1-95jqWym40a-HmgrdMC6M', | 55 | token: LOGIN_SUCCESS_TOKEN, |
56 | }); | 56 | }); |
57 | } | 57 | } |
58 | 58 | ||
@@ -70,7 +70,7 @@ class UserController { | |||
70 | 70 | ||
71 | return response.send({ | 71 | return response.send({ |
72 | message: 'Successfully logged in', | 72 | message: 'Successfully logged in', |
73 | token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJGZXJkaSBJbnRlcm5hbCBTZXJ2ZXIiLCJpYXQiOjE1NzEwNDAyMTUsImV4cCI6MjUzMzk1NDE3ODQ0LCJhdWQiOiJnZXRmZXJkaS5jb20iLCJzdWIiOiJmZXJkaUBsb2NhbGhvc3QiLCJ1c2VySWQiOiIxIn0.9_TWFGp6HROv8Yg82Rt6i1-95jqWym40a-HmgrdMC6M', | 73 | token: LOGIN_SUCCESS_TOKEN, |
74 | }); | 74 | }); |
75 | } | 75 | } |
76 | 76 | ||
@@ -85,7 +85,6 @@ class UserController { | |||
85 | return response.send({ | 85 | return response.send({ |
86 | accountType: 'individual', | 86 | accountType: 'individual', |
87 | beta: false, | 87 | beta: false, |
88 | donor: {}, | ||
89 | email: '', | 88 | email: '', |
90 | emailValidated: true, | 89 | emailValidated: true, |
91 | features: {}, | 90 | features: {}, |
@@ -121,7 +120,6 @@ class UserController { | |||
121 | data: { | 120 | data: { |
122 | accountType: 'individual', | 121 | accountType: 'individual', |
123 | beta: false, | 122 | beta: false, |
124 | donor: {}, | ||
125 | email: '', | 123 | email: '', |
126 | emailValidated: true, | 124 | emailValidated: true, |
127 | features: {}, | 125 | features: {}, |
@@ -170,19 +168,16 @@ class UserController { | |||
170 | 168 | ||
171 | const hashedPassword = crypto.createHash('sha256').update(password).digest('base64'); | 169 | const hashedPassword = crypto.createHash('sha256').update(password).digest('base64'); |
172 | 170 | ||
173 | const base = `${server}/v1/`; | ||
174 | const userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Ferdi/5.3.0-beta.1 Chrome/69.0.3497.128 Electron/4.2.4 Safari/537.36'; | ||
175 | |||
176 | // Try to get an authentication token | 171 | // Try to get an authentication token |
177 | let token; | 172 | let token; |
178 | try { | 173 | try { |
179 | const basicToken = btoa(`${email}:${hashedPassword}`); | 174 | const basicToken = btoa(`${email}:${hashedPassword}`); |
180 | 175 | ||
181 | const rawResponse = await fetch(`${base}auth/login`, { | 176 | const rawResponse = await fetch(`${server}/${API_VERSION}/auth/login`, { |
182 | method: 'POST', | 177 | method: 'POST', |
183 | headers: { | 178 | headers: { |
184 | Authorization: `Basic ${basicToken}`, | 179 | Authorization: `Basic ${basicToken}`, |
185 | 'User-Agent': userAgent, | 180 | 'User-Agent': userAgent(), |
186 | }, | 181 | }, |
187 | }); | 182 | }); |
188 | const content = await rawResponse.json(); | 183 | const content = await rawResponse.json(); |