mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
core&ui: support file renaming (#688)
Co-authored-by: undefined <i@undefined.moe>
This commit is contained in:
1 parent
746efef9bf
commit
01cb6944b7
19 files changed
+496
-144
No files matched your search
@@ -695,7 +695,7 @@ export class ProblemFilesHandler extends ProblemDetailHandler {
|
||||
const { testdata, additional_file } = this.response.body;
|
||||
const owner = await user.getById(domainId, this.pdoc.owner);
|
||||
const args = {
|
||||
testdata, additional_file, pdoc: this.pdoc, owner_udoc: owner, sidebar,
|
||||
testdata, additional_file, pdoc: this.pdoc, owner_udoc: owner, sidebar, can_edit: true,
|
||||
};
|
||||
const tasks = [];
|
||||
if (d.includes('testdata')) tasks.push(this.renderHTML('partials/problem_files.html', { ...args, filetype: 'testdata' }));
|
||||
@@ -795,6 +795,21 @@ export class ProblemFilesHandler extends ProblemDetailHandler {
|
||||
this.back();
|
||||
}
|
||||
|
||||
@post('files', Types.ArrayOf(Types.Filename))
|
||||
@post('newNames', Types.ArrayOf(Types.Filename))
|
||||
@post('type', Types.Range(['testdata', 'additional_file']), true)
|
||||
async postRenameFiles(domainId: string, files: string[], newNames: string[], type = 'testdata') {
|
||||
if (this.pdoc.reference) throw new ProblemIsReferencedError('rename files');
|
||||
if (files.length !== newNames.length) throw new ValidationError('files', 'newNames');
|
||||
if (!this.user.own(this.pdoc, PERM.PERM_EDIT_PROBLEM_SELF)) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
|
||||
await Promise.all(files.map(async (file, index) => {
|
||||
const newName = newNames[index];
|
||||
if (type === 'testdata') await problem.renameTestdata(domainId, this.pdoc.docId, file, newName, this.user._id);
|
||||
else await problem.renameAdditionalFile(domainId, this.pdoc.docId, file, newName, this.user._id);
|
||||
}));
|
||||
this.back();
|
||||
}
|
||||
|
||||
@post('files', Types.ArrayOf(Types.Filename))
|
||||
@post('type', Types.Range(['testdata', 'additional_file']), true)
|
||||
async postDeleteFiles(domainId: string, files: string[], type = 'testdata') {
|
||||
|
||||
Reference in new issue
Block a user