aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Vijay A <avijayr@protonmail.com>2021-06-05 07:58:00 +0530
committerLibravatar Vijay Raghavan Aravamudhan <vraravam@users.noreply.github.com>2021-06-05 08:03:31 +0530
commit368471dba24587415cae04ca33879404fb8639a5 (patch)
treeb216754eed7d6f478ceefea9ef3c0ab5698581d4
parentUpgraded electron to '13.1.1'. (diff)
downloadferdi-368471dba24587415cae04ca33879404fb8639a5.tar.gz
ferdi-368471dba24587415cae04ca33879404fb8639a5.tar.zst
ferdi-368471dba24587415cae04ca33879404fb8639a5.zip
Reused commonly defined method for 'apiBase'
-rw-r--r--src/api/apiBase.js3
-rw-r--r--src/api/server/ServerApi.js4
-rw-r--r--src/features/announcements/api.js7
-rw-r--r--src/features/planSelection/api.js4
4 files changed, 10 insertions, 8 deletions
diff --git a/src/api/apiBase.js b/src/api/apiBase.js
index 85dd0f3d..842c85e5 100644
--- a/src/api/apiBase.js
+++ b/src/api/apiBase.js
@@ -18,7 +18,8 @@ const apiBase = (withVersion = true) => {
18 || !window.ferdi.stores.settings.all.app.server) { 18 || !window.ferdi.stores.settings.all.app.server) {
19 // Stores have not yet been loaded - return SERVER_NOT_LOADED to force a retry when stores are loaded 19 // Stores have not yet been loaded - return SERVER_NOT_LOADED to force a retry when stores are loaded
20 return SERVER_NOT_LOADED; 20 return SERVER_NOT_LOADED;
21 } if (window.ferdi.stores.settings.all.app.server === LOCAL_SERVER) { 21 }
22 if (window.ferdi.stores.settings.all.app.server === LOCAL_SERVER) {
22 // Use URL for local server 23 // Use URL for local server
23 url = `http://127.0.0.1:${window.ferdi.stores.requests.localServerPort}`; 24 url = `http://127.0.0.1:${window.ferdi.stores.requests.localServerPort}`;
24 } else { 25 } else {
diff --git a/src/api/server/ServerApi.js b/src/api/server/ServerApi.js
index 5fd5268c..5365f9db 100644
--- a/src/api/server/ServerApi.js
+++ b/src/api/server/ServerApi.js
@@ -457,7 +457,7 @@ export default class ServerApi {
457 457
458 // News 458 // News
459 async getLatestNews() { 459 async getLatestNews() {
460 const url = `https://api.getferdi.com/v1/news?platform=${os.platform()}&arch=${os.arch()}&version=${app.getVersion()}`; 460 const url = `${apiBase(true)}/news?platform=${os.platform()}&arch=${os.arch()}&version=${app.getVersion()}`;
461 const request = await sendAuthRequest(url); 461 const request = await sendAuthRequest(url);
462 if (!request.ok) throw request; 462 if (!request.ok) throw request;
463 const data = await request.json(); 463 const data = await request.json();
@@ -467,7 +467,7 @@ export default class ServerApi {
467 } 467 }
468 468
469 async hideNews(id) { 469 async hideNews(id) {
470 const request = await sendAuthRequest(`https://api.getferdi.com/v1/news/${id}/read`); 470 const request = await sendAuthRequest(`${apiBase(true)}/news/${id}/read`);
471 if (!request.ok) throw request; 471 if (!request.ok) throw request;
472 debug('ServerApi::hideNews resolves', id); 472 debug('ServerApi::hideNews resolves', id);
473 } 473 }
diff --git a/src/features/announcements/api.js b/src/features/announcements/api.js
index 2ab5a15b..2c4d11d0 100644
--- a/src/features/announcements/api.js
+++ b/src/features/announcements/api.js
@@ -1,5 +1,6 @@
1import { app } from '@electron/remote'; 1import { app } from '@electron/remote';
2import Request from '../../stores/lib/Request'; 2import Request from '../../stores/lib/Request';
3import apiBase from '../../api/apiBase';
3 4
4const debug = require('debug')('Ferdi:feature:announcements:api'); 5const debug = require('debug')('Ferdi:feature:announcements:api');
5 6
@@ -10,8 +11,8 @@ export const announcementsApi = {
10 }, 11 },
11 12
12 async getChangelog(version) { 13 async getChangelog(version) {
13 debug('fetching release changelog from Github');
14 const url = `https://api.github.com/repos/getferdi/ferdi/releases/tags/v${version}`; 14 const url = `https://api.github.com/repos/getferdi/ferdi/releases/tags/v${version}`;
15 debug(`fetching release changelog from Github url: ${url}`);
15 const request = await window.fetch(url, { method: 'GET' }); 16 const request = await window.fetch(url, { method: 'GET' });
16 if (!request.ok) return null; 17 if (!request.ok) return null;
17 const data = await request.json(); 18 const data = await request.json();
@@ -19,8 +20,8 @@ export const announcementsApi = {
19 }, 20 },
20 21
21 async getAnnouncement(version) { 22 async getAnnouncement(version) {
22 debug('fetching release announcement from api'); 23 const url = `${apiBase(true)}/announcements/${version}`;
23 const url = `https://api.getferdi.com/v1/announcements/${version}`; 24 debug(`fetching release announcement from api url: ${url}`);
24 const response = await window.fetch(url, { method: 'GET' }); 25 const response = await window.fetch(url, { method: 'GET' });
25 if (!response.ok) return null; 26 if (!response.ok) return null;
26 return response.json(); 27 return response.json();
diff --git a/src/features/planSelection/api.js b/src/features/planSelection/api.js
index 65e6c2e8..16bf9ff2 100644
--- a/src/features/planSelection/api.js
+++ b/src/features/planSelection/api.js
@@ -1,12 +1,12 @@
1import { sendAuthRequest } from '../../api/utils/auth'; 1import { sendAuthRequest } from '../../api/utils/auth';
2import { API, API_VERSION } from '../../environment';
3import Request from '../../stores/lib/Request'; 2import Request from '../../stores/lib/Request';
3import apiBase from '../../api/apiBase';
4 4
5const debug = require('debug')('Ferdi:feature:planSelection:api'); 5const debug = require('debug')('Ferdi:feature:planSelection:api');
6 6
7export const planSelectionApi = { 7export const planSelectionApi = {
8 downgrade: async () => { 8 downgrade: async () => {
9 const url = `${API}/${API_VERSION}/payment/downgrade`; 9 const url = `${apiBase()}/payment/downgrade`;
10 const options = { 10 const options = {
11 method: 'PUT', 11 method: 'PUT',
12 }; 12 };