MCPcopy Create free account
hub / github.com/hydro-dev/Hydro / postUploadFile

Method postUploadFile

packages/hydrooj/src/handler/misc.ts:58–77  ·  view source on GitHub ↗
({ }, filename: string)

Source from the content-addressed store, hash-verified

56
57 @post('filename', Types.Filename)
58 async postUploadFile({ }, filename: string) {
59 this.checkPriv(PRIV.PRIV_CREATE_FILE);
60 if ((this.user._files?.length || 0) >= system.get('limit.user_files')) {
61 if (!this.user.hasPriv(PRIV.PRIV_UNLIMITED_QUOTA)) throw new FileLimitExceededError('count');
62 }
63 const file = this.request.files?.file;
64 if (!file) throw new ValidationError('file');
65 const size = Math.sum((this.user._files || []).map((i) => i.size)) + file.size;
66 if (size >= system.get('limit.user_files_size')) {
67 if (!this.user.hasPriv(PRIV.PRIV_UNLIMITED_QUOTA)) throw new FileLimitExceededError('size');
68 }
69 if (this.user._files.find((i) => i.name === filename)) throw new FileExistsError(filename);
70 await storage.put(`user/${this.user._id}/${filename}`, file.filepath, this.user._id);
71 const meta = await storage.getMeta(`user/${this.user._id}/${filename}`);
72 const payload = { name: filename, ...pick(meta, ['size', 'lastModified', 'etag']) };
73 if (!meta) throw new FileUploadError();
74 this.user._files.push({ _id: filename, ...payload });
75 await user.setById(this.user._id, { _files: this.user._files });
76 this.back();
77 }
78
79 @post('files', Types.ArrayOf(Types.Filename))
80 async postDeleteFiles({ }, files: string[]) {

Callers

nothing calls this directly

Calls 10

pickFunction · 0.85
checkPrivMethod · 0.80
hasPrivMethod · 0.80
findMethod · 0.80
setByIdMethod · 0.80
backMethod · 0.80
getMethod · 0.45
putMethod · 0.45
getMetaMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected