mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui: fix image paste on contest_edit and homework_edit page
This commit is contained in:
2 files changed
+19
-8
No files matched your search
@@ -146,8 +146,13 @@ export default class Editor extends DOMAttachedObject {
|
|||||||
|
|
||||||
async initMarkdownEditor() {
|
async initMarkdownEditor() {
|
||||||
const pagename = document.documentElement.getAttribute('data-page');
|
const pagename = document.documentElement.getAttribute('data-page');
|
||||||
const isProblemPage = ['problem_create', 'problem_edit'].includes(pagename);
|
const pageUploadConfig: Record<string, { endpoint: string, type?: string }> = {
|
||||||
const isProblemEdit = pagename === 'problem_edit';
|
problem_edit: { endpoint: './files', type: 'additional_file' },
|
||||||
|
homework_edit: { endpoint: './file' },
|
||||||
|
contest_edit: { endpoint: './management', type: 'public' },
|
||||||
|
};
|
||||||
|
const uploadCfg = pageUploadConfig[pagename];
|
||||||
|
const useFileProtocol = !!uploadCfg || ['problem_create', 'homework_create', 'contest_create'].includes(pagename);
|
||||||
const that = this;
|
const that = this;
|
||||||
const { $dom } = this;
|
const { $dom } = this;
|
||||||
const hasFocus = $dom.is(':focus') || $dom.hasClass('autofocus');
|
const hasFocus = $dom.is(':focus') || $dom.hasClass('autofocus');
|
||||||
@@ -234,11 +239,11 @@ export default class Editor extends DOMAttachedObject {
|
|||||||
}
|
}
|
||||||
if (!ext) return i18n('No Supported file type.');
|
if (!ext) return i18n('No Supported file type.');
|
||||||
const filename = `${nanoid()}.${ext}`;
|
const filename = `${nanoid()}.${ext}`;
|
||||||
await uploadFiles(isProblemEdit ? './files' : '/file', [files[0]], {
|
await uploadFiles(uploadCfg?.endpoint || '/file', [files[0]], {
|
||||||
type: isProblemEdit ? 'additional_file' : undefined,
|
type: uploadCfg?.type,
|
||||||
filenameCallback: () => filename,
|
filenameCallback: () => filename,
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
callback([`${isProblemPage ? 'file://' : `/file/${UserContext._id}/`}${filename}`]);
|
callback([`${useFileProtocol ? 'file://' : `/file/${UserContext._id}/`}${filename}`]);
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
callback([]);
|
callback([]);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -13,7 +13,13 @@ import { Media } from '../../backendlib/markdown-it-media';
|
|||||||
import { xssProtector } from '../../backendlib/markdown-it-xss';
|
import { xssProtector } from '../../backendlib/markdown-it-xss';
|
||||||
|
|
||||||
const pagename = document.documentElement.getAttribute('data-page');
|
const pagename = document.documentElement.getAttribute('data-page');
|
||||||
const isProblemPage = ['problem_create', 'problem_edit'].includes(pagename);
|
const previewConfig: Record<string, string> = {
|
||||||
|
problem_edit: './file/',
|
||||||
|
homework_edit: './file/public/',
|
||||||
|
contest_edit: './file/public/',
|
||||||
|
};
|
||||||
|
const isCreatePage = ['problem_create', 'homework_create', 'contest_create'].includes(pagename);
|
||||||
|
const filePreviewPrefix = previewConfig[pagename] || (isCreatePage ? `/file/${UserContext._id}/` : null);
|
||||||
|
|
||||||
config({
|
config({
|
||||||
markdownItConfig(mdit) {
|
markdownItConfig(mdit) {
|
||||||
@@ -31,9 +37,9 @@ config({
|
|||||||
mdit.use(MergeCells);
|
mdit.use(MergeCells);
|
||||||
mdit.use(xssProtector);
|
mdit.use(xssProtector);
|
||||||
mdit.use(katex);
|
mdit.use(katex);
|
||||||
if (isProblemPage) {
|
if (filePreviewPrefix) {
|
||||||
mdit.core.ruler.before('normalize', 'xss', (state) => {
|
mdit.core.ruler.before('normalize', 'xss', (state) => {
|
||||||
state.src = state.src.replace(/file:\/\//g, pagename === 'problem_create' ? `/file/${UserContext._id}/` : './file/');
|
state.src = state.src.replace(/file:\/\//g, filePreviewPrefix);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in new issue
Block a user