|
1 | 1 | import ec from './config'; |
2 | 2 |
|
3 | 3 | function getGraph(serverID) { |
4 | | - return new Promise((resolve, reject) => { |
5 | | - fetch(`${ec.baseURL + ec.getGraph(serverID)}`).then((x) => { |
6 | | - resolve(x.text()); |
7 | | - }).catch((e) => reject(e)); |
8 | | - }); |
| 4 | + return fetch(`${ec.baseURL + ec.getGraph(serverID)}`).then((x) => x.text()); |
9 | 5 | } |
10 | 6 |
|
11 | 7 | function getGraphWithHashCheck(serverID, latestHash) { |
12 | | - return new Promise((resolve, reject) => { |
13 | | - fetch(`${ec.baseURL + ec.getGraph(serverID)}`, { |
14 | | - headers: { |
15 | | - 'X-Latest-Hash': latestHash, |
16 | | - }, |
17 | | - }).then((x) => { |
18 | | - if (x.status === 200) resolve(x.text()); |
19 | | - else reject(x.text()); |
20 | | - }).catch((e) => reject(e)); |
| 8 | + return fetch(`${ec.baseURL + ec.getGraph(serverID)}`, { |
| 9 | + headers: { |
| 10 | + 'X-Latest-Hash': latestHash, |
| 11 | + }, |
| 12 | + }).then((x) => { |
| 13 | + if (x.status === 200) return x.text(); |
| 14 | + return Promise.reject(x.text()); |
21 | 15 | }); |
22 | 16 | } |
23 | 17 |
|
24 | 18 | function postGraph(graphml) { |
25 | | - return new Promise((resolve, reject) => { |
26 | | - fetch(`${ec.baseURL + ec.postGraph}/`, { |
27 | | - headers: { |
28 | | - 'Content-Type': 'application/xml', |
29 | | - }, |
30 | | - method: 'POST', |
31 | | - body: graphml, |
32 | | - |
33 | | - }).then((x) => { |
34 | | - resolve(x.text()); |
35 | | - }).catch((e) => reject(e)); |
| 19 | + return fetch(`${ec.baseURL + ec.postGraph}/`, { |
| 20 | + headers: { |
| 21 | + 'Content-Type': 'application/xml', |
| 22 | + }, |
| 23 | + method: 'POST', |
| 24 | + body: graphml, |
| 25 | + }).then((x) => { |
| 26 | + if (!x.ok) return Promise.reject(x.text()); |
| 27 | + return x.text(); |
36 | 28 | }); |
37 | 29 | } |
38 | 30 |
|
39 | 31 | function updateGraph(serverID, graphml) { |
40 | | - return new Promise((resolve, reject) => { |
41 | | - fetch(ec.baseURL + ec.updateGraph(serverID), { |
42 | | - method: 'POST', |
43 | | - headers: { |
44 | | - 'Content-Type': 'application/xml', |
45 | | - }, |
46 | | - body: graphml, |
47 | | - }).then((x) => { |
48 | | - resolve(x.text()); |
49 | | - }).catch((e) => reject(e)); |
| 32 | + return fetch(ec.baseURL + ec.updateGraph(serverID), { |
| 33 | + method: 'POST', |
| 34 | + headers: { |
| 35 | + 'Content-Type': 'application/xml', |
| 36 | + }, |
| 37 | + body: graphml, |
| 38 | + }).then((x) => { |
| 39 | + if (!x.ok) return Promise.reject(x.text()); |
| 40 | + return x.text(); |
50 | 41 | }); |
51 | 42 | } |
52 | 43 |
|
53 | 44 | function forceUpdateGraph(serverID, graphml) { |
54 | | - return new Promise((resolve, reject) => { |
55 | | - fetch(ec.baseURL + ec.forceUpdateGraph(serverID), { |
56 | | - method: 'POST', |
57 | | - headers: { |
58 | | - 'Content-Type': 'application/xml', |
59 | | - }, |
60 | | - body: graphml, |
61 | | - }).then((x) => { |
62 | | - resolve(x.text()); |
63 | | - }).catch((e) => reject(e)); |
| 45 | + return fetch(ec.baseURL + ec.forceUpdateGraph(serverID), { |
| 46 | + method: 'POST', |
| 47 | + headers: { |
| 48 | + 'Content-Type': 'application/xml', |
| 49 | + }, |
| 50 | + body: graphml, |
| 51 | + }).then((x) => { |
| 52 | + if (!x.ok) return Promise.reject(x.text()); |
| 53 | + return x.text(); |
64 | 54 | }); |
65 | 55 | } |
66 | 56 |
|
|
0 commit comments