mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-08-10 13:21:00 +00:00
fix: insert uploaded file into vditor
This commit is contained in:
@@ -37,7 +37,8 @@ export function createVditor(editorId, options = {}) {
|
|||||||
return searchUsers(value)
|
return searchUsers(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Vditor(editorId, {
|
let vditor
|
||||||
|
vditor = new Vditor(editorId, {
|
||||||
placeholder,
|
placeholder,
|
||||||
height: 'auto',
|
height: 'auto',
|
||||||
theme: getEditorTheme(),
|
theme: getEditorTheme(),
|
||||||
@@ -87,11 +88,20 @@ export function createVditor(editorId, options = {}) {
|
|||||||
const info = await res.json()
|
const info = await res.json()
|
||||||
const put = await fetch(info.uploadUrl, { method: 'PUT', body: file })
|
const put = await fetch(info.uploadUrl, { method: 'PUT', body: file })
|
||||||
if (!put.ok) return '上传失败'
|
if (!put.ok) return '上传失败'
|
||||||
return JSON.stringify({
|
|
||||||
code: 0,
|
const ext = file.name.split('.').pop().toLowerCase()
|
||||||
msg: '',
|
const imageExts = ['apng','bmp','gif','ico','cur','jpg','jpeg','jfif','pjp','pjpeg','png','svg','webp']
|
||||||
data: { errFiles: [], succMap: { [file.name]: info.fileUrl } }
|
const audioExts = ['wav','mp3','ogg']
|
||||||
})
|
let md
|
||||||
|
if (imageExts.includes(ext)) {
|
||||||
|
md = ``
|
||||||
|
} else if (audioExts.includes(ext)) {
|
||||||
|
md = `<audio controls="controls" src="${info.fileUrl}"></audio>`
|
||||||
|
} else {
|
||||||
|
md = `[${file.name}](${info.fileUrl})`
|
||||||
|
}
|
||||||
|
vditor.insertValue(md + '\n')
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// upload: {
|
// upload: {
|
||||||
@@ -125,4 +135,5 @@ export function createVditor(editorId, options = {}) {
|
|||||||
input,
|
input,
|
||||||
after
|
after
|
||||||
})
|
})
|
||||||
|
return vditor
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user