Files
dify/web/app/components/workflow/skill/hooks/use-skill-file-data.ts
yyh b3793b0198 fix(skill): use download URL for all non-editable files
Change useSkillFileData to use isEditable instead of isMediaFile:
- Editable files (markdown, code, text) fetch file content for editing
- Non-editable files (image, video, office, unsupported) fetch download URL

This fixes the download button for unsupported files which was incorrectly
using file content (UTF-8 decoded garbage) instead of the presigned URL.
2026-01-19 23:34:56 +08:00

45 lines
1.2 KiB
TypeScript

import { useGetAppAssetFileContent, useGetAppAssetFileDownloadUrl } from '@/service/use-app-asset'
export type SkillFileDataResult = {
fileContent: ReturnType<typeof useGetAppAssetFileContent>['data']
downloadUrlData: ReturnType<typeof useGetAppAssetFileDownloadUrl>['data']
isLoading: boolean
error: Error | null
}
/**
* Hook to fetch file data for skill documents.
* Fetches content for editable files and download URL for non-editable files.
*/
export function useSkillFileData(
appId: string,
nodeId: string | null | undefined,
isEditable: boolean,
): SkillFileDataResult {
const {
data: fileContent,
isLoading: isContentLoading,
error: contentError,
} = useGetAppAssetFileContent(appId, nodeId || '', {
enabled: isEditable,
})
const {
data: downloadUrlData,
isLoading: isDownloadUrlLoading,
error: downloadUrlError,
} = useGetAppAssetFileDownloadUrl(appId, nodeId || '', {
enabled: !isEditable && !!nodeId,
})
const isLoading = isEditable ? isContentLoading : isDownloadUrlLoading
const error = isEditable ? contentError : downloadUrlError
return {
fileContent,
downloadUrlData,
isLoading,
error,
}
}