Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit 591fa7c

Browse files
committed
Refactor minsite_session and download management.
1 parent c9902ef commit 591fa7c

File tree

3 files changed

+48
-22
lines changed

3 files changed

+48
-22
lines changed

core/src/plugins/gui.ajax/res/js/es6/http/PydioApi.es6

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
/*
2+
* Copyright 2007-2013 Charles du Jeu - Abstrium SAS <team (at) pyd.io>
3+
* This file is part of Pydio.
4+
*
5+
* Pydio is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* Pydio is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with Pydio. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
* The latest code can be found at <http://pyd.io/>.
19+
*/
20+
/**
21+
* API Client
22+
*/
123
class PydioApi{
224

325
constructor(){
@@ -103,20 +125,13 @@ class PydioApi{
103125
}
104126
document.location.href=downloadUrl;
105127
}else{
106-
var minisite_session = null;
107-
var parts = ajxpServerAccess.replace('?', '&').split('&');
108-
parts.map(function(p){
109-
var sub = p.split('=');
110-
if(sub.length == 2 && sub[0] == 'minisite_session'){
111-
minisite_session = sub[1];
112-
}
113-
});
114128
prototypeHiddenForm.action = window.ajxpServerAccessPath;
115129
prototypeHiddenForm.secure_token.value = this._secureToken;
116130
prototypeHiddenForm.get_action.value = dlActionName;
117131
prototypeHiddenForm.select("input").each(function(input){
118132
if(input.name!='get_action' && input.name!='secure_token') input.remove();
119133
});
134+
var minisite_session = PydioApi.detectMinisiteSession(ajxpServerAccess);
120135
if(minisite_session){
121136
prototypeHiddenForm.insert(new Element('input', {type:'hidden', name:'minisite_session', value:minisite_session}));
122137
}
@@ -139,6 +154,21 @@ class PydioApi{
139154

140155
}
141156

157+
/**
158+
* Detect a minisite_session parameter in the URL
159+
* @param serverAccess
160+
* @returns string|bool
161+
*/
162+
static detectMinisiteSession(serverAccess){
163+
var regex = new RegExp('.*?[&\\?]' + 'minisite_session' + '=(.*?)&.*');
164+
var val = serverAccess.replace(regex, "$1");
165+
return ( val == serverAccess ? false : val );
166+
}
167+
168+
/**
169+
* Detects if current browser supports HTML5 Upload.
170+
* @returns boolean
171+
*/
142172
static supportsUpload(){
143173
if(window.Connexion){
144174
return (window.FormData || window.FileReader);
@@ -148,6 +178,10 @@ class PydioApi{
148178
return false;
149179
}
150180

181+
/**
182+
* Instanciate a PydioApi client if it's not already instanciated and return it.
183+
* @returns PydioApi
184+
*/
151185
static getClient(){
152186
if(PydioApi._PydioClient) return PydioApi._PydioClient;
153187
var client = new PydioApi();
@@ -160,7 +194,6 @@ class PydioApi{
160194
* @param fileName String
161195
* @param onLoadedCode Function Callback
162196
* @param aSync Boolean load library asynchroneously
163-
* @todo : We should use Require or equivalent instead.
164197
*/
165198
static loadLibrary(fileName, onLoadedCode, aSync){
166199
if(window.pydio && pydio.Parameters.get("ajxpVersion") && fileName.indexOf("?")==-1){
@@ -395,11 +428,9 @@ class PydioApi{
395428
else if(childs[i].tagName == "logging_result")
396429
{
397430
if(childs[i].getAttribute("secure_token")){
398-
var serverAccessPath = this._pydioObject.Parameters.get("ajxpServerAccess");
399-
var regex = new RegExp('.*?[&\\?]' + 'minisite_session' + '=(.*?)&.*');
400431

401-
var val = serverAccessPath.replace(regex, "$1");
402-
var minisite_session = ( val == serverAccessPath ? false : val );
432+
var serverAccessPath = this._pydioObject.Parameters.get("ajxpServerAccess");
433+
var minisite_session = PydioApi.detectMinisiteSession(serverAccessPath);
403434

404435
var secure_token = childs[i].getAttribute("secure_token");
405436

core/src/plugins/gui.ajax/res/js/es6/model/Controller.es6

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,7 @@ class Controller extends Observable{
173173
* @returns {*}
174174
*/
175175
parseXmlMessage(xmlDoc){
176-
Logger.log("Controller.parseXmlMessage() is deprecated, use PydioApi instead");
177-
if(window.console && window.console.trace){
178-
Logger.log(console.trace());
179-
}
176+
Logger.debug("Controller.parseXmlMessage() is deprecated, use PydioApi instead");
180177
return PydioApi.getClient().parseXmlMessage(xmlDoc);
181178
}
182179

@@ -187,7 +184,7 @@ class Controller extends Observable{
187184
* @param completeCallback Function Callback to be called on complete
188185
*/
189186
submitForm(formName, post, completeCallback){
190-
Logger.log("Controller.submitForm() is deprecated, use PydioApi instead");
187+
Logger.debug("Controller.submitForm() is deprecated, use PydioApi instead");
191188
return PydioApi.getClient().submitForm(formName, post, completeCallback);
192189
}
193190

core/src/plugins/gui.ajax/res/js/ui/prototype/http/class.Connexion.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -468,14 +468,12 @@ Connexion.parseXmlMessage = function(xmlResponse){
468468
else if(childs[i].tagName == "logging_result")
469469
{
470470
if(childs[i].getAttribute("secure_token")){
471-
var regex = new RegExp('.*?[&\\?]' + 'minisite_session' + '=(.*?)&.*');
472-
var val = window.ajxpServerAccessPath.replace(regex, "$1");
473-
var minisite_session = ( val == window.ajxpServerAccessPath ? false : val );
474-
475471
Connexion.SECURE_TOKEN = childs[i].getAttribute("secure_token");
472+
var minisite_session = PydioApi.detectMinisiteSession(window.ajxpServerAccessPath);
476473
var parts = window.ajxpServerAccessPath.split("?secure_token");
477474
window.ajxpServerAccessPath = parts[0] + "?secure_token=" + Connexion.SECURE_TOKEN;
478475
if(minisite_session) window.ajxpServerAccessPath += "&minisite_session=" + minisite_session;
476+
479477
ajxpBootstrap.parameters.set('ajxpServerAccess', window.ajxpServerAccessPath);
480478
}
481479
if($("generic_dialog_box") && $("generic_dialog_box").down(".ajxp_login_error")){

0 commit comments

Comments
 (0)