mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +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() {
|
||||
const pagename = document.documentElement.getAttribute('data-page');
|
||||
const isProblemPage = ['problem_create', 'problem_edit'].includes(pagename);
|
||||
const isProblemEdit = pagename === 'problem_edit';
|
||||
const pageUploadConfig: Record<string, { endpoint: string, type?: string }> = {
|
||||
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 { $dom } = this;
|
||||
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.');
|
||||
const filename = `${nanoid()}.${ext}`;
|
||||
await uploadFiles(isProblemEdit ? './files' : '/file', [files[0]], {
|
||||
type: isProblemEdit ? 'additional_file' : undefined,
|
||||
await uploadFiles(uploadCfg?.endpoint || '/file', [files[0]], {
|
||||
type: uploadCfg?.type,
|
||||
filenameCallback: () => filename,
|
||||
}).then(() => {
|
||||
callback([`${isProblemPage ? 'file://' : `/file/${UserContext._id}/`}${filename}`]);
|
||||
callback([`${useFileProtocol ? 'file://' : `/file/${UserContext._id}/`}${filename}`]);
|
||||
}).catch(() => {
|
||||
callback([]);
|
||||
});
|
||||
|
||||
@@ -13,7 +13,13 @@ import { Media } from '../../backendlib/markdown-it-media';
|
||||
import { xssProtector } from '../../backendlib/markdown-it-xss';
|
||||
|
||||
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({
|
||||
markdownItConfig(mdit) {
|
||||
@@ -31,9 +37,9 @@ config({
|
||||
mdit.use(MergeCells);
|
||||
mdit.use(xssProtector);
|
||||
mdit.use(katex);
|
||||
if (isProblemPage) {
|
||||
if (filePreviewPrefix) {
|
||||
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