This commit is contained in:
2018-11-14 22:34:41 +00:00
parent 2f92d587e4
commit 105c8c9a78
3 changed files with 19 additions and 16 deletions

View File

@@ -14,7 +14,7 @@ export default {
json(response) {
return response.json();
},
PatchAuthorizedHeaders() {
patchAuthorizedHeaders() {
return {
//Accept: "application/json, text/plain, */*",
Accept: "application/json",
@@ -22,14 +22,14 @@ export default {
Authorization: "Bearer " + store.state.apiToken
};
},
PostAuthorizedHeaders() {
postAuthorizedHeaders() {
return {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: "Bearer " + store.state.apiToken
};
},
PostUnAuthorizedHeaders() {
postUnAuthorizedHeaders() {
return {
Accept: "application/json",
"Content-Type": "application/json"
@@ -39,11 +39,19 @@ export default {
return {
method: "post",
mode: "cors",
headers: this.PostUnAuthorizedHeaders(),
headers: this.postUnAuthorizedHeaders(),
body: JSON.stringify(data)
};
},
APIUrl() {
return store.state.apiUrl;
fetchPost(data) {
return {
method: "post",
mode: "cors",
headers: this.postAuthorizedHeaders(),
body: JSON.stringify(data)
};
},
APIUrl(apiPath) {
return store.state.apiUrl + apiPath;
}
};

View File

@@ -5,7 +5,7 @@ import { processLogin, processLogout } from "../utils/authutil";
export default {
async authenticate(login, password) {
return fetch(
apiUtil.APIUrl() + "auth",
apiUtil.APIUrl("auth"),
apiUtil.fetchPostNoAuth({
login: login,
password: password

View File

@@ -13,23 +13,18 @@ export default {
fetch(keys) {
return new Promise(function(resolve, reject) {
//step 1: build an array of keys that we don't have already
var NeedIt = [];
var needIt = [];
for (var i = 0; i < keys.length; i++) {
if (!_.has(store.state.localeText, keys[i])) {
NeedIt.push(keys[i]);
needIt.push(keys[i]);
}
}
if (NeedIt.length == 0) {
if (needIt.length == 0) {
resolve();
return;
}
//step 2: get it
fetch(apiUtil.APIUrl() + "locale/subset", {
method: "post",
mode: "cors",
headers: apiUtil.PostAuthorizedHeaders(),
body: JSON.stringify(NeedIt)
})
fetch(apiUtil.APIUrl("locale/subset"), apiUtil.fetchPost(needIt))
.then(apiUtil.status)
.then(apiUtil.json)
.then(response => {