fix(skill): use downloadUrl utility instead of window.open for file downloads

Replaces window.open with the downloadUrl helper from utils/download.ts
to trigger proper browser download behavior via <a download> instead of
opening a new tab that may display garbled content.
This commit is contained in:
yyh
2026-01-29 12:49:15 +08:00
parent bd4b76db5c
commit efb3657cfe
3 changed files with 10 additions and 10 deletions

View File

@ -1,21 +1,22 @@
'use client'
// Handles file download operation - opens download URL in new tab
import { useCallback, useState } from 'react'
import { useTranslation } from 'react-i18next'
import Toast from '@/app/components/base/toast'
import { consoleClient } from '@/service/client'
import { downloadUrl } from '@/utils/download'
type UseDownloadOperationOptions = {
appId: string
nodeId: string
fileName?: string
onClose: () => void
}
export function useDownloadOperation({
appId,
nodeId,
fileName,
onClose,
}: UseDownloadOperationOptions) {
const { t } = useTranslation('workflow')
@ -25,7 +26,6 @@ export function useDownloadOperation({
if (!nodeId || !appId)
return
// Close menu immediately before any async operation
onClose()
setIsDownloading(true)
@ -34,9 +34,7 @@ export function useDownloadOperation({
params: { appId, nodeId },
})
// Open download URL in new tab (consistent with UnsupportedFileDownload)
if (typeof window !== 'undefined')
window.open(download_url, '_blank', 'noopener,noreferrer')
downloadUrl({ url: download_url, fileName })
}
catch {
Toast.notify({
@ -47,7 +45,7 @@ export function useDownloadOperation({
finally {
setIsDownloading(false)
}
}, [appId, nodeId, onClose, t])
}, [appId, nodeId, fileName, onClose, t])
return {
handleDownload,

View File

@ -55,6 +55,7 @@ export function useFileOperations({
const downloadOps = useDownloadOperation({
appId,
nodeId,
fileName: node?.data.name,
onClose,
})