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