From fe09f88ea37ff1d70e928cde8bb17a50e9acda89 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sun, 14 Sep 2025 18:26:41 -0700 Subject: [PATCH] [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. --- src/composables/graph/useImageMenuOptions.ts | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/src/composables/graph/useImageMenuOptions.ts b/src/composables/graph/useImageMenuOptions.ts index ac613629f..3956edefa 100644 --- a/src/composables/graph/useImageMenuOptions.ts +++ b/src/composables/graph/useImageMenuOptions.ts @@ -1,5 +1,6 @@ import { useI18n } from 'vue-i18n' +import { downloadFile } from '@/base/common/downloadUtil' import { useCommandStore } from '@/stores/commandStore' import type { MenuOption } from './useMoreOptionsMenu' @@ -69,22 +70,7 @@ export function useImageMenuOptions() { try { const url = new URL(img.src) url.searchParams.delete('preview') - - 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) - } - }) + downloadFile(url.toString()) } catch (error) { console.error('Failed to save image:', error) }