-
-
Notifications
You must be signed in to change notification settings - Fork 286
/
Copy pathsystem.ts
89 lines (87 loc) · 2.35 KB
/
system.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { API_BASE } from '@/utils/constants';
import { baseHeaders } from '@/utils/request';
const System = {
hasSetting: async (
label: string
): Promise<{ label: string; exists: boolean }> => {
return fetch(`${API_BASE}/system/setting/${label}/exists`, {
method: 'GET',
cache: 'no-cache',
headers: baseHeaders(),
})
.then((res) => res.json())
.then((res) => res)
.catch((e) => {
console.error(e);
return { label, exists: false, error: e.message };
});
},
getSetting: async (label: string): Promise<{ label: string; value: any }> => {
return fetch(`${API_BASE}/system/setting/${label}`, {
method: 'GET',
cache: 'no-cache',
headers: baseHeaders(),
})
.then((res) => res.json())
.then((res) => res)
.catch((e) => {
console.error(e);
return { label, value: null, error: e.message };
});
},
updateSettings: async (
config = {}
): Promise<{ success: boolean; error: null | string }> => {
return fetch(`${API_BASE}/system/update-settings`, {
method: 'POST',
cache: 'no-cache',
body: JSON.stringify({ config }),
headers: baseHeaders(),
})
.then((res) => res.json())
.then((res) => res)
.catch((e) => {
console.error(e);
return { success: false, error: e.message };
});
},
documentProcessorOnline: async () => {
return fetch(`${API_BASE}/v1/document-processor/status`, {
method: 'GET',
cache: 'no-cache',
headers: baseHeaders(),
})
.then((res) => res.ok)
.then((res) => res)
.catch((e) => {
console.error(e);
return false;
});
},
acceptedDocumentTypes: async () => {
return fetch(`${API_BASE}/v1/document-processor/filetypes`, {
method: 'GET',
cache: 'no-cache',
headers: baseHeaders(),
})
.then((res) => res.json())
.then((res) => res?.types)
.catch((e) => {
console.error(e);
return null;
});
},
onboardingComplete: async (): Promise<boolean> => {
return fetch(`${API_BASE}/system/onboarding-complete`, {
method: 'GET',
cache: 'no-cache',
})
.then((res) => res.json())
.then((res) => res.completed)
.catch((e) => {
console.error(e);
return false;
});
},
};
export default System;