refactor(web): consolidate download helpers (#31664)

This commit is contained in:
盐粒 Yanli
2026-01-29 16:02:49 +08:00
committed by GitHub
parent 74cfe77674
commit b9ac7af9c5
26 changed files with 167 additions and 270 deletions

View File

@ -15,7 +15,7 @@ import {
} from '@/app/components/base/portal-to-follow-elem'
import { useDownloadPlugin } from '@/service/use-plugins'
import { cn } from '@/utils/classnames'
import { downloadFile } from '@/utils/format'
import { downloadBlob } from '@/utils/download'
import { getMarketplaceUrl } from '@/utils/var'
type Props = {
@ -67,7 +67,7 @@ const OperationDropdown: FC<Props> = ({
if (!needDownload || !blob)
return
const fileName = `${author}-${name}_${version}.zip`
downloadFile({ data: blob, fileName })
downloadBlob({ data: blob, fileName })
setNeedDownload(false)
queryClient.removeQueries({
queryKey: ['plugins', 'downloadPlugin', downloadInfo],

View File

@ -19,6 +19,7 @@ import {
} from '@/app/components/base/portal-to-follow-elem'
import { useStore } from '@/app/components/workflow/store'
import { cn } from '@/utils/classnames'
import { downloadUrl } from '@/utils/download'
import { useNodesReadOnly } from '../hooks'
import TipPopup from './tip-popup'
@ -146,26 +147,14 @@ const MoreActions: FC = () => {
}
}
const fileName = `${filename}.${type}`
if (currentWorkflow) {
setPreviewUrl(dataUrl)
setPreviewTitle(`${filename}.${type}`)
setPreviewTitle(fileName)
}
const link = document.createElement('a')
link.href = dataUrl
link.download = `${filename}.${type}`
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}
else {
// For current view, just download
const link = document.createElement('a')
link.href = dataUrl
link.download = `${filename}.${type}`
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}
downloadUrl({ url: dataUrl, fileName })
}
catch (error) {
console.error('Export image failed:', error)