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 'lodash'
22 import $ from 'jquery'
23 import alt
from '../../alt'
24 import utils
from '../../libraries/utils'
25 import FileManagerActions
from './FileManagerActions'
26 let Utils
= require('utils/utils.js');
27 let API_SERVER
= require('utils/rw.js').getSearchParams(window
.location
).api_server
;
28 let HOST
= API_SERVER
;
29 let NODE_PORT
= require('utils/rw.js').getSearchParams(window
.location
).api_port
|| ((window
.location
.protocol
== 'https:') ? 8443 : 8000);
30 const FileManagerSource
= {
32 getFilelist: function() {
34 remote: function(state
, id
, type
) {
35 return new Promise(function(resolve
, reject
) {
36 console
.log('Getting File Manager');
38 beforeSend
: Utils
.addAuthorizationStub
,
39 url
: 'api/file-manager?api_server=' + utils
.getSearchParams(window
.location
).api_server
+'&package_type=' + type
+ '&package_id=' + id
,
40 success: function(data
) {
41 resolve(JSON
.parse(data
));
43 error: function(error
) {
44 if (typeof error
== 'string') {
45 error
= JSON
.parse(error
);
49 }).fail(function(xhr
){
50 //Authentication and the handling of fail states should be wrapped up into a connection class.
51 Utils
.checkAuthentication(xhr
.status
);
55 success
: FileManagerActions
.getFilelistSuccess
,
56 error
: FileManagerActions
.getFilelistError
61 remote: function(state
, id
, type
, path
, url
, refresh
) {
62 return new Promise(function(resolve
, reject
) {
63 console
.log('Adding file');
64 console
.log(id
, type
, path
, url
);
65 let splitUrl
= url
.split('/');
66 let fileName
= splitUrl
[splitUrl
.length
-1];
67 let packagePath
= refresh
? path
+ ((path
[path
.length
- 1] == '/') ? '' : '/') : path
+ '/' + fileName
;
69 beforeSend
: Utils
.addAuthorizationStub
,
70 url
: 'api/file-manager?api_server=' + utils
.getSearchParams(window
.location
).api_server
+'&package_type=' + type
+ '&package_id=' + id
+ '&package_path=' + packagePath
+ '&url=' + url
,
71 success: function(data
) {
79 error: function(error
) {
80 if (typeof error
== 'string') {
81 error
= JSON
.parse(error
);
85 }).fail(function(xhr
){
86 //Authentication and the handling of fail states should be wrapped up into a connection class.
87 Utils
.checkAuthentication(xhr
.status
);
91 success
: FileManagerActions
.addFileSuccess
,
92 error
: FileManagerActions
.addFileError
95 deleteFile: function() {
97 remote: function(state
, id
, type
, path
) {
98 return new Promise(function(resolve
, reject
) {
101 beforeSend
: Utils
.addAuthorizationStub
,
102 url
: 'api/file-manager?api_server=' + utils
.getSearchParams(window
.location
).api_server
+'&package_type=' + type
+ '&package_id=' + id
+ '&package_path=' + path
,
103 success: function(data
) {
109 error: function(error
) {
110 if (typeof error
== 'string') {
111 error
= JSON
.parse(error
);
115 }).fail(function(xhr
){
116 //Authentication and the handling of fail states should be wrapped up into a connection class.
117 Utils
.checkAuthentication(xhr
.status
);
121 success
: FileManagerActions
.deleteFileSuccess
,
122 error
: FileManagerActions
.deleteFileError
125 updateFile: function() {
127 remote: function(state
, file
) {
128 return new Promise(function(resolve
, reject
) {
129 console
.log('Getting File Manager');
131 console
.log('Updating single file');
134 console
.log('Update all files')
139 success
: FileManagerActions
.getFilelistSuccess
,
140 error
: FileManagerActions
.getFilelistError
143 openDownloadMonitoringSocket: function() {
145 remote: function(state
, packageID
) {
146 return new Promise(function(resolve
, reject
) {
147 //api/operational/download-jobs/job/
149 url
: '/socket-polling',
151 beforeSend
: Utils
.addAuthorizationStub
,
153 url
: 'http://localhost:8000/composer/api/file-manager/jobs/' + packageID
+ '?api_server=' + API_SERVER
,
155 success: function(data
, textStatus
, jqXHR
) {
156 Utils
.checkAndResolveSocketRequest(data
, resolve
, reject
);
158 }).fail(function(xhr
){
159 //Authentication and the handling of fail states should be wrapped up into a connection class.
160 Utils
.checkAuthentication(xhr
.status
);
164 success
: FileManagerActions
.openDownloadMonitoringSocketSuccess
,
165 error
: FileManagerActions
.openDownloadMonitoringSocketError
168 openFileMonitoringSocket: function() {
170 remote: function(state
, id
, type
) {
171 return new Promise(function(resolve
, reject
) {
172 //api/operational/download-jobs/job/
174 url
: '/socket-polling',
176 beforeSend
: Utils
.addAuthorizationStub
,
178 url
: 'http://localhost:8000/composer/api/file-manager?api_server=' + utils
.getSearchParams(window
.location
).api_server
+'&package_type=' + type
+ '&package_id=' + id
180 success: function(data
, textStatus
, jqXHR
) {
181 Utils
.checkAndResolveSocketRequest(data
, resolve
, reject
);
183 }).fail(function(xhr
){
184 //Authentication and the handling of fail states should be wrapped up into a connection class.
185 Utils
.checkAuthentication(xhr
.status
);
189 success
: FileManagerActions
.getFilelistSocketSuccess
,
190 error
: FileManagerActions
.getFilelistError
195 export default FileManagerSource
;