diff options
| author | Pitu <[email protected]> | 2017-01-19 02:37:35 -0300 |
|---|---|---|
| committer | Pitu <[email protected]> | 2017-01-19 02:37:35 -0300 |
| commit | 83aaef0f824e8776ddf4c60a44e6d56c21a0efcc (patch) | |
| tree | b9474b361cc328d43fe5bfd4949702c6566819f2 /public/js/upload.js | |
| parent | Small fixes (diff) | |
| download | host.fuwn.me-83aaef0f824e8776ddf4c60a44e6d56c21a0efcc.tar.xz host.fuwn.me-83aaef0f824e8776ddf4c60a44e6d56c21a0efcc.zip | |
Changed request system and post data
Changed from XMLHttpRequest to Axiios and made every POST call to look for params or json and not pass the values as headers. Token is still a header though
Diffstat (limited to 'public/js/upload.js')
| -rw-r--r-- | public/js/upload.js | 83 |
1 files changed, 42 insertions, 41 deletions
diff --git a/public/js/upload.js b/public/js/upload.js index d6d9b9d..35208f3 100644 --- a/public/js/upload.js +++ b/public/js/upload.js @@ -5,16 +5,18 @@ upload.token = localStorage.token; upload.maxFileSize; upload.checkIfPublic = function(){ - var xhr = new XMLHttpRequest(); - xhr.onreadystatechange = function() { - if (xhr.readyState == XMLHttpRequest.DONE) { - upload.isPublic = JSON.parse(xhr.responseText).private; - upload.maxFileSize = JSON.parse(xhr.responseText).maxFileSize; - upload.preparePage(); - } - } - xhr.open('GET', '/api/check', true); - xhr.send(null); + + axios.get('/api/check') + .then(function (response) { + upload.isPublic = response.data.private; + upload.maxFileSize = response.data.maxFileSize; + upload.preparePage(); + }) + .catch(function (error) { + return swal("An error ocurred", 'There was an error with the request, please check the console for more information.', "error"); + console.log(error); + }); + } upload.preparePage = function(){ @@ -30,38 +32,37 @@ upload.preparePage = function(){ } upload.verifyToken = function(token, reloadOnError = false){ - var xhr = new XMLHttpRequest(); - - xhr.onreadystatechange = function() { - if (xhr.readyState == XMLHttpRequest.DONE) { - - var json = JSON.parse(xhr.responseText); - if(json.success === false){ - - swal({ - title: "An error ocurred", - text: json.description, - type: "error" - }, function(){ - if(reloadOnError){ - localStorage.removeItem("token"); - location.reload(); - } - }) - - return; - } - - localStorage.token = token; - upload.token = token; - return upload.prepareUpload(); - } - } - xhr.open('GET', '/api/tokens/verify', true); - xhr.setRequestHeader('type', 'client'); - xhr.setRequestHeader('token', token); - xhr.send(null); + axios.post('/api/tokens/verify', { + type: 'client', + token: token + }) + .then(function (response) { + + if(response.data.success === false){ + swal({ + title: "An error ocurred", + text: response.data.description, + type: "error" + }, function(){ + if(reloadOnError){ + localStorage.removeItem("token"); + location.reload(); + } + }) + return; + } + + localStorage.token = token; + upload.token = token; + return upload.prepareUpload(); + + }) + .catch(function (error) { + return swal("An error ocurred", 'There was an error with the request, please check the console for more information.', "error"); + console.log(error); + }); + } upload.prepareUpload = function(){ |