mirror of
https://github.com/langgenius/dify.git
synced 2026-05-04 09:28:04 +08:00
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:
@ -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,
|
||||
|
||||
@ -55,6 +55,7 @@ export function useFileOperations({
|
||||
const downloadOps = useDownloadOperation({
|
||||
appId,
|
||||
nodeId,
|
||||
fileName: node?.data.name,
|
||||
onClose,
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user