From 4bdfad340fd6cfb31a2ed52fb748328fae41fa9e Mon Sep 17 00:00:00 2001 From: MoonLeeeaf <150461955+MoonLeeeaf@users.noreply.github.com> Date: Wed, 12 Jun 2024 22:07:50 +0800 Subject: [PATCH] fix: image --- ling_chair_http/chat-message.css | 7 ++++++- ling_chair_http/finally.js | 21 +++++++++++++-------- ling_chair_http/handler.js | 11 +++++++++-- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/ling_chair_http/chat-message.css b/ling_chair_http/chat-message.css index 755dfb5..dd59cab 100644 --- a/ling_chair_http/chat-message.css +++ b/ling_chair_http/chat-message.css @@ -82,4 +82,9 @@ width: 50px; height: 50px; border-radius: 50%; -} \ No newline at end of file +} + +.message-image { + max-width: 40%; + max-height: 40%; +} diff --git a/ling_chair_http/finally.js b/ling_chair_http/finally.js index 91295f5..6595466 100644 --- a/ling_chair_http/finally.js +++ b/ling_chair_http/finally.js @@ -53,11 +53,11 @@ ChatMsgAdapter.initMsgElementEvents() ChatMsgAdapter.initInputResizer() -const showLinkDialog = (link) => mdui.alert(decodeURIComponent(link) + "
如果你确认此链接是安全的, 那么请点我", '链接', () => { }, { confirmText: "关闭" }) +const showLinkDialog = (link) => mdui.alert(decodeURI(link) + "
如果你确认此链接是安全的, 那么请点我", '链接', () => { }, { confirmText: "关闭" }) -const showImageDialog = (link, id, alt) => mdui.alert(`此图片链接来源未知: ${decodeURIComponent(link)}
如果你希望加载, 请点我`, '外部图片', () => { }, { confirmText: "关闭" }) +const showImageDialog = (link, id, alt) => mdui.alert(`此图片链接来源未知: ${decodeURI(link)}
如果你希望加载, 请点我`, '外部图片', () => { }, { confirmText: "关闭" }) -const showCodeDialog = (code) => mdui.alert(`
${decodeURIComponent(code)}
`, '代码块', () => { }, { confirmText: "关闭" }) +const showCodeDialog = (code) => mdui.alert(`
${decodeURI(code)}
`, '代码块', () => { }, { confirmText: "关闭" }) const renderer = { heading(text, level) { @@ -70,23 +70,28 @@ const renderer = { return text }, link(href, title, text) { - return `[链接] ${text}` + return `[链接] ${text}` }, image(href, title, text) { let h = Hash.sha256(href) - if (new URL(href).hostname === new URL(location.href)) - return `${text}` + let out = true + try { + out = new URL(href).hostname === new URL(location.href) + } catch(e) {} + if (out) + return `${text}` else - return `
[外部图片] ${text}
` + return `
[外部图片] ${text}
` }, code(src) { - return `[代码块]` + return `[代码块]` }, } marked.use({ gfm: true, renderer: renderer, + async: true, }) diff --git a/ling_chair_http/handler.js b/ling_chair_http/handler.js index 03261de..adc197c 100644 --- a/ling_chair_http/handler.js +++ b/ling_chair_http/handler.js @@ -399,7 +399,14 @@ class ChatMsgAdapter { let nick = await NickCache.getNick(name) // re.data == null ? name : re.data.nick - let msg = marked.parse(m) + let msg + + try { + msg = await marked.parse(m) + } catch(e) { + console.log("解析消息失败: " + e) + msg = escapeHTML(m) + } let temp if (name === localStorage.userName) @@ -440,7 +447,7 @@ class ChatMsgAdapter { } this.bbn = new Date(t).getMinutes() - + return e } /**