mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-28 19:58:11 +08:00
Refactor: Merge document update API (#13962)
### What problem does this PR solve? Refactor: merge document.rename into document.update_document ### Type of change - [x] Refactoring <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a unified document update API (PUT) supporting name, metadata, parser/chunk settings, and status changes. * **Breaking Changes** * Legacy single-parameter rename endpoint removed; renames now require dataset + document identifiers. * `/list` now reads dataset id from a different query parameter. * **Validation / Bug Fixes** * Stricter meta_fields and parser-config validation; unauthenticated requests return 401. * **Frontend** * UI now sends dataset id when saving document names. * **Tests** * Numerous unit and HTTP tests adjusted or removed to match new API and validations. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Jin Hai <haijin.chn@gmail.com> Co-authored-by: Jin Hai <haijin.chn@gmail.com> Co-authored-by: MkDev11 <94194147+MkDev11@users.noreply.github.com> Co-authored-by: mkdev11 <YOUR_GITHUB_ID+MkDev11@users.noreply.github.com> Co-authored-by: mkdev11 <MkDev11@users.noreply.github.com> Co-authored-by: Qi Wang <wangq8@outlook.com> Co-authored-by: dataCenter430 <161712630+dataCenter430@users.noreply.github.com> Co-authored-by: balibabu <cike8899@users.noreply.github.com>
This commit is contained in:
@@ -15,7 +15,10 @@ import {
|
||||
} from '@/interfaces/request/document';
|
||||
import i18n from '@/locales/config';
|
||||
import { EMPTY_METADATA_FIELD } from '@/pages/dataset/dataset/use-select-filters';
|
||||
import kbService, { listDocument } from '@/services/knowledge-service';
|
||||
import kbService, {
|
||||
listDocument,
|
||||
renameDocument,
|
||||
} from '@/services/knowledge-service';
|
||||
import api, { restAPIv1, webAPI } from '@/utils/api';
|
||||
import { getSearchValue } from '@/utils/common-util';
|
||||
import { buildChunkHighlights } from '@/utils/document-util';
|
||||
@@ -336,12 +339,13 @@ export const useSaveDocumentName = () => {
|
||||
mutationFn: async ({
|
||||
name,
|
||||
documentId,
|
||||
kbId,
|
||||
}: {
|
||||
name: string;
|
||||
documentId: string;
|
||||
kbId: string;
|
||||
}) => {
|
||||
const { data } = await kbService.document_rename({
|
||||
doc_id: documentId,
|
||||
const { data } = await renameDocument(kbId, documentId, {
|
||||
name: name,
|
||||
});
|
||||
if (data.code === 0) {
|
||||
|
||||
@@ -15,14 +15,18 @@ export const useRenameDocument = () => {
|
||||
|
||||
const onRenameOk = useCallback(
|
||||
async (name: string) => {
|
||||
if (record?.id) {
|
||||
const ret = await saveName({ documentId: record.id, name });
|
||||
if (record?.id && record?.kb_id) {
|
||||
const ret = await saveName({
|
||||
documentId: record.id,
|
||||
name,
|
||||
kbId: record.kb_id,
|
||||
});
|
||||
if (ret === 0) {
|
||||
hideRenameModal();
|
||||
}
|
||||
}
|
||||
},
|
||||
[record?.id, saveName, hideRenameModal],
|
||||
[record?.id, record?.kb_id, saveName, hideRenameModal],
|
||||
);
|
||||
|
||||
const handleShow = useCallback(
|
||||
|
||||
@@ -77,7 +77,7 @@ const methods = {
|
||||
},
|
||||
document_rename: {
|
||||
url: document_rename,
|
||||
method: 'post',
|
||||
method: 'put',
|
||||
},
|
||||
document_create: {
|
||||
url: document_create,
|
||||
@@ -251,6 +251,12 @@ export const listDocument = (
|
||||
export const documentFilter = (kb_id: string) =>
|
||||
request.post(api.get_dataset_filter, { kb_id });
|
||||
|
||||
export const renameDocument = (
|
||||
datasetId: string,
|
||||
documentId: string,
|
||||
data: { name?: string },
|
||||
) => request.put(api.document_rename(datasetId, documentId), { data });
|
||||
|
||||
export const getMetaDataService = ({
|
||||
kb_id,
|
||||
doc_ids,
|
||||
|
||||
@@ -109,7 +109,8 @@ export default {
|
||||
document_change_status: `${webAPI}/document/change_status`,
|
||||
document_rm: `${webAPI}/document/rm`,
|
||||
document_delete: `${webAPI}/api/document`,
|
||||
document_rename: `${webAPI}/document/rename`,
|
||||
document_rename: (datasetId: string, documentId: string) =>
|
||||
`${restAPIv1}/datasets/${datasetId}/documents/${documentId}`,
|
||||
document_create: `${webAPI}/document/create`,
|
||||
document_run: `${webAPI}/document/run`,
|
||||
document_change_parser: `${webAPI}/document/change_parser`,
|
||||
|
||||
Reference in New Issue
Block a user