aboutsummaryrefslogtreecommitdiffstats
path: root/settings/src/store/api.js
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-03-09 17:46:34 +0100
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-05-16 09:50:20 +0200
commitc8f670dd8f2982f455662a24be67ad89f8ca2915 (patch)
tree296e14353e3a94b33b97c50646974840d1b3c4bd /settings/src/store/api.js
parent7de6c06c66df859f6e5ffcd4e0c85580b3c4d365 (diff)
downloadnextcloud-server-c8f670dd8f2982f455662a24be67ad89f8ca2915.tar.gz
nextcloud-server-c8f670dd8f2982f455662a24be67ad89f8ca2915.zip
Settings to vuejs
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'settings/src/store/api.js')
-rw-r--r--settings/src/store/api.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/settings/src/store/api.js b/settings/src/store/api.js
new file mode 100644
index 00000000000..d67c77a5ff3
--- /dev/null
+++ b/settings/src/store/api.js
@@ -0,0 +1,50 @@
+import axios from 'axios';
+
+const requestToken = document.getElementsByTagName('head')[0].getAttribute('data-requesttoken');
+const tokenHeaders = { headers: { requesttoken: requestToken } };
+
+const sanitize = function(url) {
+ return url.replace(/\/$/, ''); // Remove last slash of url
+}
+
+export default {
+ requireAdmin() {
+ return new Promise(function(resolve, reject) {
+ setTimeout(reject, 5000); // automatically reject 5s if not ok
+ function waitForpassword() {
+ if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
+ setTimeout(waitForpassword, 500);
+ return;
+ }
+ resolve();
+ }
+ waitForpassword();
+ OC.PasswordConfirmation.requirePasswordConfirmation();
+ }).catch((error) => console.log('Required password not entered'));
+ },
+ get(url) {
+ return axios.get(sanitize(url), tokenHeaders)
+ .then((response) => Promise.resolve(response))
+ .catch((error) => Promise.reject(error));
+ },
+ post(url, data) {
+ return axios.post(sanitize(url), data, tokenHeaders)
+ .then((response) => Promise.resolve(response))
+ .catch((error) => Promise.reject(error));
+ },
+ patch(url, data) {
+ return axios.patch(sanitize(url), { data: data, headers: tokenHeaders.headers })
+ .then((response) => Promise.resolve(response))
+ .catch((error) => Promise.reject(error));
+ },
+ put(url, data) {
+ return axios.put(sanitize(url), data, tokenHeaders)
+ .then((response) => Promise.resolve(response))
+ .catch((error) => Promise.reject(error));
+ },
+ delete(url, data) {
+ return axios.delete(sanitize(url), { data: data, headers: tokenHeaders.headers })
+ .then((response) => Promise.resolve(response))
+ .catch((error) => Promise.reject(error));
+ }
+}; \ No newline at end of file