Skip to content

Commit 7fae627

Browse files
committed
add information about compute server id to project upload POST
1 parent 81efe69 commit 7fae627

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

src/packages/frontend/file-upload.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,14 @@ const Header = () => {
8585

8686
function postUrl(project_id: string, path: string): string {
8787
const dest_dir = encode_path(path);
88-
return join(appBasePath, project_id, `raw/.smc/upload?dest_dir=${dest_dir}`);
88+
const compute_server_id = redux
89+
.getProjectStore(project_id)
90+
.get("compute_server_id");
91+
return join(
92+
appBasePath,
93+
project_id,
94+
`raw/.smc/upload?dest_dir=${dest_dir}&compute_server_id=${compute_server_id}`,
95+
);
8996
}
9097

9198
interface FileUploadProps {
@@ -98,7 +105,7 @@ interface FileUploadProps {
98105

99106
export const FileUpload: React.FC<FileUploadProps> = (props) => {
100107
const student_project_functionality = useStudentProjectFunctionality(
101-
props.project_id
108+
props.project_id,
102109
);
103110

104111
if (student_project_functionality.disableUploads) {
@@ -137,7 +144,7 @@ export const FileUpload: React.FC<FileUploadProps> = (props) => {
137144
eventHandlers={props.dropzone_handler}
138145
djsConfig={{
139146
previewTemplate: ReactDOMServer.renderToStaticMarkup(
140-
dropzone_template()
147+
dropzone_template(),
141148
),
142149
...UPLOAD_OPTIONS,
143150
}}
@@ -174,7 +181,7 @@ interface FileUploadWrapperProps {
174181

175182
export const FileUploadWrapper: React.FC<FileUploadWrapperProps> = (props) => {
176183
const student_project_functionality = useStudentProjectFunctionality(
177-
props.project_id
184+
props.project_id,
178185
);
179186
const disabled =
180187
props.disabled || student_project_functionality.disableUploads;
@@ -196,12 +203,12 @@ export const FileUploadWrapper: React.FC<FileUploadWrapperProps> = (props) => {
196203
? ReactDOM.findDOMNode(preview_ref.current)
197204
: undefined,
198205
previewTemplate: ReactDOMServer.renderToStaticMarkup(
199-
preview_template()
206+
preview_template(),
200207
),
201208
addRemoveLinks: props.event_handlers.removedfile != null,
202209
...UPLOAD_OPTIONS,
203210
},
204-
true
211+
true,
205212
);
206213
return merge(with_defaults, props.config);
207214
}
@@ -252,7 +259,7 @@ export const FileUploadWrapper: React.FC<FileUploadWrapperProps> = (props) => {
252259
true,
253260
{},
254261
dropzone.current.options,
255-
get_djs_config()
262+
get_djs_config(),
256263
);
257264
}
258265
}
@@ -270,7 +277,7 @@ export const FileUploadWrapper: React.FC<FileUploadWrapperProps> = (props) => {
270277
// from the dropzone. This is true by default if there is
271278
// no "removedfile" handler, and false otherwise.
272279
function close_preview(
273-
remove_all: boolean = props.event_handlers.removedfile == null
280+
remove_all: boolean = props.event_handlers.removedfile == null,
274281
) {
275282
if (typeof props.on_close === "function") {
276283
props.on_close();

src/packages/project/upload.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,34 @@ const { F_OK, W_OK, R_OK } = fs_constants;
2929
import ensureContainingDirectoryExists from "@cocalc/backend/misc/ensure-containing-directory-exists";
3030
import { getLogger } from "./logger";
3131

32+
const logger = getLogger("project:upload");
33+
3234
export default function init(): Router {
33-
const winston = getLogger("upload");
34-
winston.info("configuring the upload endpoint");
35+
logger.info("configuring the upload endpoint");
3536

3637
const router = Router();
3738

3839
router.get("/.smc/upload", function (_, res) {
39-
winston.http("upload GET");
40+
logger.http("upload GET");
4041
return res.send("hello");
4142
});
4243

4344
router.post("/.smc/upload", async function (req, res): Promise<void> {
4445
function dbg(...m): void {
45-
winston.http("upload POST ", ...m);
46+
logger.http("upload POST ", ...m);
4647
}
4748
// See https://github.com/felixge/node-formidable; user uploaded a file
48-
dbg();
4949

5050
// See http://stackoverflow.com/questions/14022353/how-to-change-upload-path-when-use-formidable-with-express-in-node-js
5151
// Important to set maxFileSize, since the default is 200MB!
5252
// See https://stackoverflow.com/questions/13374238/how-to-limit-upload-file-size-in-express-js
5353
const { dest_dir } = req.query;
54+
const compute_server_id = getComputeServerId(req);
55+
56+
dbg({ dest_dir, compute_server_id });
57+
5458
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");
5660
return;
5761
}
5862
const { HOME } = process.env;
@@ -63,7 +67,7 @@ export default function init(): Router {
6367
try {
6468
const uploadDir = join(HOME, dest_dir);
6569

66-
// ensure target path existsJS
70+
// ensure target path exists
6771
dbg("ensure target path exists... ", uploadDir);
6872
await mkdir(uploadDir, { recursive: true });
6973

@@ -140,6 +144,14 @@ export default function init(): Router {
140144
return router;
141145
}
142146

147+
function getComputeServerId(req) {
148+
try {
149+
return parseInt(req.query.compute_server_id ?? "0");
150+
} catch (_) {
151+
return 0;
152+
}
153+
}
154+
143155
async function handle_chunk_data(
144156
index: number,
145157
total: number,

0 commit comments

Comments
 (0)