mirror of
https://github.com/langgenius/dify.git
synced 2026-05-03 17:08:03 +08:00
Extract business logic into dedicated hooks to reduce component complexity: - useFileTypeInfo: file type detection (markdown, code, image, video, etc.) - useSkillFileData: data fetching with conditional API calls - useSkillFileSave: save logic with Ctrl+S keyboard shortcut Also fix Vercel best practice: use ternary instead of && for conditional rendering.
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 media files.
|
|
*/
|
|
export function useSkillFileData(
|
|
appId: string,
|
|
nodeId: string | null | undefined,
|
|
isMediaFile: boolean,
|
|
): SkillFileDataResult {
|
|
const {
|
|
data: fileContent,
|
|
isLoading: isContentLoading,
|
|
error: contentError,
|
|
} = useGetAppAssetFileContent(appId, nodeId || '', {
|
|
enabled: !isMediaFile,
|
|
})
|
|
|
|
const {
|
|
data: downloadUrlData,
|
|
isLoading: isDownloadUrlLoading,
|
|
error: downloadUrlError,
|
|
} = useGetAppAssetFileDownloadUrl(appId, nodeId || '', {
|
|
enabled: isMediaFile && !!nodeId,
|
|
})
|
|
|
|
const isLoading = isMediaFile ? isDownloadUrlLoading : isContentLoading
|
|
const error = isMediaFile ? downloadUrlError : contentError
|
|
|
|
return {
|
|
fileContent,
|
|
downloadUrlData,
|
|
isLoading,
|
|
error,
|
|
}
|
|
}
|