Change image download from Promise.all to forEach for progressive display

This commit is contained in:
jingrow 2025-11-15 04:47:41 +08:00
parent 72cef8d29b
commit 35e75b3c4b
2 changed files with 25 additions and 7 deletions

View File

@ -900,23 +900,28 @@ function extractAttachmentImageUrls(attachments: any[]): string[] {
return [...new Set(urls)] // return [...new Set(urls)] //
} }
// //
async function autoDownloadImages(imageUrls: string[]) { async function autoDownloadImages(imageUrls: string[]) {
const downloadPromises = imageUrls.map(async (url) => { //
imageUrls.forEach(async (url) => {
const filename = url.split('/').pop() || 'image.jpg' const filename = url.split('/').pop() || 'image.jpg'
try { try {
const result = await downloadImageToLocal(url, filename) const result = await downloadImageToLocal(url, filename)
if (result.success) { if (result.success) {
// //
return !(result as any).data?.cached const imgElements = document.querySelectorAll(`img[src="${url}"], img[src*="${filename}"]`)
imgElements.forEach((img) => {
const imgEl = img as HTMLImageElement
if (imgEl.complete && !imgEl.naturalHeight) {
imgEl.src = url + '?t=' + Date.now()
}
})
} }
} catch (error) { } catch (error) {
//
} }
return false
}) })
await Promise.all(downloadPromises)
} }
// - // -

View File

@ -31,7 +31,9 @@
<img <img
:src="attachment.file_url" :src="attachment.file_url"
:alt="attachment.file_name" :alt="attachment.file_name"
loading="lazy"
@click="openImageGallery(index)" @click="openImageGallery(index)"
@error="handleImageError"
/> />
<div class="image-overlay"> <div class="image-overlay">
<button <button
@ -289,6 +291,17 @@ const addAttachment = () => {
const deleteAttachment = (attachment: any) => { const deleteAttachment = (attachment: any) => {
emit('delete-attachment', attachment) emit('delete-attachment', attachment)
} }
//
const handleImageError = (event: Event) => {
const img = event.target as HTMLImageElement
//
if (img.src && !img.src.includes('?retry=')) {
setTimeout(() => {
img.src = img.src.split('?')[0] + '?retry=' + Date.now()
}, 1000)
}
}
</script> </script>
<style scoped> <style scoped>