mirror of
https://github.com/langgenius/dify.git
synced 2026-02-24 20:01:22 +08:00
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.
45 lines
1.2 KiB
TypeScript
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,
|
|
}
|
|
}
|