Feat: When Delete Chunk Will Also Delete Chunk Related Image (#7656)
### What problem does this PR solve? When Delete Chunk Will Also Delete Chunk Related Image ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
parent
1d0dcddf61
commit
d2b346cf9e
1 changed files with 5 additions and 0 deletions
|
|
@ -37,6 +37,7 @@ import xxhash
|
|||
import re
|
||||
|
||||
|
||||
|
||||
@manager.route('/list', methods=['POST']) # noqa: F821
|
||||
@login_required
|
||||
@validate_request("doc_id")
|
||||
|
|
@ -194,6 +195,7 @@ def switch():
|
|||
@login_required
|
||||
@validate_request("chunk_ids", "doc_id")
|
||||
def rm():
|
||||
from rag.utils.storage_factory import STORAGE_IMPL
|
||||
req = request.json
|
||||
try:
|
||||
e, doc = DocumentService.get_by_id(req["doc_id"])
|
||||
|
|
@ -204,6 +206,9 @@ def rm():
|
|||
deleted_chunk_ids = req["chunk_ids"]
|
||||
chunk_number = len(deleted_chunk_ids)
|
||||
DocumentService.decrement_chunk_num(doc.id, doc.kb_id, 1, chunk_number, 0)
|
||||
for cid in deleted_chunk_ids:
|
||||
if STORAGE_IMPL.obj_exist(doc.kb_id, cid):
|
||||
STORAGE_IMPL.rm(doc.kb_id, cid)
|
||||
return get_json_result(data=True)
|
||||
except Exception as e:
|
||||
return server_error_response(e)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue