mirror of
https://github.com/langgenius/dify.git
synced 2024-11-15 19:22:36 +08:00
Signed-off-by: root <root@localhost.localdomain> Co-authored-by: root <root@localhost.localdomain>
This commit is contained in:
parent
9550b884f7
commit
570f10d91c
|
@ -356,3 +356,19 @@ def content_digest(element):
|
||||||
digest.update(child.encode("utf-8"))
|
digest.update(child.encode("utf-8"))
|
||||||
digest = digest.hexdigest()
|
digest = digest.hexdigest()
|
||||||
return digest
|
return digest
|
||||||
|
|
||||||
|
|
||||||
|
def get_image_upload_file_ids(content):
|
||||||
|
pattern = r"!\[image\]\((http?://.*?(file-preview|image-preview))\)"
|
||||||
|
matches = re.findall(pattern, content)
|
||||||
|
image_upload_file_ids = []
|
||||||
|
for match in matches:
|
||||||
|
if match[1] == "file-preview":
|
||||||
|
content_pattern = r"files/([^/]+)/file-preview"
|
||||||
|
else:
|
||||||
|
content_pattern = r"files/([^/]+)/image-preview"
|
||||||
|
content_match = re.search(content_pattern, match[0])
|
||||||
|
if content_match:
|
||||||
|
image_upload_file_id = content_match.group(1)
|
||||||
|
image_upload_file_ids.append(image_upload_file_id)
|
||||||
|
return image_upload_file_ids
|
||||||
|
|
|
@ -5,6 +5,7 @@ import click
|
||||||
from celery import shared_task
|
from celery import shared_task
|
||||||
|
|
||||||
from core.rag.index_processor.index_processor_factory import IndexProcessorFactory
|
from core.rag.index_processor.index_processor_factory import IndexProcessorFactory
|
||||||
|
from core.tools.utils.web_reader_tool import get_image_upload_file_ids
|
||||||
from extensions.ext_database import db
|
from extensions.ext_database import db
|
||||||
from extensions.ext_storage import storage
|
from extensions.ext_storage import storage
|
||||||
from models.dataset import (
|
from models.dataset import (
|
||||||
|
@ -67,6 +68,16 @@ def clean_dataset_task(
|
||||||
db.session.delete(document)
|
db.session.delete(document)
|
||||||
|
|
||||||
for segment in segments:
|
for segment in segments:
|
||||||
|
image_upload_file_ids = get_image_upload_file_ids(segment.content)
|
||||||
|
for upload_file_id in image_upload_file_ids:
|
||||||
|
image_file = db.session.query(UploadFile).filter(UploadFile.id == upload_file_id).first()
|
||||||
|
try:
|
||||||
|
storage.delete(image_file.key)
|
||||||
|
except Exception:
|
||||||
|
logging.exception(
|
||||||
|
"Delete image_files failed when storage deleted, \
|
||||||
|
image_upload_file_is: {}".format(upload_file_id)
|
||||||
|
)
|
||||||
db.session.delete(segment)
|
db.session.delete(segment)
|
||||||
|
|
||||||
db.session.query(DatasetProcessRule).filter(DatasetProcessRule.dataset_id == dataset_id).delete()
|
db.session.query(DatasetProcessRule).filter(DatasetProcessRule.dataset_id == dataset_id).delete()
|
||||||
|
|
|
@ -6,6 +6,7 @@ import click
|
||||||
from celery import shared_task
|
from celery import shared_task
|
||||||
|
|
||||||
from core.rag.index_processor.index_processor_factory import IndexProcessorFactory
|
from core.rag.index_processor.index_processor_factory import IndexProcessorFactory
|
||||||
|
from core.tools.utils.web_reader_tool import get_image_upload_file_ids
|
||||||
from extensions.ext_database import db
|
from extensions.ext_database import db
|
||||||
from extensions.ext_storage import storage
|
from extensions.ext_storage import storage
|
||||||
from models.dataset import Dataset, DocumentSegment
|
from models.dataset import Dataset, DocumentSegment
|
||||||
|
@ -40,6 +41,16 @@ def clean_document_task(document_id: str, dataset_id: str, doc_form: str, file_i
|
||||||
index_processor.clean(dataset, index_node_ids)
|
index_processor.clean(dataset, index_node_ids)
|
||||||
|
|
||||||
for segment in segments:
|
for segment in segments:
|
||||||
|
image_upload_file_ids = get_image_upload_file_ids(segment.content)
|
||||||
|
for upload_file_id in image_upload_file_ids:
|
||||||
|
image_file = db.session.query(UploadFile).filter(UploadFile.id == upload_file_id).first()
|
||||||
|
try:
|
||||||
|
storage.delete(image_file.key)
|
||||||
|
except Exception:
|
||||||
|
logging.exception(
|
||||||
|
"Delete image_files failed when storage deleted, \
|
||||||
|
image_upload_file_is: {}".format(upload_file_id)
|
||||||
|
)
|
||||||
db.session.delete(segment)
|
db.session.delete(segment)
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user