File tree 3 files changed +32
-31
lines changed
3 files changed +32
-31
lines changed Original file line number Diff line number Diff line change @@ -85,7 +85,31 @@ module.exports = eggspress('/writeFile', {
85
85
if ( owner_user . suspended )
86
86
return res . status ( 401 ) . send ( { error : 'Account suspended' } ) ;
87
87
88
- const db = req . services . get ( 'database' ) . get ( DB_WRITE , 'filesystem' ) ;
88
+ const writeFile_handler_api = {
89
+ async get_dest_node ( ) {
90
+ if ( ! req . body . destination_write_url ) {
91
+ res . status ( 400 ) . send ( {
92
+ error :{
93
+ message : 'No destination specified.'
94
+ }
95
+ } ) ;
96
+ return ;
97
+ }
98
+ try {
99
+ validate_signature_auth ( req . body . destination_write_url , 'write' ) ;
100
+ } catch ( e ) {
101
+ res . status ( 403 ) . send ( e ) ;
102
+ return ;
103
+ }
104
+ try {
105
+ return await ( new FSNodeParam ( 'dest_path' ) ) . consolidate ( {
106
+ req, getParam : ( ) => req . body . dest_path ?? req . body . destination_uid
107
+ } ) ;
108
+ } catch ( e ) {
109
+ res . status ( 500 ) . send ( 'Internal Server Error' ) ;
110
+ }
111
+ }
112
+ } ;
89
113
90
114
const writeFile_handlers = require ( './writeFile/writeFile_handlers.js' ) ;
91
115
if ( writeFile_handlers . hasOwnProperty ( req . query . operation ) ) {
@@ -98,6 +122,7 @@ module.exports = eggspress('/writeFile', {
98
122
99
123
return await Context . get ( ) . sub ( { actor : Actor . adapt ( user ) } ) . arun ( async ( ) => {
100
124
return await writeFile_handlers [ req . query . operation ] ( {
125
+ api : writeFile_handler_api ,
101
126
req, res, actor,
102
127
node,
103
128
} ) ;
Original file line number Diff line number Diff line change @@ -3,35 +3,19 @@ const { HLCopy } = require('../../filesystem/hl_operations/hl_copy');
3
3
const { validate_signature_auth } = require ( '../../helpers' ) ;
4
4
5
5
module . exports = async function writeFile_handle_copy ( {
6
+ api,
6
7
req, res, actor, node,
7
8
} ) {
8
9
9
10
// check if destination_write_url provided
10
- if ( ! req . body . destination_write_url ) {
11
- return res . status ( 400 ) . send ( {
12
- error :{
13
- message : 'No destination specified.'
14
- }
15
- } )
16
- }
17
11
18
12
// check if destination_write_url is valid
19
- try {
20
- validate_signature_auth ( req . body . destination_write_url , 'write' ) ;
21
- } catch ( e ) {
22
- console . log ( 'REALLY THIS ONE' )
23
- return res . status ( 403 ) . send ( e ) ;
24
- }
13
+ const dest_node = await api . get_dest_node ( ) ;
14
+ if ( ! dest_node ) return ;
25
15
26
16
const overwrite = req . body . overwrite ?? false ;
27
17
const change_name = req . body . auto_rename ?? false ;
28
18
29
- // TODO: [fs:operation:param-coercion]
30
- const dest_node = await ( new FSNodeParam ( 'dest_path' ) ) . consolidate ( {
31
- req, getParam : ( ) => req . body . dest_path ?? req . body . destination_uid
32
- } ) ;
33
-
34
- // Get user
35
19
const opts = {
36
20
source : node ,
37
21
destination_or_parent : dest_node ,
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ const { HLMove } = require("../../filesystem/hl_operations/hl_move");
3
3
const { validate_signature_auth } = require ( "../../helpers" ) ;
4
4
5
5
module . exports = async function writeFile_handle_move ( {
6
+ api,
6
7
req, res, actor, node,
7
8
} ) {
8
9
// check if destination_write_url provided
@@ -14,20 +15,11 @@ module.exports = async function writeFile_handle_move ({
14
15
} )
15
16
}
16
17
17
- // check if destination_write_url is valid
18
- try {
19
- validate_signature_auth ( req . body . destination_write_url , 'write' ) ;
20
- } catch ( e ) {
21
- return res . status ( 403 ) . send ( e ) ;
22
- }
18
+ const dest_node = await api . get_dest_node ( ) ;
19
+ if ( ! dest_node ) return ;
23
20
24
21
const hl_move = new HLMove ( ) ;
25
22
26
- // TODO: [fs:operation:param-coercion]
27
- const dest_node = await ( new FSNodeParam ( 'dest_path' ) ) . consolidate ( {
28
- req, getParam : ( ) => req . body . dest_path ?? req . body . destination_uid
29
- } ) ;
30
-
31
23
const opts = {
32
24
user : actor . type . user ,
33
25
source : node ,
You can’t perform that action at this time.
0 commit comments