mirror of
https://github.com/langgenius/dify.git
synced 2026-03-19 05:37:42 +08:00
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.
This commit is contained in:
@ -9,19 +9,19 @@ export type SkillFileDataResult = {
|
||||
|
||||
/**
|
||||
* Hook to fetch file data for skill documents.
|
||||
* Fetches content for editable files and download URL for media files.
|
||||
* Fetches content for editable files and download URL for non-editable files.
|
||||
*/
|
||||
export function useSkillFileData(
|
||||
appId: string,
|
||||
nodeId: string | null | undefined,
|
||||
isMediaFile: boolean,
|
||||
isEditable: boolean,
|
||||
): SkillFileDataResult {
|
||||
const {
|
||||
data: fileContent,
|
||||
isLoading: isContentLoading,
|
||||
error: contentError,
|
||||
} = useGetAppAssetFileContent(appId, nodeId || '', {
|
||||
enabled: !isMediaFile,
|
||||
enabled: isEditable,
|
||||
})
|
||||
|
||||
const {
|
||||
@ -29,11 +29,11 @@ export function useSkillFileData(
|
||||
isLoading: isDownloadUrlLoading,
|
||||
error: downloadUrlError,
|
||||
} = useGetAppAssetFileDownloadUrl(appId, nodeId || '', {
|
||||
enabled: isMediaFile && !!nodeId,
|
||||
enabled: !isEditable && !!nodeId,
|
||||
})
|
||||
|
||||
const isLoading = isMediaFile ? isDownloadUrlLoading : isContentLoading
|
||||
const error = isMediaFile ? downloadUrlError : contentError
|
||||
const isLoading = isEditable ? isContentLoading : isDownloadUrlLoading
|
||||
const error = isEditable ? contentError : downloadUrlError
|
||||
|
||||
return {
|
||||
fileContent,
|
||||
|
||||
@ -44,9 +44,9 @@ const SkillDocEditor: FC = () => {
|
||||
|
||||
const currentFileNode = activeTabId ? nodeMap?.get(activeTabId) : undefined
|
||||
|
||||
const { isMarkdown, isCodeOrText, isImage, isVideo, isOffice, isEditable, isMediaFile } = useFileTypeInfo(currentFileNode)
|
||||
const { isMarkdown, isCodeOrText, isImage, isVideo, isOffice, isEditable } = useFileTypeInfo(currentFileNode)
|
||||
|
||||
const { fileContent, downloadUrlData, isLoading, error } = useSkillFileData(appId, activeTabId, isMediaFile)
|
||||
const { fileContent, downloadUrlData, isLoading, error } = useSkillFileData(appId, activeTabId, isEditable)
|
||||
|
||||
const originalContent = fileContent?.content ?? ''
|
||||
|
||||
@ -150,8 +150,8 @@ const SkillDocEditor: FC = () => {
|
||||
)
|
||||
}
|
||||
|
||||
const mediaPreviewUrl = downloadUrlData?.download_url || ''
|
||||
const textPreviewUrl = fileContent?.content || ''
|
||||
// For non-editable files (media, office, unsupported), use download URL
|
||||
const downloadUrl = downloadUrlData?.download_url || ''
|
||||
const fileName = currentFileNode?.name || ''
|
||||
const fileSize = currentFileNode?.size
|
||||
const isUnsupportedFile = !isMarkdown && !isCodeOrText && !isImage && !isVideo && !isOffice
|
||||
@ -183,7 +183,7 @@ const SkillDocEditor: FC = () => {
|
||||
? (
|
||||
<MediaFilePreview
|
||||
type={isImage ? 'image' : 'video'}
|
||||
src={mediaPreviewUrl}
|
||||
src={downloadUrl}
|
||||
/>
|
||||
)
|
||||
: null}
|
||||
@ -197,7 +197,7 @@ const SkillDocEditor: FC = () => {
|
||||
<UnsupportedFileDownload
|
||||
name={fileName}
|
||||
size={fileSize}
|
||||
downloadUrl={textPreviewUrl}
|
||||
downloadUrl={downloadUrl}
|
||||
/>
|
||||
)
|
||||
: null}
|
||||
|
||||
Reference in New Issue
Block a user