summaryrefslogtreecommitdiff
path: root/src/web/app/common/scripts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-03-03 14:42:25 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-03-03 14:42:25 +0900
commitbec7ed723be235b94daf1d5e5aa7f595bf7d9815 (patch)
treef1959261337e300b0c60dcb066e5d54c22551a0c /src/web/app/common/scripts
parent:v: (diff)
downloadsharkey-bec7ed723be235b94daf1d5e5aa7f595bf7d9815.tar.gz
sharkey-bec7ed723be235b94daf1d5e5aa7f595bf7d9815.tar.bz2
sharkey-bec7ed723be235b94daf1d5e5aa7f595bf7d9815.zip
:v:
Diffstat (limited to 'src/web/app/common/scripts')
-rw-r--r--src/web/app/common/scripts/api.ts47
1 files changed, 0 insertions, 47 deletions
diff --git a/src/web/app/common/scripts/api.ts b/src/web/app/common/scripts/api.ts
deleted file mode 100644
index bba838f56b..0000000000
--- a/src/web/app/common/scripts/api.ts
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * API Request
- */
-
-declare const _API_URL_: string;
-
-let spinner = null;
-let pending = 0;
-
-/**
- * Send a request to API
- * @param {string|Object} i Credential
- * @param {string} endpoint Endpoint
- * @param {any} [data={}] Data
- * @return {Promise<any>} Response
- */
-export default (i, endpoint, data = {}): Promise<{ [x: string]: any }> => {
- if (++pending === 1) {
- spinner = document.createElement('div');
- spinner.setAttribute('id', 'wait');
- document.body.appendChild(spinner);
- }
-
- // Append the credential
- if (i != null) (data as any).i = typeof i === 'object' ? i.token : i;
-
- return new Promise((resolve, reject) => {
- // Send request
- fetch(endpoint.indexOf('://') > -1 ? endpoint : `${_API_URL_}/${endpoint}`, {
- method: 'POST',
- body: JSON.stringify(data),
- credentials: endpoint === 'signin' ? 'include' : 'omit',
- cache: 'no-cache'
- }).then(res => {
- if (--pending === 0) spinner.parentNode.removeChild(spinner);
- if (res.status === 200) {
- res.json().then(resolve);
- } else if (res.status === 204) {
- resolve();
- } else {
- res.json().then(err => {
- reject(err.error);
- }, reject);
- }
- }).catch(reject);
- });
-};