feat: 聊天文件
This commit is contained in:
@@ -8,6 +8,7 @@ import ReactDOM from 'react-dom/client'
|
|||||||
|
|
||||||
import './ui/custom-elements/chat-image.ts'
|
import './ui/custom-elements/chat-image.ts'
|
||||||
import './ui/custom-elements/chat-video.ts'
|
import './ui/custom-elements/chat-video.ts'
|
||||||
|
import './ui/custom-elements/chat-file.ts'
|
||||||
|
|
||||||
const urlParams = new URL(location.href).searchParams
|
const urlParams = new URL(location.href).searchParams
|
||||||
|
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ const markedInstance = new marked.Marked({
|
|||||||
if (/uploaded_files\/[A-Za-z0-9]+$/.test(href)) {
|
if (/uploaded_files\/[A-Za-z0-9]+$/.test(href)) {
|
||||||
return ({
|
return ({
|
||||||
Image: `<chat-image src="${href}" alt="${text}"></chat-image>`,
|
Image: `<chat-image src="${href}" alt="${text}"></chat-image>`,
|
||||||
Video: `<chat-video src="${href}" alt="${text}"></chat-video>`,
|
Video: `<chat-video src="${href}"></chat-video>`,
|
||||||
File: `<chat-file src="${href}" alt="${text}"></chat-file>`,
|
File: `<chat-file href="${href}" name="${/^Video|File=(.*)/.exec(text)?.[1] || 'Unnamed file'}"></chat-file>`,
|
||||||
})?.[type] || ``
|
})?.[type] || ``
|
||||||
}
|
}
|
||||||
return ``
|
return ``
|
||||||
@@ -280,6 +280,7 @@ export default function ChatFragment({ target, showReturnButton, onReturnButtonC
|
|||||||
'src',
|
'src',
|
||||||
'alt',
|
'alt',
|
||||||
'href',
|
'href',
|
||||||
|
'name',
|
||||||
],
|
],
|
||||||
}).replaceAll('\n', '<br>')
|
}).replaceAll('\n', '<br>')
|
||||||
const lastDate = date
|
const lastDate = date
|
||||||
|
|||||||
22
client/ui/custom-elements/chat-file.ts
Normal file
22
client/ui/custom-elements/chat-file.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { $ } from 'mdui/jq'
|
||||||
|
|
||||||
|
customElements.define('chat-file', class extends HTMLElement {
|
||||||
|
constructor() {
|
||||||
|
super()
|
||||||
|
}
|
||||||
|
connectedCallback() {
|
||||||
|
this.style.display = 'block'
|
||||||
|
const e = new DOMParser().parseFromString(`
|
||||||
|
<div style="width: 100%;height: 100%;">
|
||||||
|
<mdui-card variant="outlined" clickable style="display: flex;align-items: center;">
|
||||||
|
<mdui-icon name="insert_drive_file" style="margin: 13px;font-size: 34px;"></mdui-icon>
|
||||||
|
<span style="margin-right: 13px;"></span>
|
||||||
|
</mdui-card>
|
||||||
|
</div>`, 'text/html').body.firstChild as HTMLElement
|
||||||
|
$(e).find('span').text($(this).attr("name"))
|
||||||
|
const href = $(this).attr('href')
|
||||||
|
// deno-lint-ignore no-window
|
||||||
|
e.onclick = () => window.open(href, '_blank')
|
||||||
|
this.appendChild(e)
|
||||||
|
}
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user