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

View File

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

View File

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

View File

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