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
) {
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];
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=' + path
+ '/' + fileName
+ '&url=' + url
,
70 success: function(data
) {
77 error: function(error
) {
78 if (typeof error
== 'string') {
79 error
= JSON
.parse(error
);
83 }).fail(function(xhr
){
84 //Authentication and the handling of fail states should be wrapped up into a connection class.
85 Utils
.checkAuthentication(xhr
.status
);
89 success
: FileManagerActions
.addFileSuccess
,
90 error
: FileManagerActions
.addFileError
93 deleteFile: function() {
95 remote: function(state
, id
, type
, path
) {
96 return new Promise(function(resolve
, reject
) {
99 beforeSend
: Utils
.addAuthorizationStub
,
100 url
: 'api/file-manager?api_server=' + utils
.getSearchParams(window
.location
).api_server
+'&package_type=' + type
+ '&package_id=' + id
+ '&package_path=' + path
,
101 success: function(data
) {
107 error: function(error
) {
108 if (typeof error
== 'string') {
109 error
= JSON
.parse(error
);
113 }).fail(function(xhr
){
114 //Authentication and the handling of fail states should be wrapped up into a connection class.
115 Utils
.checkAuthentication(xhr
.status
);
119 success
: FileManagerActions
.deleteFileSuccess
,
120 error
: FileManagerActions
.deleteFileError
123 updateFile: function() {
125 remote: function(state
, file
) {
126 return new Promise(function(resolve
, reject
) {
127 console
.log('Getting File Manager');
129 console
.log('Updating single file');
132 console
.log('Update all files')
137 success
: FileManagerActions
.getFilelistSuccess
,
138 error
: FileManagerActions
.getFilelistError
141 openDownloadMonitoringSocket: function() {
143 remote: function(state
, packageID
) {
144 return new Promise(function(resolve
, reject
) {
145 //api/operational/download-jobs/job/
147 url
: '/socket-polling?api_server=' + API_SERVER
,
149 beforeSend
: Utils
.addAuthorizationStub
,
151 url
: 'http://localhost:8000/composer/api/file-manager/jobs/' + packageID
+ '?api_server=' + API_SERVER
,
153 success: function(data
, textStatus
, jqXHR
) {
154 Utils
.checkAndResolveSocketRequest(data
, resolve
, reject
);
156 }).fail(function(xhr
){
157 //Authentication and the handling of fail states should be wrapped up into a connection class.
158 Utils
.checkAuthentication(xhr
.status
);
162 success
: FileManagerActions
.openDownloadMonitoringSocketSuccess
,
163 error
: FileManagerActions
.openDownloadMonitoringSocketError
166 openFileMonitoringSocket: function() {
168 remote: function(state
, id
, type
) {
169 return new Promise(function(resolve
, reject
) {
170 //api/operational/download-jobs/job/
172 url
: '/socket-polling?api_server=' + API_SERVER
,
174 beforeSend
: Utils
.addAuthorizationStub
,
176 url
: 'http://localhost:8000/composer/api/file-manager?api_server=' + utils
.getSearchParams(window
.location
).api_server
+'&package_type=' + type
+ '&package_id=' + id
178 success: function(data
, textStatus
, jqXHR
) {
179 Utils
.checkAndResolveSocketRequest(data
, resolve
, reject
);
181 }).fail(function(xhr
){
182 //Authentication and the handling of fail states should be wrapped up into a connection class.
183 Utils
.checkAuthentication(xhr
.status
);
187 success
: FileManagerActions
.getFilelistSocketSuccess
,
188 error
: FileManagerActions
.getFilelistError
193 export default FileManagerSource
;