mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-05-08 03:37:28 +08:00
fix: enable paste upload with progress
This commit is contained in:
@@ -81,17 +81,42 @@ export function createVditor(editorId, options = {}) {
|
|||||||
multiple: false,
|
multiple: false,
|
||||||
handler: async (files) => {
|
handler: async (files) => {
|
||||||
const file = files[0]
|
const file = files[0]
|
||||||
const res = await fetch(`${API_BASE_URL}/api/upload/presign?filename=${encodeURIComponent(file.name)}`, {
|
vditor.tip.show('图片上传中', 0)
|
||||||
headers: { Authorization: `Bearer ${getToken()}` }
|
vditor.disabled()
|
||||||
})
|
const res = await fetch(
|
||||||
if (!res.ok) return '获取上传地址失败'
|
`${API_BASE_URL}/api/upload/presign?filename=${encodeURIComponent(file.name)}`,
|
||||||
|
{ headers: { Authorization: `Bearer ${getToken()}` } }
|
||||||
|
)
|
||||||
|
if (!res.ok) {
|
||||||
|
vditor.enable()
|
||||||
|
vditor.tip.hide()
|
||||||
|
return '获取上传地址失败'
|
||||||
|
}
|
||||||
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) {
|
||||||
|
vditor.enable()
|
||||||
|
vditor.tip.hide()
|
||||||
|
return '上传失败'
|
||||||
|
}
|
||||||
|
|
||||||
const ext = file.name.split('.').pop().toLowerCase()
|
const ext = file.name.split('.').pop().toLowerCase()
|
||||||
const imageExts = ['apng','bmp','gif','ico','cur','jpg','jpeg','jfif','pjp','pjpeg','png','svg','webp']
|
const imageExts = [
|
||||||
const audioExts = ['wav','mp3','ogg']
|
'apng',
|
||||||
|
'bmp',
|
||||||
|
'gif',
|
||||||
|
'ico',
|
||||||
|
'cur',
|
||||||
|
'jpg',
|
||||||
|
'jpeg',
|
||||||
|
'jfif',
|
||||||
|
'pjp',
|
||||||
|
'pjpeg',
|
||||||
|
'png',
|
||||||
|
'svg',
|
||||||
|
'webp'
|
||||||
|
]
|
||||||
|
const audioExts = ['wav', 'mp3', 'ogg']
|
||||||
let md
|
let md
|
||||||
if (imageExts.includes(ext)) {
|
if (imageExts.includes(ext)) {
|
||||||
md = ``
|
md = ``
|
||||||
@@ -101,6 +126,8 @@ export function createVditor(editorId, options = {}) {
|
|||||||
md = `[${file.name}](${info.fileUrl})`
|
md = `[${file.name}](${info.fileUrl})`
|
||||||
}
|
}
|
||||||
vditor.insertValue(md + '\n')
|
vditor.insertValue(md + '\n')
|
||||||
|
vditor.enable()
|
||||||
|
vditor.tip.hide()
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user