diff options
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/FeaturesApi.js | 13 | ||||
-rw-r--r-- | src/api/LocalApi.js | 8 | ||||
-rw-r--r-- | src/api/RecipesApi.js | 2 | ||||
-rw-r--r-- | src/api/index.js | 2 | ||||
-rw-r--r-- | src/api/server/LocalApi.js | 21 | ||||
-rw-r--r-- | src/api/server/ServerApi.js | 33 |
6 files changed, 63 insertions, 16 deletions
diff --git a/src/api/FeaturesApi.js b/src/api/FeaturesApi.js new file mode 100644 index 000000000..c66f28f5b --- /dev/null +++ b/src/api/FeaturesApi.js | |||
@@ -0,0 +1,13 @@ | |||
1 | export default class FeaturesApi { | ||
2 | constructor(server) { | ||
3 | this.server = server; | ||
4 | } | ||
5 | |||
6 | default() { | ||
7 | return this.server.getDefaultFeatures(); | ||
8 | } | ||
9 | |||
10 | features() { | ||
11 | return this.server.getFeatures(); | ||
12 | } | ||
13 | } | ||
diff --git a/src/api/LocalApi.js b/src/api/LocalApi.js index 741917104..e2a46874a 100644 --- a/src/api/LocalApi.js +++ b/src/api/LocalApi.js | |||
@@ -4,12 +4,12 @@ export default class LocalApi { | |||
4 | this.local = local; | 4 | this.local = local; |
5 | } | 5 | } |
6 | 6 | ||
7 | getAppSettings() { | 7 | getAppSettings(type) { |
8 | return this.local.getAppSettings(); | 8 | return this.local.getAppSettings(type); |
9 | } | 9 | } |
10 | 10 | ||
11 | updateAppSettings(data) { | 11 | updateAppSettings(type, data) { |
12 | return this.local.updateAppSettings(data); | 12 | return this.local.updateAppSettings(type, data); |
13 | } | 13 | } |
14 | 14 | ||
15 | getAppCacheSize() { | 15 | getAppCacheSize() { |
diff --git a/src/api/RecipesApi.js b/src/api/RecipesApi.js index 0573dacaf..800888b00 100644 --- a/src/api/RecipesApi.js +++ b/src/api/RecipesApi.js | |||
@@ -1,4 +1,4 @@ | |||
1 | export default class ServicesApi { | 1 | export default class RecipesApi { |
2 | constructor(server) { | 2 | constructor(server) { |
3 | this.server = server; | 3 | this.server = server; |
4 | } | 4 | } |
diff --git a/src/api/index.js b/src/api/index.js index 3fc18c4b5..3c87cc087 100644 --- a/src/api/index.js +++ b/src/api/index.js | |||
@@ -6,12 +6,14 @@ import UserApi from './UserApi'; | |||
6 | import LocalApi from './LocalApi'; | 6 | import LocalApi from './LocalApi'; |
7 | import PaymentApi from './PaymentApi'; | 7 | import PaymentApi from './PaymentApi'; |
8 | import NewsApi from './NewsApi'; | 8 | import NewsApi from './NewsApi'; |
9 | import FeaturesApi from './FeaturesApi'; | ||
9 | 10 | ||
10 | export default (server, local) => ({ | 11 | export default (server, local) => ({ |
11 | app: new AppApi(server, local), | 12 | app: new AppApi(server, local), |
12 | services: new ServicesApi(server, local), | 13 | services: new ServicesApi(server, local), |
13 | recipePreviews: new RecipePreviewsApi(server, local), | 14 | recipePreviews: new RecipePreviewsApi(server, local), |
14 | recipes: new RecipesApi(server, local), | 15 | recipes: new RecipesApi(server, local), |
16 | features: new FeaturesApi(server, local), | ||
15 | user: new UserApi(server, local), | 17 | user: new UserApi(server, local), |
16 | local: new LocalApi(server, local), | 18 | local: new LocalApi(server, local), |
17 | payment: new PaymentApi(server, local), | 19 | payment: new PaymentApi(server, local), |
diff --git a/src/api/server/LocalApi.js b/src/api/server/LocalApi.js index 78deb7aa5..ab1604a27 100644 --- a/src/api/server/LocalApi.js +++ b/src/api/server/LocalApi.js | |||
@@ -3,26 +3,29 @@ import du from 'du'; | |||
3 | 3 | ||
4 | import { getServicePartitionsDirectory } from '../../helpers/service-helpers.js'; | 4 | import { getServicePartitionsDirectory } from '../../helpers/service-helpers.js'; |
5 | 5 | ||
6 | const debug = require('debug')('LocalApi'); | 6 | const debug = require('debug')('Franz:LocalApi'); |
7 | 7 | ||
8 | const { session } = remote; | 8 | const { session } = remote; |
9 | 9 | ||
10 | export default class LocalApi { | 10 | export default class LocalApi { |
11 | // Settings | 11 | // Settings |
12 | getAppSettings() { | 12 | getAppSettings(type) { |
13 | return new Promise((resolve) => { | 13 | return new Promise((resolve) => { |
14 | ipcRenderer.once('appSettings', (event, data) => { | 14 | ipcRenderer.once('appSettings', (event, resp) => { |
15 | debug('LocalApi::getAppSettings resolves', data); | 15 | debug('LocalApi::getAppSettings resolves', resp.type, resp.data); |
16 | resolve(data); | 16 | resolve(resp); |
17 | }); | 17 | }); |
18 | 18 | ||
19 | ipcRenderer.send('getAppSettings'); | 19 | ipcRenderer.send('getAppSettings', type); |
20 | }); | 20 | }); |
21 | } | 21 | } |
22 | 22 | ||
23 | async updateAppSettings(data) { | 23 | async updateAppSettings(type, data) { |
24 | debug('LocalApi::updateAppSettings resolves', data); | 24 | debug('LocalApi::updateAppSettings resolves', type, data); |
25 | ipcRenderer.send('updateAppSettings', data); | 25 | ipcRenderer.send('updateAppSettings', { |
26 | type, | ||
27 | data, | ||
28 | }); | ||
26 | } | 29 | } |
27 | 30 | ||
28 | // Services | 31 | // Services |
diff --git a/src/api/server/ServerApi.js b/src/api/server/ServerApi.js index 353faa7f4..164419951 100644 --- a/src/api/server/ServerApi.js +++ b/src/api/server/ServerApi.js | |||
@@ -27,7 +27,7 @@ import { | |||
27 | removeServicePartitionDirectory, | 27 | removeServicePartitionDirectory, |
28 | } from '../../helpers/service-helpers.js'; | 28 | } from '../../helpers/service-helpers.js'; |
29 | 29 | ||
30 | const debug = require('debug')('ServerApi'); | 30 | const debug = require('debug')('Franz:ServerApi'); |
31 | 31 | ||
32 | module.paths.unshift( | 32 | module.paths.unshift( |
33 | getDevRecipeDirectory(), | 33 | getDevRecipeDirectory(), |
@@ -35,7 +35,7 @@ module.paths.unshift( | |||
35 | ); | 35 | ); |
36 | 36 | ||
37 | const { app } = remote; | 37 | const { app } = remote; |
38 | const fetch = remote.require('electron-fetch'); | 38 | const { default: fetch } = remote.require('electron-fetch'); |
39 | 39 | ||
40 | const SERVER_URL = API; | 40 | const SERVER_URL = API; |
41 | const API_VERSION = 'v1'; | 41 | const API_VERSION = 'v1'; |
@@ -261,6 +261,35 @@ export default class ServerApi { | |||
261 | return data; | 261 | return data; |
262 | } | 262 | } |
263 | 263 | ||
264 | // Features | ||
265 | async getDefaultFeatures() { | ||
266 | const request = await window.fetch(`${SERVER_URL}/${API_VERSION}/features/default`, this._prepareAuthRequest({ | ||
267 | method: 'GET', | ||
268 | })); | ||
269 | if (!request.ok) { | ||
270 | throw request; | ||
271 | } | ||
272 | const data = await request.json(); | ||
273 | |||
274 | const features = data; | ||
275 | console.debug('ServerApi::getDefaultFeatures resolves', features); | ||
276 | return features; | ||
277 | } | ||
278 | |||
279 | async getFeatures() { | ||
280 | const request = await window.fetch(`${SERVER_URL}/${API_VERSION}/features`, this._prepareAuthRequest({ | ||
281 | method: 'GET', | ||
282 | })); | ||
283 | if (!request.ok) { | ||
284 | throw request; | ||
285 | } | ||
286 | const data = await request.json(); | ||
287 | |||
288 | const features = data; | ||
289 | console.debug('ServerApi::getFeatures resolves', features); | ||
290 | return features; | ||
291 | } | ||
292 | |||
264 | // Recipes | 293 | // Recipes |
265 | async getInstalledRecipes() { | 294 | async getInstalledRecipes() { |
266 | const recipesDirectory = getRecipeDirectory(); | 295 | const recipesDirectory = getRecipeDirectory(); |