Skip to content

Commit 7c1e480

Browse files
committed
core: user_file allow uid arg for admin
1 parent 5d7f5fe commit 7c1e480

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

  • packages/hydrooj/src/handler

packages/hydrooj/src/handler/misc.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { PRIV } from '../model/builtin';
99
import * as oplog from '../model/oplog';
1010
import storage from '../model/storage';
1111
import * as system from '../model/system';
12-
import user from '../model/user';
12+
import user, { User } from '../model/user';
1313
import {
1414
Handler, param, post, requireSudo, Types,
1515
} from '../service/server';
@@ -31,19 +31,31 @@ class SwitchLanguageHandler extends Handler {
3131

3232
export class FilesHandler extends Handler {
3333
noCheckPermView = true;
34+
udoc: User;
3435

35-
async get() {
36-
if (!this.user._files?.length) this.checkPriv(PRIV.PRIV_CREATE_FILE);
36+
@param('uid', Types.Int, true)
37+
async prepare({ domainId }, uid: number) {
38+
if (uid) {
39+
this.checkPriv(PRIV.PRIV_EDIT_SYSTEM);
40+
this.udoc = await (await user.getById(domainId, uid)).private();
41+
} else {
42+
this.udoc = this.user;
43+
}
44+
}
45+
46+
@param('uid', Types.Int, true)
47+
async get({ }, uid: number) {
48+
if (!this.udoc._files?.length) this.checkPriv(PRIV.PRIV_CREATE_FILE);
3749
this.response.body = {
38-
files: sortFiles(this.user._files),
39-
urlForFile: (filename: string) => this.url('fs_download', { uid: this.user._id, filename }),
50+
files: sortFiles(this.udoc._files),
51+
urlForFile: (filename: string) => this.url('fs_download', { uid, filename }),
4052
};
4153
this.response.pjax = 'partials/files.html';
4254
this.response.template = 'home_files.html';
4355
}
4456

4557
@post('filename', Types.Filename)
46-
async postUploadFile(domainId: string, filename: string) {
58+
async postUploadFile({ }, filename: string) {
4759
this.checkPriv(PRIV.PRIV_CREATE_FILE);
4860
if ((this.user._files?.length || 0) >= system.get('limit.user_files')) {
4961
if (!this.user.hasPriv(PRIV.PRIV_UNLIMITED_QUOTA)) throw new FileLimitExceededError('count');
@@ -65,10 +77,10 @@ export class FilesHandler extends Handler {
6577
}
6678

6779
@post('files', Types.ArrayOf(Types.Filename))
68-
async postDeleteFiles(domainId: string, files: string[]) {
80+
async postDeleteFiles({ }, files: string[]) {
6981
await Promise.all([
70-
storage.del(files.map((t) => `user/${this.user._id}/${t}`), this.user._id),
71-
user.setById(this.user._id, { _files: this.user._files.filter((i) => !files.includes(i.name)) }),
82+
storage.del(files.map((t) => `user/${this.udoc._id}/${t}`), this.user._id),
83+
user.setById(this.udoc._id, { _files: this.udoc._files.filter((i) => !files.includes(i.name)) }),
7284
]);
7385
this.back();
7486
}

0 commit comments

Comments
 (0)