aboutsummaryrefslogtreecommitdiffstats
path: root/src/api
diff options
context:
space:
mode:
authorLibravatar Vijay A <vraravam@users.noreply.github.com>2022-07-25 08:16:50 +0530
committerLibravatar Vijay A <vraravam@users.noreply.github.com>2022-07-25 08:17:10 +0530
commitcf282aa351cbc58691fb1b2fb4764830247cdbe8 (patch)
tree1a6ac4c9abd8b3de9d358016a5065da86cdd8510 /src/api
parent6.0.1-nightly.3 [skip ci] (diff)
downloadferdium-app-cf282aa351cbc58691fb1b2fb4764830247cdbe8.tar.gz
ferdium-app-cf282aa351cbc58691fb1b2fb4764830247cdbe8.tar.zst
ferdium-app-cf282aa351cbc58691fb1b2fb4764830247cdbe8.zip
eslint needs to be executed at the top-level to actually workv6.0.1-nightly.3
Diffstat (limited to 'src/api')
-rw-r--r--src/api/apiBase.ts10
-rw-r--r--src/api/server/ServerApi.ts6
-rw-r--r--src/api/utils/auth.ts10
3 files changed, 16 insertions, 10 deletions
diff --git a/src/api/apiBase.ts b/src/api/apiBase.ts
index d066d1466..fad20ca5e 100644
--- a/src/api/apiBase.ts
+++ b/src/api/apiBase.ts
@@ -32,10 +32,12 @@ export default function apiBase(withVersion = true) {
32 : (window as any).ferdium.stores.settings.all.app.server; 32 : (window as any).ferdium.stores.settings.all.app.server;
33 33
34 return fixUrl(withVersion ? `${url}/${API_VERSION}` : url); 34 return fixUrl(withVersion ? `${url}/${API_VERSION}` : url);
35}; 35}
36 36
37export function needsToken(): boolean { 37export function needsToken(): boolean {
38 return (window as any).ferdium.stores.settings.all.app.server === LOCAL_SERVER; 38 return (
39 (window as any).ferdium.stores.settings.all.app.server === LOCAL_SERVER
40 );
39} 41}
40 42
41export function localServerToken(): string | undefined { 43export function localServerToken(): string | undefined {
@@ -46,9 +48,7 @@ export function localServerToken(): string | undefined {
46 48
47export function importExportURL() { 49export function importExportURL() {
48 const base = apiBase(false); 50 const base = apiBase(false);
49 return needsToken() 51 return needsToken() ? `${base}/token/${localServerToken()}` : base;
50 ? `${base}/token/${localServerToken()}`
51 : base;
52} 52}
53 53
54export function serverBase() { 54export function serverBase() {
diff --git a/src/api/server/ServerApi.ts b/src/api/server/ServerApi.ts
index 8b551ade2..a3d873c65 100644
--- a/src/api/server/ServerApi.ts
+++ b/src/api/server/ServerApi.ts
@@ -25,7 +25,11 @@ import { SERVER_NOT_LOADED } from '../../config';
25import { userDataRecipesPath, userDataPath } from '../../environment-remote'; 25import { userDataRecipesPath, userDataPath } from '../../environment-remote';
26import { asarRecipesPath } from '../../helpers/asar-helpers'; 26import { asarRecipesPath } from '../../helpers/asar-helpers';
27import apiBase from '../apiBase'; 27import apiBase from '../apiBase';
28import { prepareAuthRequest, prepareLocalToken, sendAuthRequest } from '../utils/auth'; 28import {
29 prepareAuthRequest,
30 prepareLocalToken,
31 sendAuthRequest,
32} from '../utils/auth';
29 33
30import { 34import {
31 getRecipeDirectory, 35 getRecipeDirectory,
diff --git a/src/api/utils/auth.ts b/src/api/utils/auth.ts
index 282d00459..1f694a781 100644
--- a/src/api/utils/auth.ts
+++ b/src/api/utils/auth.ts
@@ -31,15 +31,17 @@ export const prepareAuthRequest = (
31 return request; 31 return request;
32}; 32};
33 33
34export const prepareLocalToken = async ( 34export const prepareLocalToken = async (requestData: {
35 requestData: { method: string; headers?: any; body?: any }, 35 method: string;
36) => { 36 headers?: any;
37 body?: any;
38}) => {
37 await when(() => !needsToken() || !!localServerToken(), { timeout: 2000 }); 39 await when(() => !needsToken() || !!localServerToken(), { timeout: 2000 });
38 const token = localServerToken(); 40 const token = localServerToken();
39 if (token) { 41 if (token) {
40 requestData.headers['X-Ferdium-Local-Token'] = token; 42 requestData.headers['X-Ferdium-Local-Token'] = token;
41 } 43 }
42} 44};
43 45
44export const sendAuthRequest = async ( 46export const sendAuthRequest = async (
45 url: RequestInfo, 47 url: RequestInfo,