Add Vue frontend application
This commit is contained in:
73
frontend/src/api/document.ts
Normal file
73
frontend/src/api/document.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import api from './index'
|
||||
|
||||
export interface Document {
|
||||
id: string
|
||||
title: string
|
||||
filename: string
|
||||
file_type: string
|
||||
file_size: number
|
||||
summary?: string
|
||||
chunk_count: number
|
||||
is_indexed: boolean
|
||||
folder_id?: string | null
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export interface SearchResult {
|
||||
chunk_id: string
|
||||
document_id: string
|
||||
document_title: string
|
||||
content: string
|
||||
score: number
|
||||
metadata_?: string
|
||||
prev_chunk?: string
|
||||
next_chunk?: string
|
||||
}
|
||||
|
||||
export interface UploadResponse {
|
||||
id: string
|
||||
title: string
|
||||
chunk_count: number
|
||||
status: string
|
||||
}
|
||||
|
||||
export const documentApi = {
|
||||
list(folderId?: string | null) {
|
||||
return api.get<Document[]>('/api/documents', {
|
||||
params: folderId ? { folder_id: folderId } : undefined,
|
||||
})
|
||||
},
|
||||
|
||||
upload(file: File, folderId?: string | null) {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
if (folderId) {
|
||||
formData.append('folder_id', folderId)
|
||||
}
|
||||
return api.post<UploadResponse>('/api/documents/upload', formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
})
|
||||
},
|
||||
|
||||
get(id: string) {
|
||||
return api.get<Document>(`/api/documents/${id}`)
|
||||
},
|
||||
|
||||
getChunks(id: string) {
|
||||
return api.get<any[]>(`/api/documents/${id}/chunks`)
|
||||
},
|
||||
|
||||
delete(id: string) {
|
||||
return api.delete(`/api/documents/${id}`)
|
||||
},
|
||||
|
||||
search(query: string, top_k = 5, mode = 'hybrid') {
|
||||
return api.get<SearchResult[]>('/api/documents/search', {
|
||||
params: { query, top_k, mode },
|
||||
})
|
||||
},
|
||||
|
||||
getContent(id: string) {
|
||||
return api.get<string>(`/api/documents/${id}/content`)
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user