mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
core&ui: fix homework_files
This commit is contained in:
4 files changed
+21
-13
No files matched your search
@@ -109,8 +109,8 @@ class HomeworkDetailHandler extends Handler {
|
|||||||
tdoc: this.tdoc, tsdoc, udict, ddocs, page, dpcount, dcount,
|
tdoc: this.tdoc, tsdoc, udict, ddocs, page, dpcount, dcount,
|
||||||
};
|
};
|
||||||
this.response.body.tdoc.content = this.response.body.tdoc.content
|
this.response.body.tdoc.content = this.response.body.tdoc.content
|
||||||
.replace(/\(file:\/\//g, `(./${this.tdoc.docId}/file/`)
|
.replace(/\(file:\/\//g, `(./${this.tdoc.docId}/file/public/`)
|
||||||
.replace(/="file:\/\//g, `="./${this.tdoc.docId}/file/`);
|
.replace(/="file:\/\//g, `="./${this.tdoc.docId}/file/public/`);
|
||||||
if (
|
if (
|
||||||
(contest.isNotStarted(this.tdoc) || (!tsdoc?.attend && !contest.isDone(this.tdoc)))
|
(contest.isNotStarted(this.tdoc) || (!tsdoc?.attend && !contest.isDone(this.tdoc)))
|
||||||
&& !this.user.own(this.tdoc)
|
&& !this.user.own(this.tdoc)
|
||||||
@@ -247,7 +247,7 @@ class HomeworkEditHandler extends Handler {
|
|||||||
await Promise.all([
|
await Promise.all([
|
||||||
record.updateMulti(domainId, { domainId, contest: tid }, undefined, undefined, { contest: '' }),
|
record.updateMulti(domainId, { domainId, contest: tid }, undefined, undefined, { contest: '' }),
|
||||||
contest.del(domainId, tid),
|
contest.del(domainId, tid),
|
||||||
storage.del(tdoc.files?.map((i) => `contest/${domainId}/${tid}/private/${i.name}`) || [], this.user._id),
|
storage.del(tdoc.files?.map((i) => `contest/${domainId}/${tid}/public/${i.name}`) || [], this.user._id),
|
||||||
]);
|
]);
|
||||||
this.response.redirect = this.url('homework_main');
|
this.response.redirect = this.url('homework_main');
|
||||||
}
|
}
|
||||||
@@ -271,7 +271,7 @@ export class HomeworkFilesHandler extends Handler {
|
|||||||
tsdoc: await contest.getStatus(domainId, this.tdoc.docId, this.user._id),
|
tsdoc: await contest.getStatus(domainId, this.tdoc.docId, this.user._id),
|
||||||
udoc: await user.getById(domainId, this.tdoc.owner),
|
udoc: await user.getById(domainId, this.tdoc.owner),
|
||||||
files: sortFiles(this.tdoc.files || []),
|
files: sortFiles(this.tdoc.files || []),
|
||||||
urlForFile: (filename: string) => this.url('homework_file_download', { tid, filename }),
|
urlForFile: (filename: string) => this.url('homework_file_download', { tid, filename, type: 'public' }),
|
||||||
};
|
};
|
||||||
this.response.pjax = 'partials/files.html';
|
this.response.pjax = 'partials/files.html';
|
||||||
this.response.template = 'homework_files.html';
|
this.response.template = 'homework_files.html';
|
||||||
@@ -289,8 +289,8 @@ export class HomeworkFilesHandler extends Handler {
|
|||||||
if (size >= system.get('limit.contest_files_size')) {
|
if (size >= system.get('limit.contest_files_size')) {
|
||||||
throw new FileLimitExceededError('size');
|
throw new FileLimitExceededError('size');
|
||||||
}
|
}
|
||||||
await storage.put(`contest/${domainId}/${tid}/private/${filename}`, file.filepath, this.user._id);
|
await storage.put(`contest/${domainId}/${tid}/public/${filename}`, file.filepath, this.user._id);
|
||||||
const meta = await storage.getMeta(`contest/${domainId}/${tid}/private/${filename}`);
|
const meta = await storage.getMeta(`contest/${domainId}/${tid}/public/${filename}`);
|
||||||
const payload = { _id: filename, name: filename, ...pick(meta, ['size', 'lastModified', 'etag']) };
|
const payload = { _id: filename, name: filename, ...pick(meta, ['size', 'lastModified', 'etag']) };
|
||||||
if (!meta) throw new FileUploadError();
|
if (!meta) throw new FileUploadError();
|
||||||
await contest.edit(domainId, tid, { files: [...(this.tdoc.files || []), payload] });
|
await contest.edit(domainId, tid, { files: [...(this.tdoc.files || []), payload] });
|
||||||
@@ -301,7 +301,7 @@ export class HomeworkFilesHandler extends Handler {
|
|||||||
@post('files', Types.ArrayOf(Types.Filename))
|
@post('files', Types.ArrayOf(Types.Filename))
|
||||||
async postDeleteFiles(domainId: string, tid: ObjectId, files: string[]) {
|
async postDeleteFiles(domainId: string, tid: ObjectId, files: string[]) {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
storage.del(files.map((t) => `contest/${domainId}/${tid}/private/${t}`), this.user._id),
|
storage.del(files.map((t) => `contest/${domainId}/${tid}/public/${t}`), this.user._id),
|
||||||
contest.edit(domainId, tid, { files: this.tdoc.files.filter((i) => !files.includes(i.name)) }),
|
contest.edit(domainId, tid, { files: this.tdoc.files.filter((i) => !files.includes(i.name)) }),
|
||||||
]);
|
]);
|
||||||
this.back();
|
this.back();
|
||||||
@@ -315,7 +315,7 @@ export async function apply(ctx) {
|
|||||||
ctx.Route('homework_code', '/homework/:tid/code', ContestCodeHandler, PERM.PERM_VIEW_HOMEWORK);
|
ctx.Route('homework_code', '/homework/:tid/code', ContestCodeHandler, PERM.PERM_VIEW_HOMEWORK);
|
||||||
ctx.Route('homework_edit', '/homework/:tid/edit', HomeworkEditHandler);
|
ctx.Route('homework_edit', '/homework/:tid/edit', HomeworkEditHandler);
|
||||||
ctx.Route('homework_files', '/homework/:tid/file', HomeworkFilesHandler, PERM.PERM_VIEW_HOMEWORK);
|
ctx.Route('homework_files', '/homework/:tid/file', HomeworkFilesHandler, PERM.PERM_VIEW_HOMEWORK);
|
||||||
ctx.Route('homework_file_download', '/homework/:tid/file/:filename', ContestFileDownloadHandler, PERM.PERM_VIEW_HOMEWORK);
|
ctx.Route('homework_file_download', '/homework/:tid/file/:type/:filename', ContestFileDownloadHandler, PERM.PERM_VIEW_HOMEWORK);
|
||||||
await ctx.inject(['scoreboard'], ({ Route }) => {
|
await ctx.inject(['scoreboard'], ({ Route }) => {
|
||||||
Route('homework_scoreboard', '/homework/:tid/scoreboard', ContestScoreboardHandler, PERM.PERM_VIEW_HOMEWORK_SCOREBOARD);
|
Route('homework_scoreboard', '/homework/:tid/scoreboard', ContestScoreboardHandler, PERM.PERM_VIEW_HOMEWORK_SCOREBOARD);
|
||||||
Route('homework_scoreboard_view', '/homework/:tid/scoreboard/:view', ContestScoreboardHandler, PERM.PERM_VIEW_HOMEWORK_SCOREBOARD);
|
Route('homework_scoreboard_view', '/homework/:tid/scoreboard/:view', ContestScoreboardHandler, PERM.PERM_VIEW_HOMEWORK_SCOREBOARD);
|
||||||
|
|||||||
@@ -617,12 +617,21 @@ export const coreScripts: MigrationScript[] = [
|
|||||||
await discussion.coll.deleteMany({ content: { $not: { $type: 'string' } } });
|
await discussion.coll.deleteMany({ content: { $not: { $type: 'string' } } });
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
async function _95_96() {
|
null,
|
||||||
|
async function _96_97() {
|
||||||
const files = await StorageModel.list('contest/', true);
|
const files = await StorageModel.list('contest/', true);
|
||||||
|
const rename = async (path: string, newPath: string) => {
|
||||||
|
if (path === newPath) return;
|
||||||
|
console.log('Rename', path, '->', newPath);
|
||||||
|
await StorageModel.rename(path, newPath);
|
||||||
|
};
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const [, domainId, tid, type, name] = file.path.split('/');
|
const [, domainId, tid, type, name] = file.path.split('/');
|
||||||
if (!name) await StorageModel.rename(file.path, `contest/${domainId}/${tid}/public/${type}`);
|
const tdoc = await contest.get(domainId, new ObjectId(tid));
|
||||||
|
if (!tdoc) console.error('Contest not found', file.path);
|
||||||
|
if (tdoc.rule === 'homework' || !name) {
|
||||||
|
await rename(file.path, `contest/${domainId}/${tid}/public/${name || type}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@@ -6,7 +6,6 @@ import fs from 'fs-extra';
|
|||||||
import { globbySync } from 'globby';
|
import { globbySync } from 'globby';
|
||||||
import webpack, { Stats } from 'webpack';
|
import webpack, { Stats } from 'webpack';
|
||||||
import WebpackDevServer from 'webpack-dev-server';
|
import WebpackDevServer from 'webpack-dev-server';
|
||||||
import pkg from '../package.json';
|
|
||||||
import webpackConfig from './config/webpack';
|
import webpackConfig from './config/webpack';
|
||||||
import root from './utils/root';
|
import root from './utils/root';
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@
|
|||||||
<button class="primary rounded button" name="upload_file">{{ _('Upload File') }}</button>
|
<button class="primary rounded button" name="upload_file">{{ _('Upload File') }}</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% set files = tdoc.privateFiles %}
|
{% set files = privateFiles %}
|
||||||
{% set filetype = "private" %}
|
{% set filetype = "private" %}
|
||||||
{% include "partials/files.html" %}
|
{% include "partials/files.html" %}
|
||||||
<div class="section__body">
|
<div class="section__body">
|
||||||
|
|||||||
Reference in new issue
Block a user