mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-28 18:22:40 +00:00
[refactor] deduplicate download functionality in useImageMenuOptions (#5569)
Replace duplicated download implementation in saveImage function with the existing downloadFile utility from downloadUtil. This removes 18 lines of duplicate code while maintaining identical functionality. Changes: - Import downloadFile from @/base/common/downloadUtil - Replace manual anchor element creation with downloadFile call - Maintain same URL preprocessing (removing preview parameter) - Keep existing error handling The downloadFile utility already includes comprehensive test coverage and handles filename extraction, DOM manipulation, and cleanup.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
|
|
||||||
|
import { downloadFile } from '@/base/common/downloadUtil'
|
||||||
import { useCommandStore } from '@/stores/commandStore'
|
import { useCommandStore } from '@/stores/commandStore'
|
||||||
|
|
||||||
import type { MenuOption } from './useMoreOptionsMenu'
|
import type { MenuOption } from './useMoreOptionsMenu'
|
||||||
@@ -69,22 +70,7 @@ export function useImageMenuOptions() {
|
|||||||
try {
|
try {
|
||||||
const url = new URL(img.src)
|
const url = new URL(img.src)
|
||||||
url.searchParams.delete('preview')
|
url.searchParams.delete('preview')
|
||||||
|
downloadFile(url.toString())
|
||||||
const a = document.createElement('a')
|
|
||||||
a.href = url.toString()
|
|
||||||
a.setAttribute(
|
|
||||||
'download',
|
|
||||||
new URLSearchParams(url.search).get('filename') ?? 'image.png'
|
|
||||||
)
|
|
||||||
a.style.display = 'none'
|
|
||||||
document.body.appendChild(a)
|
|
||||||
a.click()
|
|
||||||
|
|
||||||
requestAnimationFrame(() => {
|
|
||||||
if (document.body.contains(a)) {
|
|
||||||
document.body.removeChild(a)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to save image:', error)
|
console.error('Failed to save image:', error)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user