@@ -9,67 +9,65 @@ export function execute(ctx : HTTPRequestContext, methodName : string, privilege
9
9
ctx . noBodyExpected ( ( ) => {
10
10
ctx . getResource ( ( e , r ) => {
11
11
ctx . checkIfHeader ( r , ( ) => {
12
- //ctx.requirePrivilege([ privilegeName ], r, () => {
13
- const overwrite = ctx . headers . find ( 'overwrite' ) === 'T' ;
12
+ const overwrite = ctx . headers . find ( 'overwrite' ) === 'T' ;
14
13
15
- let destination : any = ctx . headers . find ( 'destination' ) ;
16
- if ( ! destination )
17
- {
18
- ctx . setCode ( HTTPCodes . BadRequest ) ;
19
- return callback ( ) ;
20
- }
21
-
22
- const startIndex = destination . indexOf ( '://' ) ;
23
- if ( startIndex !== - 1 )
24
- {
25
- destination = destination . substring ( startIndex + '://' . length )
26
- destination = destination . substring ( destination . indexOf ( '/' ) ) // Remove the hostname + port
27
- }
28
- destination = new Path ( destination ) ;
14
+ let destination : any = ctx . headers . find ( 'destination' ) ;
15
+ if ( ! destination )
16
+ {
17
+ ctx . setCode ( HTTPCodes . BadRequest ) ;
18
+ return callback ( ) ;
19
+ }
20
+
21
+ const startIndex = destination . indexOf ( '://' ) ;
22
+ if ( startIndex !== - 1 )
23
+ {
24
+ destination = destination . substring ( startIndex + '://' . length )
25
+ destination = destination . substring ( destination . indexOf ( '/' ) ) // Remove the hostname + port
26
+ }
27
+ destination = new Path ( destination ) ;
29
28
30
- const sDest = destination . toString ( true ) ;
31
- const sSource = ctx . requested . path . toString ( true ) ;
32
- if ( sDest === sSource )
33
- {
34
- ctx . setCode ( HTTPCodes . Forbidden ) ;
35
- return callback ( ) ;
36
- }
37
- if ( sDest . indexOf ( sSource ) === 0 )
38
- {
39
- ctx . setCode ( HTTPCodes . BadGateway ) ;
40
- return callback ( ) ;
41
- }
29
+ const sDest = destination . toString ( true ) ;
30
+ const sSource = ctx . requested . path . toString ( true ) ;
31
+ if ( sDest === sSource )
32
+ {
33
+ ctx . setCode ( HTTPCodes . Forbidden ) ;
34
+ return callback ( ) ;
35
+ }
36
+ if ( sDest . indexOf ( sSource ) === 0 )
37
+ {
38
+ ctx . setCode ( HTTPCodes . BadGateway ) ;
39
+ return callback ( ) ;
40
+ }
42
41
43
- const cb = ( e ?: Error , overwritten ?: boolean ) =>
42
+ const cb = ( e ?: Error , overwritten ?: boolean ) =>
43
+ {
44
+ if ( e )
44
45
{
45
- if ( e )
46
- {
47
- if ( e === Errors . ResourceAlreadyExists )
48
- ctx . setCode ( HTTPCodes . PreconditionFailed ) ;
49
- else if ( ! ctx . setCodeFromError ( e ) )
50
- ctx . setCode ( HTTPCodes . InternalServerError )
51
- }
52
- else if ( overwritten )
53
- ctx . setCode ( HTTPCodes . NoContent ) ;
54
- else
55
- ctx . setCode ( HTTPCodes . Created ) ;
56
- callback ( ) ;
57
- } ;
46
+ if ( e === Errors . ResourceAlreadyExists )
47
+ ctx . setCode ( HTTPCodes . PreconditionFailed ) ;
48
+ else if ( ! ctx . setCodeFromError ( e ) )
49
+ ctx . setCode ( HTTPCodes . InternalServerError )
50
+ }
51
+ else if ( overwritten )
52
+ ctx . setCode ( HTTPCodes . NoContent ) ;
53
+ else
54
+ ctx . setCode ( HTTPCodes . Created ) ;
55
+ callback ( ) ;
56
+ } ;
58
57
59
- ctx . server . getFileSystem ( destination , ( destFs , destRootPath , destSubPath ) => {
60
- if ( destFs !== r . fs )
61
- { // Standard method
62
- if ( methodName === 'move' )
63
- StandardMethods . standardMove ( ctx , r . path , r . fs , destSubPath , destFs , overwrite , cb ) ;
64
- else
65
- StandardMethods . standardCopy ( ctx , r . path , r . fs , destSubPath , destFs , overwrite , cb ) ;
66
- }
58
+ ctx . server . getFileSystem ( destination , ( destFs , destRootPath , destSubPath ) => {
59
+ if ( destFs !== r . fs )
60
+ { // Standard method
61
+ if ( methodName === 'move' )
62
+ StandardMethods . standardMove ( ctx , r . path , r . fs , destSubPath , destFs , overwrite , cb ) ;
67
63
else
68
- { // Delegate the operation to the file system
69
- r [ methodName ] ( destination , overwrite , cb ) ;
70
- }
71
- } )
72
- //})
64
+ StandardMethods . standardCopy ( ctx , r . path , r . fs , destSubPath , destFs , overwrite , cb ) ;
65
+ }
66
+ else
67
+ { // Delegate the operation to the file system
68
+ r [ methodName ] ( destSubPath , overwrite , cb ) ;
69
+ }
70
+ } )
73
71
} )
74
72
} )
75
73
} )
0 commit comments