feat: allow GET for some endpoints

Resolve #8263
This commit is contained in:
syuilo
2022-06-25 18:26:31 +09:00
parent 7be4b2145b
commit 58e83f8e4f
24 changed files with 146 additions and 46 deletions

View File

@@ -52,6 +52,39 @@ export const api = ((endpoint: string, data: Record<string, any> = {}, token?: s
return promise;
}) as typeof apiClient.request;
export const apiGet = ((endpoint: string, data: Record<string, any> = {}) => {
pendingApiRequestsCount.value++;
const onFinally = () => {
pendingApiRequestsCount.value--;
};
const query = new URLSearchParams(data);
const promise = new Promise((resolve, reject) => {
// Send request
fetch(`${apiUrl}/${endpoint}?${query}`, {
method: 'GET',
credentials: 'omit',
cache: 'default',
}).then(async (res) => {
const body = res.status === 204 ? null : await res.json();
if (res.status === 200) {
resolve(body);
} else if (res.status === 204) {
resolve();
} else {
reject(body.error);
}
}).catch(reject);
});
promise.then(onFinally, onFinally);
return promise;
}) as typeof apiClient.request;
export const apiWithDialog = ((
endpoint: string,
data: Record<string, any> = {},