4 * Copyright 2016 RIFT.IO Inc
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 import $ from 'jquery'
22 import alt
from '../../alt'
23 import utils
from '../../libraries/utils'
24 import FileManagerActions
from './FileManagerActions'
25 let Utils
= require('utils/utils.js');
26 let API_SERVER
= require('utils/rw.js').getSearchParams(window
.location
).api_server
;
27 let HOST
= API_SERVER
;
28 let NODE_PORT
= require('utils/rw.js').getSearchParams(window
.location
).api_port
|| ((window
.location
.protocol
== 'https:') ? 8443 : 8000);
29 const FileManagerSource
= {
31 getFilelist: function() {
33 remote: function(state
, id
, type
) {
34 return new Promise(function(resolve
, reject
) {
35 console
.log('Getting File Manager');
37 beforeSend
: Utils
.addAuthorizationStub
,
38 url
: 'api/file-manager?api_server=' + utils
.getSearchParams(window
.location
).api_server
+'&package_type=' + type
+ '&package_id=' + id
,
39 success: function(data
) {
40 resolve(JSON
.parse(data
));
42 error: function(error
) {
43 if (typeof error
== 'string') {
44 error
= JSON
.parse(error
);
48 }).fail(function(xhr
){
49 //Authentication and the handling of fail states should be wrapped up into a connection class.
50 Utils
.checkAuthentication(xhr
.status
);
54 success
: FileManagerActions
.getFilelistSuccess
,
55 error
: FileManagerActions
.getFilelistError
60 remote: function(state
, id
, type
, path
, url
, refresh
) {
61 return new Promise(function(resolve
, reject
) {
62 console
.log('Adding file');
63 console
.log(id
, type
, path
, url
);
64 let splitUrl
= url
.split('/');
65 let fileName
= splitUrl
[splitUrl
.length
-1];
66 let packagePath
= refresh
? path
+ ((path
[path
.length
- 1] == '/') ? '' : '/') : path
+ '/' + fileName
;
68 beforeSend
: Utils
.addAuthorizationStub
,
69 url
: 'api/file-manager?api_server=' + utils
.getSearchParams(window
.location
).api_server
+'&package_type=' + type
+ '&package_id=' + id
+ '&package_path=' + packagePath
+ '&url=' + url
,
70 success: function(data
) {
78 error: function(error
) {
79 if (typeof error
== 'string') {
80 error
= JSON
.parse(error
);
84 }).fail(function(xhr
){
85 //Authentication and the handling of fail states should be wrapped up into a connection class.
86 Utils
.checkAuthentication(xhr
.status
);
90 success
: FileManagerActions
.addFileSuccess
,
91 error
: FileManagerActions
.addFileError
94 deleteFile: function() {
96 remote: function(state
, id
, type
, path
) {
97 return new Promise(function(resolve
, reject
) {
100 beforeSend
: Utils
.addAuthorizationStub
,
101 url
: 'api/file-manager?api_server=' + utils
.getSearchParams(window
.location
).api_server
+'&package_type=' + type
+ '&package_id=' + id
+ '&package_path=' + path
,
102 success: function(data
) {
108 error: function(error
) {
109 if (typeof error
== 'string') {
110 error
= JSON
.parse(error
);
114 }).fail(function(xhr
){
115 //Authentication and the handling of fail states should be wrapped up into a connection class.
116 Utils
.checkAuthentication(xhr
.status
);
120 success
: FileManagerActions
.deleteFileSuccess
,
121 error
: FileManagerActions
.deleteFileError
124 updateFile: function() {
126 remote: function(state
, file
) {
127 return new Promise(function(resolve
, reject
) {
128 console
.log('Getting File Manager');
130 console
.log('Updating single file');
133 console
.log('Update all files')
138 success
: FileManagerActions
.getFilelistSuccess
,
139 error
: FileManagerActions
.getFilelistError
142 openDownloadMonitoringSocket: function() {
144 remote: function(state
, packageID
) {
145 return new Promise(function(resolve
, reject
) {
146 //api/operational/download-jobs/job/
148 url
: '/socket-polling',
150 beforeSend
: Utils
.addAuthorizationStub
,
152 url
: 'composer/api/file-manager/jobs/' + packageID
+ '?api_server=' + API_SERVER
,
154 success: function(data
, textStatus
, jqXHR
) {
155 Utils
.checkAndResolveSocketRequest(data
, resolve
, reject
);
157 }).fail(function(xhr
){
158 //Authentication and the handling of fail states should be wrapped up into a connection class.
159 Utils
.checkAuthentication(xhr
.status
);
163 success
: FileManagerActions
.openDownloadMonitoringSocketSuccess
,
164 error
: FileManagerActions
.openDownloadMonitoringSocketError
167 openFileMonitoringSocket: function() {
169 remote: function(state
, id
, type
) {
170 return new Promise(function(resolve
, reject
) {
171 //api/operational/download-jobs/job/
173 url
: '/socket-polling',
175 beforeSend
: Utils
.addAuthorizationStub
,
177 url
: 'composer/api/file-manager?api_server=' + utils
.getSearchParams(window
.location
).api_server
+'&package_type=' + type
+ '&package_id=' + id
179 success: function(data
, textStatus
, jqXHR
) {
180 Utils
.checkAndResolveSocketRequest(data
, resolve
, reject
);
182 }).fail(function(xhr
){
183 //Authentication and the handling of fail states should be wrapped up into a connection class.
184 Utils
.checkAuthentication(xhr
.status
);
188 success
: FileManagerActions
.getFilelistSocketSuccess
,
189 error
: FileManagerActions
.getFilelistError
194 export default FileManagerSource
;