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
+ */
1
23
class PydioApi {
2
24
3
25
constructor ( ) {
@@ -103,20 +125,13 @@ class PydioApi{
103
125
}
104
126
document . location . href = downloadUrl ;
105
127
} 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
- } ) ;
114
128
prototypeHiddenForm . action = window . ajxpServerAccessPath ;
115
129
prototypeHiddenForm . secure_token . value = this . _secureToken ;
116
130
prototypeHiddenForm . get_action . value = dlActionName ;
117
131
prototypeHiddenForm . select ( "input" ) . each ( function ( input ) {
118
132
if ( input . name != 'get_action' && input . name != 'secure_token' ) input . remove ( ) ;
119
133
} ) ;
134
+ var minisite_session = PydioApi . detectMinisiteSession ( ajxpServerAccess ) ;
120
135
if ( minisite_session ) {
121
136
prototypeHiddenForm . insert ( new Element ( 'input' , { type :'hidden' , name :'minisite_session' , value :minisite_session } ) ) ;
122
137
}
@@ -139,6 +154,21 @@ class PydioApi{
139
154
140
155
}
141
156
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
+ */
142
172
static supportsUpload ( ) {
143
173
if ( window . Connexion ) {
144
174
return ( window . FormData || window . FileReader ) ;
@@ -148,6 +178,10 @@ class PydioApi{
148
178
return false ;
149
179
}
150
180
181
+ /**
182
+ * Instanciate a PydioApi client if it's not already instanciated and return it.
183
+ * @returns PydioApi
184
+ */
151
185
static getClient ( ) {
152
186
if ( PydioApi . _PydioClient ) return PydioApi . _PydioClient ;
153
187
var client = new PydioApi ( ) ;
@@ -160,7 +194,6 @@ class PydioApi{
160
194
* @param fileName String
161
195
* @param onLoadedCode Function Callback
162
196
* @param aSync Boolean load library asynchroneously
163
- * @todo : We should use Require or equivalent instead.
164
197
*/
165
198
static loadLibrary ( fileName , onLoadedCode , aSync ) {
166
199
if ( window . pydio && pydio . Parameters . get ( "ajxpVersion" ) && fileName . indexOf ( "?" ) == - 1 ) {
@@ -395,11 +428,9 @@ class PydioApi{
395
428
else if ( childs [ i ] . tagName == "logging_result" )
396
429
{
397
430
if ( childs [ i ] . getAttribute ( "secure_token" ) ) {
398
- var serverAccessPath = this . _pydioObject . Parameters . get ( "ajxpServerAccess" ) ;
399
- var regex = new RegExp ( '.*?[&\\?]' + 'minisite_session' + '=(.*?)&.*' ) ;
400
431
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 ) ;
403
434
404
435
var secure_token = childs [ i ] . getAttribute ( "secure_token" ) ;
405
436
0 commit comments