Files
dify/web/app/components/workflow/skill/hooks/use-skill-file-data.ts
yyh 8486c675c8 refactor(skill): extract hooks from skill-doc-editor for better separation
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.
2026-01-19 23:25:48 +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 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,
}
}