|
|
|
|
@ -1,3 +1,6 @@
|
|
|
|
|
|
|
|
|
|
import { WEB_VERSION } from '@/config'
|
|
|
|
|
|
|
|
|
|
function checkStatus(response) {
|
|
|
|
|
if (response.status >= 200 && response.status < 300) {
|
|
|
|
|
return response
|
|
|
|
|
@ -12,8 +15,12 @@ function checkStatus(response) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function fetchText(url) {
|
|
|
|
|
return fetch(url)
|
|
|
|
|
.then(checkStatus)
|
|
|
|
|
return fetch(url, {
|
|
|
|
|
method: 'GET',
|
|
|
|
|
headers: {
|
|
|
|
|
'X-Web-Version': WEB_VERSION
|
|
|
|
|
}
|
|
|
|
|
}).then(checkStatus)
|
|
|
|
|
.then(response => response.text())
|
|
|
|
|
.catch(error => {
|
|
|
|
|
throw error
|
|
|
|
|
@ -23,8 +30,12 @@ export function fetchText(url) {
|
|
|
|
|
export function fetchJSON(url, data) {
|
|
|
|
|
const params = data ? new URLSearchParams(data).toString() : '';
|
|
|
|
|
const ifp = url.includes('?') ? '&' : '?';
|
|
|
|
|
return fetch(`${url}${ifp}${params}`)
|
|
|
|
|
.then(checkStatus)
|
|
|
|
|
return fetch(`${url}${ifp}${params}`, {
|
|
|
|
|
method: 'GET',
|
|
|
|
|
headers: {
|
|
|
|
|
'X-Web-Version': WEB_VERSION
|
|
|
|
|
}
|
|
|
|
|
}).then(checkStatus)
|
|
|
|
|
.then(response => response.json())
|
|
|
|
|
.catch(error => {
|
|
|
|
|
throw error;
|
|
|
|
|
@ -34,7 +45,10 @@ export function fetchJSON(url, data) {
|
|
|
|
|
export function postForm(url, data) {
|
|
|
|
|
return fetch(url, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: data
|
|
|
|
|
body: data,
|
|
|
|
|
headers: {
|
|
|
|
|
'X-Web-Version': WEB_VERSION
|
|
|
|
|
}
|
|
|
|
|
}).then(checkStatus)
|
|
|
|
|
.then(response => response.json())
|
|
|
|
|
.catch(error => {
|
|
|
|
|
@ -47,7 +61,8 @@ export function postJSON(url, obj) {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: JSON.stringify(obj),
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-type': 'application/json; charset=UTF-8'
|
|
|
|
|
'Content-type': 'application/json; charset=UTF-8',
|
|
|
|
|
'X-Web-Version': WEB_VERSION
|
|
|
|
|
}
|
|
|
|
|
}).then(checkStatus)
|
|
|
|
|
.then(response => response.json())
|
|
|
|
|
@ -61,7 +76,8 @@ export function postStream(url, obj) {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: JSON.stringify(obj),
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-type': 'application/octet-stream'
|
|
|
|
|
'Content-type': 'application/octet-stream',
|
|
|
|
|
'X-Web-Version': WEB_VERSION
|
|
|
|
|
}
|
|
|
|
|
}).then(checkStatus)
|
|
|
|
|
.then(response => response.json())
|
|
|
|
|
|