1
- import { FsEntity } from "./filesystemTypes" ;
2
- import { filesystemPath , hostname } from "./api" ;
3
- import Axios , { AxiosResponse } from "axios" ;
4
- import { constants } from "../constants" ;
1
+ import { FsEntity } from "./filesystemTypes" ;
2
+ import { filesystemPath , hostname } from "./api" ;
3
+ import Axios , { AxiosError , AxiosResponse } from "axios" ;
4
+ import { constants } from "../constants" ;
5
5
6
6
import store from "../redux/store" ;
7
- import { ApiAction , ApiActionStatus , ApiActionType } from "../redux/actions/apiActionsTypes" ;
8
- import { addApiAction , changeStatus , nextFsEntity } from "../redux/actions/apiActions" ;
9
- import { addToContents , removeFromContents } from "../redux/actions/filesystem" ;
10
- import { EditableFileWithPreflightInfo , PreflightEntity } from "../../components/pages/filesytem/upload/preflightTypes" ;
11
- import { isFsEntityInFolder } from "../methods/filesystem" ;
12
-
7
+ import {
8
+ ApiAction ,
9
+ ApiActionStatus ,
10
+ ApiActionType
11
+ } from "../redux/actions/apiActionsTypes" ;
12
+ import {
13
+ addApiAction ,
14
+ changeStatus ,
15
+ nextFsEntity
16
+ } from "../redux/actions/apiActions" ;
17
+ import { addToContents , removeFromContents } from "../redux/actions/filesystem" ;
18
+ import {
19
+ EditableFileWithPreflightInfo ,
20
+ PreflightEntity
21
+ } from "../../components/pages/filesytem/upload/preflightTypes" ;
22
+ import { isFsEntityInFolder } from "../methods/filesystem" ;
13
23
14
24
const fhHostname = constants . url . FH_URL ;
15
25
16
26
export const getFolderContents = ( path : string ) => {
17
- console . log ( "[Get folder content" , path )
27
+ console . log ( "[Get folder content" , path ) ;
18
28
return new Promise < AxiosResponse < FsEntity [ ] > > ( ( resolve , reject ) => {
19
29
let config = {
20
30
headers : {
@@ -24,9 +34,8 @@ export const getFolderContents = (path: string) => {
24
34
Axios . get < FsEntity [ ] > ( hostname + filesystemPath + "contents" , config )
25
35
. then ( ( response : AxiosResponse < FsEntity [ ] > ) => resolve ( response ) )
26
36
. catch ( ( error ) => reject ( error ) ) ;
27
- } )
28
- }
29
-
37
+ } ) ;
38
+ } ;
30
39
31
40
export const uploadPreflight = (
32
41
files : File [ ] | EditableFileWithPreflightInfo [ ] ,
@@ -43,7 +52,8 @@ export const uploadPreflight = (
43
52
} ) ) ;
44
53
return new Promise < PreflightEntity [ ] > ( ( resolve , reject ) => {
45
54
Axios . post < PreflightEntity [ ] > (
46
- hostname + filesystemPath + parentFolderID + "/upload/preflight" , postData
55
+ hostname + filesystemPath + parentFolderID + "/upload/preflight" ,
56
+ postData
47
57
)
48
58
. then ( ( response : AxiosResponse < PreflightEntity [ ] > ) => {
49
59
resolve ( response . data ) ;
@@ -52,8 +62,15 @@ export const uploadPreflight = (
52
62
} ) ;
53
63
} ;
54
64
55
- export const uploadFiles = ( files : File [ ] | EditableFileWithPreflightInfo [ ] , parentFolderID : string ) => {
56
- console . log ( "[API filesystem] uploading files to folderID" , parentFolderID , files ) ;
65
+ export const uploadFiles = (
66
+ files : File [ ] | EditableFileWithPreflightInfo [ ] ,
67
+ parentFolderID : string
68
+ ) => {
69
+ console . log (
70
+ "[API filesystem] uploading files to folderID" ,
71
+ parentFolderID ,
72
+ files
73
+ ) ;
57
74
const apiCall = ( file : File | EditableFileWithPreflightInfo ) => {
58
75
return new Promise ( ( resolve , reject ) => {
59
76
let formData = new FormData ( ) ;
@@ -78,9 +95,10 @@ export const uploadFiles = (files: File[] | EditableFileWithPreflightInfo[], par
78
95
. then ( ( response : AxiosResponse < [ FsEntity ] > ) => {
79
96
const currentPath = store . getState ( ) . filesystem . currentPath ;
80
97
81
- const fsEntityToShow = response . data . find ( ( fsEntity : FsEntity ) =>
82
- isFsEntityInFolder ( fsEntity , currentPath )
83
- )
98
+ const fsEntityToShow = response . data . find (
99
+ ( fsEntity : FsEntity ) =>
100
+ isFsEntityInFolder ( fsEntity , currentPath )
101
+ ) ;
84
102
85
103
if ( fsEntityToShow ) {
86
104
store . dispatch ( addToContents ( fsEntityToShow ) ) ;
@@ -93,15 +111,16 @@ export const uploadFiles = (files: File[] | EditableFileWithPreflightInfo[], par
93
111
handleMultipleApiActions ( files , apiCall , ApiActionType . UPLOAD ) ;
94
112
} ;
95
113
96
-
97
114
export const deleteFsEntities = ( files : FsEntity [ ] ) => {
98
115
const apiCall = ( fsEntity : FsEntity ) => {
99
116
return new Promise ( ( resolve , reject ) => {
100
117
Axios . delete < FsEntity [ ] > (
101
118
fhHostname + "/delete/" + fsEntity . fileSystemId
102
119
)
103
120
. then ( ( response : AxiosResponse < FsEntity [ ] > ) => {
104
- response . data . forEach ( ( e ) => store . dispatch ( removeFromContents ( e ) ) ) ;
121
+ response . data . forEach ( ( e ) =>
122
+ store . dispatch ( removeFromContents ( e ) )
123
+ ) ;
105
124
resolve ( response ) ;
106
125
} )
107
126
. catch ( ( error ) => reject ( error ) ) ;
@@ -110,6 +129,21 @@ export const deleteFsEntities = (files: FsEntity[]) => {
110
129
handleMultipleApiActions ( files , apiCall , ApiActionType . DELETE ) ;
111
130
} ;
112
131
132
+ export const createNewFolder = (
133
+ folderName : string ,
134
+ parentFolderID : string
135
+ ) : Promise < AxiosResponse < FsEntity > > => {
136
+ const body = { name : folderName } ;
137
+
138
+ return new Promise ( ( resolve , reject ) => {
139
+ Axios . post < FsEntity > (
140
+ hostname + filesystemPath + parentFolderID + "/folder/create" ,
141
+ body
142
+ )
143
+ . then ( ( response : AxiosResponse < FsEntity > ) => resolve ( response ) )
144
+ . catch ( ( error : AxiosError ) => reject ( error ) ) ;
145
+ } ) ;
146
+ } ;
113
147
114
148
function handleMultipleApiActions < Type extends File | FsEntity > (
115
149
items : Type [ ] ,
@@ -134,7 +168,9 @@ function handleMultipleApiActions<Type extends File | FsEntity>(
134
168
// get the info from the store
135
169
apiAction = store
136
170
. getState ( )
137
- . apiActions . actions . find ( ( a : ApiAction ) => a . key === apiAction ?. key ) ;
171
+ . apiActions . actions . find (
172
+ ( a : ApiAction ) => a . key === apiAction ?. key
173
+ ) ;
138
174
139
175
if (
140
176
! apiAction ||
@@ -150,7 +186,10 @@ function handleMultipleApiActions<Type extends File | FsEntity>(
150
186
151
187
if ( currentIndex === apiAction . totalAmount ) {
152
188
store . dispatch (
153
- changeStatus ( { key : apiAction . key , status : ApiActionStatus . FINISHED } )
189
+ changeStatus ( {
190
+ key : apiAction . key ,
191
+ status : ApiActionStatus . FINISHED
192
+ } )
154
193
) ;
155
194
return ;
156
195
} else {
@@ -166,7 +205,9 @@ function handleMultipleApiActions<Type extends File | FsEntity>(
166
205
167
206
action ( items [ currentIndex ] )
168
207
. then ( ( response ) => {
169
- console . log ( "[API filesystem] handleMultipleApiActions next iteration" ) ;
208
+ console . log (
209
+ "[API filesystem] handleMultipleApiActions next iteration"
210
+ ) ;
170
211
handleMultipleApiActions ( items , action , type , apiAction ) ;
171
212
} )
172
213
. catch ( ( error ) => {
0 commit comments