Skip to content

Commit d6d657c

Browse files
committed
core&ui: fix homework_files
1 parent 9226b26 commit d6d657c

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

packages/hydrooj/src/handler/homework.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ class HomeworkEditHandler extends Handler {
247247
await Promise.all([
248248
record.updateMulti(domainId, { domainId, contest: tid }, undefined, undefined, { contest: '' }),
249249
contest.del(domainId, tid),
250-
storage.del(tdoc.files?.map((i) => `contest/${domainId}/${tid}/private/${i.name}`) || [], this.user._id),
250+
storage.del(tdoc.files?.map((i) => `contest/${domainId}/${tid}/public/${i.name}`) || [], this.user._id),
251251
]);
252252
this.response.redirect = this.url('homework_main');
253253
}
@@ -271,7 +271,7 @@ export class HomeworkFilesHandler extends Handler {
271271
tsdoc: await contest.getStatus(domainId, this.tdoc.docId, this.user._id),
272272
udoc: await user.getById(domainId, this.tdoc.owner),
273273
files: sortFiles(this.tdoc.files || []),
274-
urlForFile: (filename: string) => this.url('homework_file_download', { tid, filename }),
274+
urlForFile: (filename: string) => this.url('homework_file_download', { tid, filename, type: 'public' }),
275275
};
276276
this.response.pjax = 'partials/files.html';
277277
this.response.template = 'homework_files.html';
@@ -289,8 +289,8 @@ export class HomeworkFilesHandler extends Handler {
289289
if (size >= system.get('limit.contest_files_size')) {
290290
throw new FileLimitExceededError('size');
291291
}
292-
await storage.put(`contest/${domainId}/${tid}/private/${filename}`, file.filepath, this.user._id);
293-
const meta = await storage.getMeta(`contest/${domainId}/${tid}/private/${filename}`);
292+
await storage.put(`contest/${domainId}/${tid}/public/${filename}`, file.filepath, this.user._id);
293+
const meta = await storage.getMeta(`contest/${domainId}/${tid}/public/${filename}`);
294294
const payload = { _id: filename, name: filename, ...pick(meta, ['size', 'lastModified', 'etag']) };
295295
if (!meta) throw new FileUploadError();
296296
await contest.edit(domainId, tid, { files: [...(this.tdoc.files || []), payload] });
@@ -301,7 +301,7 @@ export class HomeworkFilesHandler extends Handler {
301301
@post('files', Types.ArrayOf(Types.Filename))
302302
async postDeleteFiles(domainId: string, tid: ObjectId, files: string[]) {
303303
await Promise.all([
304-
storage.del(files.map((t) => `contest/${domainId}/${tid}/private/${t}`), this.user._id),
304+
storage.del(files.map((t) => `contest/${domainId}/${tid}/public/${t}`), this.user._id),
305305
contest.edit(domainId, tid, { files: this.tdoc.files.filter((i) => !files.includes(i.name)) }),
306306
]);
307307
this.back();
@@ -315,7 +315,7 @@ export async function apply(ctx) {
315315
ctx.Route('homework_code', '/homework/:tid/code', ContestCodeHandler, PERM.PERM_VIEW_HOMEWORK);
316316
ctx.Route('homework_edit', '/homework/:tid/edit', HomeworkEditHandler);
317317
ctx.Route('homework_files', '/homework/:tid/file', HomeworkFilesHandler, PERM.PERM_VIEW_HOMEWORK);
318-
ctx.Route('homework_file_download', '/homework/:tid/file/:filename', ContestFileDownloadHandler, PERM.PERM_VIEW_HOMEWORK);
318+
ctx.Route('homework_file_download', '/homework/:tid/file/:type/:filename', ContestFileDownloadHandler, PERM.PERM_VIEW_HOMEWORK);
319319
await ctx.inject(['scoreboard'], ({ Route }) => {
320320
Route('homework_scoreboard', '/homework/:tid/scoreboard', ContestScoreboardHandler, PERM.PERM_VIEW_HOMEWORK_SCOREBOARD);
321321
Route('homework_scoreboard_view', '/homework/:tid/scoreboard/:view', ContestScoreboardHandler, PERM.PERM_VIEW_HOMEWORK_SCOREBOARD);

packages/hydrooj/src/upgrade.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,12 +617,21 @@ export const coreScripts: MigrationScript[] = [
617617
await discussion.coll.deleteMany({ content: { $not: { $type: 'string' } } });
618618
return true;
619619
},
620-
async function _95_96() {
620+
null,
621+
async function _96_97() {
621622
const files = await StorageModel.list('contest/', true);
623+
const rename = async (path: string, newPath: string) => {
624+
if (path === newPath) return;
625+
console.log('Rename', path, '->', newPath);
626+
await StorageModel.rename(path, newPath);
627+
};
622628
for (const file of files) {
623629
const [, domainId, tid, type, name] = file.path.split('/');
624-
if (!name) await StorageModel.rename(file.path, `contest/${domainId}/${tid}/public/${type}`);
630+
const tdoc = await contest.get(domainId, new ObjectId(tid));
631+
if (!tdoc) console.error('Contest not found', file.path);
632+
if (tdoc.rule === 'homework' || !name) {
633+
await rename(file.path, `contest/${domainId}/${tid}/public/${name || type}`);
634+
}
625635
}
626-
return true;
627636
},
628637
];

packages/ui-default/build/main.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import fs from 'fs-extra';
66
import { globbySync } from 'globby';
77
import webpack, { Stats } from 'webpack';
88
import WebpackDevServer from 'webpack-dev-server';
9-
import pkg from '../package.json';
109
import webpackConfig from './config/webpack';
1110
import root from './utils/root';
1211

packages/ui-default/templates/contest_manage.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ <h1 class="section__title">{{ _('Materials') }}({{ _('Only Partic.') }})</h1>
6363
<button class="primary rounded button" name="upload_file">{{ _('Upload File') }}</button>
6464
</div>
6565
</div>
66-
{% set files = tdoc.privateFiles %}
66+
{% set files = privateFiles %}
6767
{% set filetype = "private" %}
6868
{% include "partials/files.html" %}
6969
<div class="section__body">

0 commit comments

Comments
 (0)