1515
1616import uuid_utils .compat as uuid
1717from charset_normalizer import detect
18+ from django .db .models import QuerySet
1819from django .utils .translation import gettext_lazy as _
1920
2021from common .handle .base_split_handle import BaseSplitHandle
@@ -38,6 +39,16 @@ def get_buffer(self, file):
3839 return self .buffer
3940
4041
42+ def save_image (image_list ):
43+ if image_list is not None and len (image_list ) > 0 :
44+ exist_image_list = [str (i .get ('id' )) for i in
45+ QuerySet (File ).filter (id__in = [i .id for i in image_list ]).values ('id' )]
46+ save_image_list = [image for image in image_list if not exist_image_list .__contains__ (str (image .id ))]
47+ save_image_list = list ({img .id : img for img in save_image_list }.values ())
48+ if len (save_image_list ) > 0 :
49+ QuerySet (File ).bulk_create (save_image_list )
50+
51+
4152default_split_handle = TextSplitHandle ()
4253split_handles = [
4354 HTMLSplitHandle (),
@@ -82,20 +93,20 @@ def get_image_list(result_list: list, zip_files: List[str]):
8293 '/' ) else source_image_path )
8394 if not zip_files .__contains__ (image_path ):
8495 continue
85- if image_path .startswith ('api /file/' ) or image_path .startswith ('api /image/' ):
86- image_id = image_path .replace ('api /file/' , '' ).replace ('api /image/' , '' )
96+ if image_path .startswith ('oss /file/' ) or image_path .startswith ('oss /image/' ):
97+ image_id = image_path .replace ('oss /file/' , '' ).replace ('oss /image/' , '' )
8798 if is_valid_uuid (image_id ):
8899 image_file_list .append ({'source_file' : image_path ,
89100 'image_id' : image_id })
90101 else :
91102 image_file_list .append ({'source_file' : image_path ,
92103 'image_id' : new_image_id })
93- content = content .replace (source_image_path , f'/api /image/{ new_image_id } ' )
104+ content = content .replace (source_image_path , f'/oss /image/{ new_image_id } ' )
94105 p ['content' ] = content
95106 else :
96107 image_file_list .append ({'source_file' : image_path ,
97108 'image_id' : new_image_id })
98- content = content .replace (source_image_path , f'/api /image/{ new_image_id } ' )
109+ content = content .replace (source_image_path , f'/oss /image/{ new_image_id } ' )
99110 p ['content' ] = content
100111
101112 return image_file_list
0 commit comments