feat: Add Download Button to UI for Knowledge Resource Source Files (#23320)

This commit is contained in:
Warren Wong
2025-08-03 16:26:11 +08:00
committed by GitHub
parent 7831d44099
commit 6d5a7684b4
5 changed files with 110 additions and 0 deletions

View File

@@ -9,6 +9,8 @@ import { pauseDocIndexing, resumeDocIndexing } from '../datasets'
import type { DocumentDetailResponse, DocumentListResponse, UpdateDocumentBatchParams } from '@/models/datasets'
import { DocumentActionType } from '@/models/datasets'
import type { CommonResponse } from '@/models/common'
// Download document with authentication (sends Authorization header)
import Toast from '@/app/components/base/toast'
const NAME_SPACE = 'knowledge/document'
@@ -95,6 +97,21 @@ export const useSyncDocument = () => {
})
}
// Download document with authentication (sends Authorization header)
export const useDocumentDownload = () => {
return useMutation({
mutationFn: async ({ datasetId, documentId }: { datasetId: string; documentId: string }) => {
// The get helper automatically adds the Authorization header from localStorage
return get<CommonResponse>(`/datasets/${datasetId}/documents/${documentId}/upload-file`)
},
onError: (error: any) => {
// Show a toast notification if download fails
const message = error?.message || 'Download failed.'
Toast.notify({ type: 'error', message })
},
})
}
export const useSyncWebsite = () => {
return useMutation({
mutationFn: ({ datasetId, documentId }: UpdateDocumentBatchParams) => {