Replace hand-crafted request token logic by nextcloud-axios lib

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
Christoph Wurst 2018-10-08 15:26:54 +02:00
parent 8110a3be69
commit c5c576addd
No known key found for this signature in database
GPG Key ID: CC42AC2A7F0E56D8
4 changed files with 26 additions and 41 deletions

View File

@ -3292,8 +3292,7 @@
"ansi-regex": {
"version": "2.1.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"aproba": {
"version": "1.2.0",
@ -3314,14 +3313,12 @@
"balanced-match": {
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@ -3336,20 +3333,17 @@
"code-point-at": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"core-util-is": {
"version": "1.0.2",
@ -3466,8 +3460,7 @@
"inherits": {
"version": "2.0.3",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"ini": {
"version": "1.3.5",
@ -3479,7 +3472,6 @@
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@ -3494,7 +3486,6 @@
"version": "3.0.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
@ -3502,14 +3493,12 @@
"minimist": {
"version": "0.0.8",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"minipass": {
"version": "2.2.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.1",
"yallist": "^3.0.0"
@ -3528,7 +3517,6 @@
"version": "0.5.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
@ -3609,8 +3597,7 @@
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"object-assign": {
"version": "4.1.1",
@ -3622,7 +3609,6 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"wrappy": "1"
}
@ -3708,8 +3694,7 @@
"safe-buffer": {
"version": "5.1.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"safer-buffer": {
"version": "2.1.2",
@ -3745,7 +3730,6 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
@ -3765,7 +3749,6 @@
"version": "3.0.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"ansi-regex": "^2.0.0"
}
@ -3809,14 +3792,12 @@
"wrappy": {
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"yallist": {
"version": "3.0.2",
"bundled": true,
"dev": true,
"optional": true
"dev": true
}
}
},
@ -5078,6 +5059,14 @@
"integrity": "sha512-vdqTKI9GBIYcAEbFAcpKPErKINfPF5zIuz3/niBfq8WUZjpT2tytLlFVrBgWdOtqI4uaA/Rb6No0hux39XXDuw==",
"dev": true
},
"nextcloud-axios": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/nextcloud-axios/-/nextcloud-axios-0.1.2.tgz",
"integrity": "sha512-iGmsgetYead0678dpExmYaN4odpiKjKxtPpzuk3TyB1UoQJs4Mop+Dozh1ryWLA0Nqzng9HIvsWkBqLxAm3q5g==",
"requires": {
"axios": "^0.18.0"
}
},
"nextcloud-vue": {
"version": "0.1.5",
"resolved": "https://registry.npmjs.org/nextcloud-vue/-/nextcloud-vue-0.1.5.tgz",

View File

@ -12,7 +12,7 @@
},
"dependencies": {
"@babel/polyfill": "^7.0.0",
"axios": "^0.18.0",
"nextcloud-axios": "^0.1.2",
"nextcloud-vue": "^0.1.5",
"v-tooltip": "^2.0.0-rc.33",
"vue": "^2.5.17",

View File

@ -20,10 +20,7 @@
*
*/
import axios from 'axios';
const requestToken = document.getElementsByTagName('head')[0].getAttribute('data-requesttoken');
const tokenHeaders = { headers: { requesttoken: requestToken } };
import axios from 'nextcloud-axios'
const sanitize = function(url) {
return url.replace(/\/$/, ''); // Remove last url slash
@ -94,27 +91,27 @@ export default {
});
},
get(url) {
return axios.get(sanitize(url), tokenHeaders)
return axios.get(sanitize(url))
.then((response) => Promise.resolve(response))
.catch((error) => Promise.reject(error));
},
post(url, data) {
return axios.post(sanitize(url), data, tokenHeaders)
return axios.post(sanitize(url), data)
.then((response) => Promise.resolve(response))
.catch((error) => Promise.reject(error));
},
patch(url, data) {
return axios.patch(sanitize(url), data, tokenHeaders)
return axios.patch(sanitize(url), data)
.then((response) => Promise.resolve(response))
.catch((error) => Promise.reject(error));
},
put(url, data) {
return axios.put(sanitize(url), data, tokenHeaders)
return axios.put(sanitize(url), data)
.then((response) => Promise.resolve(response))
.catch((error) => Promise.reject(error));
},
delete(url, data) {
return axios.delete(sanitize(url), { data: data, headers: tokenHeaders.headers })
return axios.delete(sanitize(url), { data: data })
.then((response) => Promise.resolve(response))
.catch((error) => Promise.reject(error));
}

View File

@ -21,7 +21,6 @@
*/
import api from './api';
import axios from 'axios/index';
import Vue from 'vue';
const state = {