@@ -29,30 +29,34 @@ const { F_OK, W_OK, R_OK } = fs_constants;
29
29
import ensureContainingDirectoryExists from "@cocalc/backend/misc/ensure-containing-directory-exists" ;
30
30
import { getLogger } from "./logger" ;
31
31
32
+ const logger = getLogger ( "project:upload" ) ;
33
+
32
34
export default function init ( ) : Router {
33
- const winston = getLogger ( "upload" ) ;
34
- winston . info ( "configuring the upload endpoint" ) ;
35
+ logger . info ( "configuring the upload endpoint" ) ;
35
36
36
37
const router = Router ( ) ;
37
38
38
39
router . get ( "/.smc/upload" , function ( _ , res ) {
39
- winston . http ( "upload GET" ) ;
40
+ logger . http ( "upload GET" ) ;
40
41
return res . send ( "hello" ) ;
41
42
} ) ;
42
43
43
44
router . post ( "/.smc/upload" , async function ( req , res ) : Promise < void > {
44
45
function dbg ( ...m ) : void {
45
- winston . http ( "upload POST " , ...m ) ;
46
+ logger . http ( "upload POST " , ...m ) ;
46
47
}
47
48
// See https://github.com/felixge/node-formidable; user uploaded a file
48
- dbg ( ) ;
49
49
50
50
// See http://stackoverflow.com/questions/14022353/how-to-change-upload-path-when-use-formidable-with-express-in-node-js
51
51
// Important to set maxFileSize, since the default is 200MB!
52
52
// See https://stackoverflow.com/questions/13374238/how-to-limit-upload-file-size-in-express-js
53
53
const { dest_dir } = req . query ;
54
+ const compute_server_id = getComputeServerId ( req ) ;
55
+
56
+ dbg ( { dest_dir, compute_server_id } ) ;
57
+
54
58
if ( typeof dest_dir != "string" ) {
55
- res . status ( 500 ) . send ( "query parm dest_dir must be a string" ) ;
59
+ res . status ( 500 ) . send ( "query param dest_dir must be a string" ) ;
56
60
return ;
57
61
}
58
62
const { HOME } = process . env ;
@@ -63,7 +67,7 @@ export default function init(): Router {
63
67
try {
64
68
const uploadDir = join ( HOME , dest_dir ) ;
65
69
66
- // ensure target path existsJS
70
+ // ensure target path exists
67
71
dbg ( "ensure target path exists... " , uploadDir ) ;
68
72
await mkdir ( uploadDir , { recursive : true } ) ;
69
73
@@ -140,6 +144,14 @@ export default function init(): Router {
140
144
return router ;
141
145
}
142
146
147
+ function getComputeServerId ( req ) {
148
+ try {
149
+ return parseInt ( req . query . compute_server_id ?? "0" ) ;
150
+ } catch ( _ ) {
151
+ return 0 ;
152
+ }
153
+ }
154
+
143
155
async function handle_chunk_data (
144
156
index : number ,
145
157
total : number ,
0 commit comments