mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core&ui: support pasting image in editor
This commit is contained in:
1 parent
6a289f788d
commit
8223b45d23
13 files changed
+131
-39
No files matched your search
@@ -790,8 +790,20 @@ export class ProblemCreateHandler extends Handler {
|
||||
domainId: string, title: string, content: string, pid: string,
|
||||
hidden = false, difficulty = 0, tag: string[] = [], assign: string[] = [],
|
||||
) {
|
||||
if (pid && await problem.get(domainId, pid)) throw new BadRequestError('invalid pid');
|
||||
if (pid && await problem.get(domainId, pid)) throw new BadRequestError('ProblemID already exists');
|
||||
const docId = await problem.add(domainId, pid, title, content, this.user._id, tag ?? [], hidden, assign);
|
||||
const files = new Set(Array.from(content.matchAll(/file:\/\/([a-zA-Z0-9_-]+\.[a-zA-Z0-9]+)/g)).map((i) => i[1]));
|
||||
const tasks = [];
|
||||
for (const file of files) {
|
||||
if (this.user._files.find((i) => i.name === file)) {
|
||||
tasks.push(
|
||||
storage.rename(`user/${this.user._id}/${file}`, `problem/${domainId}/${docId}/additional_file/${file}`)
|
||||
.then(() => problem.addAdditionalFile(domainId, docId, file, '', true)),
|
||||
user.setById(this.user._id, { _files: this.user._files.filter((i) => i.name !== file) }),
|
||||
);
|
||||
}
|
||||
}
|
||||
await Promise.all(tasks);
|
||||
if (difficulty) await problem.edit(domainId, docId, { difficulty });
|
||||
this.response.body = { pid: pid || docId };
|
||||
this.response.redirect = this.url('problem_files', { pid: pid || docId });
|
||||
|
||||
Reference in new issue
Block a user