feat: Add Download Button to UI for Knowledge Resource Source Files (#23320)
This commit is contained in:
@@ -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) => {
|
||||
|
Reference in New Issue
Block a user