Updated API to manage TokenTree
This commit is contained in:
parent
4e40f26e64
commit
3c04f3cc50
|
@ -67,6 +67,10 @@ APIClass.prototype = {
|
|||
|
||||
/* si success de requête */
|
||||
if( [0,200,417].indexOf(ptrAPI.xhr[i].status) > -1 ){ // si fichier existe et reçu
|
||||
|
||||
// Récupération token TreeToken
|
||||
window._token_ = ptrAPI.xhr[i].getResponseHeader('X-Tree-Token');
|
||||
|
||||
var parsedResponse = {ModuleError:-1, ErrorDescription:'Erreur au niveau de api.js'};
|
||||
|
||||
// On essaie de parser le json
|
||||
|
@ -107,7 +111,14 @@ APIClass.prototype = {
|
|||
|
||||
|
||||
// Gestion du token optionnel
|
||||
if( pToken != null ) this.xhr[i].setRequestHeader('Authorization', 'Digest '+pToken);
|
||||
if( pToken != null )
|
||||
this.xhr[i].setRequestHeader('Authorization', 'Digest '+pToken);
|
||||
|
||||
// Gestion du token (TreeToken)
|
||||
if( window._token_ == null )
|
||||
this.xhr[i].setRequestHeader('X-Tree-Token', JSON.parse('{"'+document.cookie.replace(/=/g,'":"').replace(/; /g,'","')+'"}')._PUBLIC_);
|
||||
else
|
||||
this.xhr[i].setRequestHeader('X-Tree-Token', window._token_);
|
||||
|
||||
|
||||
// Header pour dire que c'est AJAX
|
||||
|
|
|
@ -1,4 +1 @@
|
|||
function APIClass(c){this.target=c}
|
||||
APIClass.prototype={xhr:[],buffer:null,optionalParams:[],send:function(c,f,g){c.hasOwnProperty("path")||f({ModuleError:4});for(var a=0;a<this.xhr.length;a++)4==this.xhr[a].readyState&&this.xhr.splice(a,1);this.xhr.push(null);a=this.xhr.length-1;this.optionalParams[a]=[];if(3<arguments.length)for(var d=3;d<arguments.length;d++)this.optionalParams[a].push(arguments[d]);this.xhr[a]=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHttpRequest");var e=this;this.xhr[a].onreadystatechange=
|
||||
function(){if(4==e.xhr[a].readyState)if(e.buffer=e.xhr[a].responseText,console.log("api request",c),-1<[0,200,417].indexOf(e.xhr[a].status)){var b={ModuleError:-1,ErrorDescription:"Erreur au niveau de api.js"};try{b=JSON.parse(e.xhr[a].responseText)}catch(d){}console.log("api response",b);b.hasOwnProperty("ModuleError")&&0!=b.ModuleError&&console.error("ModuleError::"+b.ModuleError);f(b,e.optionalParams[a])}else f({ModuleError:-2,ModuleDescription:"Erreur au niveau d'AJAX."})};var d=new FormData,
|
||||
b;for(b in c)"path"==b?d.append(b,c[b]):c[b]instanceof File?d.append(b,c[b]):d.append(b,JSON.stringify(c[b]));this.xhr[a].open("POST",this.target,!0);null!=g&&this.xhr[a].setRequestHeader("Authorization","Digest "+g);this.xhr[a].setRequestHeader("X-Requested-With","XMLHttpRequest");this.xhr[a].send(d)}};
|
||||
function APIClass(e){this.target=e}APIClass.prototype={xhr:[],buffer:null,optionalParams:[],send:function(e,r,t){e.hasOwnProperty("path")||r({ModuleError:4});for(var s=0;s<this.xhr.length;s++)4==this.xhr[s].readyState&&this.xhr.splice(s,1);if(this.xhr.push(null),s=this.xhr.length-1,this.optionalParams[s]=[],arguments.length>3)for(var o=3;o<arguments.length;o++)this.optionalParams[s].push(arguments[o]);window.XMLHttpRequest?this.xhr[s]=new XMLHttpRequest:this.xhr[s]=new ActiveXObject("Microsoft.XMLHttpRequest");var n=this;this.xhr[s].onreadystatechange=function(){if(4==n.xhr[s].readyState)if(n.buffer=n.xhr[s].responseText,console.log("api request",e),[0,200,417].indexOf(n.xhr[s].status)>-1){window._token_=n.xhr[s].getResponseHeader("X-Tree-Token");var t={ModuleError:-1,ErrorDescription:"Erreur au niveau de api.js"};try{t=JSON.parse(n.xhr[s].responseText)}catch(e){}console.log("api response",t),t.hasOwnProperty("ModuleError")&&0!=t.ModuleError&&console.error("ModuleError::"+t.ModuleError),r(t,n.optionalParams[s])}else r({ModuleError:-2,ModuleDescription:"Erreur au niveau d'AJAX."})};var a=new FormData;for(var i in e)"path"==i?a.append(i,e[i]):e[i]instanceof File?a.append(i,e[i]):a.append(i,JSON.stringify(e[i]));this.xhr[s].open("POST",this.target,!0),null!=t&&this.xhr[s].setRequestHeader("Authorization","Digest "+t),null==window._token_?this.xhr[s].setRequestHeader("X-Tree-Token",JSON.parse('{"'+document.cookie.replace(/=/g,'":"').replace(/; /g,'","')+'"}')._PUBLIC_):this.xhr[s].setRequestHeader("X-Tree-Token",window._token_),this.xhr[s].setRequestHeader("X-Requested-With","XMLHttpRequest"),this.xhr[s].send(a)}};
|
Loading…
Reference in New Issue