e2d5dd6f by 冯轩

init

1 parent c8bacd75
from mimetypes import suffix_map
import os
import io
import time
......@@ -1125,10 +1126,18 @@ class DocView(DocGenericView, DocHandler):
random_int = random.randint(0, consts.TIME_NUM)
metadata_version_id = str(int(time.time()) - random_int)
# 现在不只接受pdf 图片也接收
pdf_file = request.FILES.get('pdf_file')
file_suffux = ''
if isinstance(pdf_file.name, str):
if not pdf_file.name.endswith('pdf') and not pdf_file.name.endswith('PDF'):
self.invalid_params(msg='invalid params: not a PDF file')
# if not pdf_file.name.endswith('pdf') and not pdf_file.name.endswith('PDF'):
# self.invalid_params(msg='invalid params: not a PDF file')
if '.' in pdf_file.name:
file_suffux = pdf_file.name.split('.')[-1]
else:
self.invalid_params(msg='invalid params: invalid file name')
else:
self.invalid_params(msg='invalid params: invalid file name')
business_type = request.POST.get('business_type', '')
document_scheme = request.POST.get('document_scheme', '')
......@@ -1138,9 +1147,10 @@ class DocView(DocGenericView, DocHandler):
args = {'business_type':business_type,'document_scheme':document_scheme,'data_source':data_source,'document_name':document_name,'pdf_file':pdf_file,'fsm':fsm}
# business_type = random.choice(consts.BUSINESS_TYPE_LIST)
# business_type = consts.BUSINESS_TYPE_LIST[0]
tmp_save_path = os.path.join(conf.DATA_DIR, business_type, '{0}.pdf'.format(metadata_version_id))
tmp_save_path = os.path.join(conf.DATA_DIR, business_type, '{0}.{1}}'.format(metadata_version_id, file_suffux))
file_write(pdf_file, tmp_save_path)
if file_suffux.lower() == 'pdf':
try:
file = fitz.Document(tmp_save_path)
except Exception as e:
......@@ -1194,7 +1204,7 @@ class DocView(DocGenericView, DocHandler):
# 3.pdf文件移动
save_dir_path = os.path.join(conf.DATA_DIR, business_type, consts.TMP_DIR_NAME, str(doc.id))
save_file_path = os.path.join(save_dir_path, '{0}.pdf'.format(doc.id))
save_file_path = os.path.join(save_dir_path, '{0}.{1}'.format(doc.id, file_suffux))
os.makedirs(save_dir_path, exist_ok=True)
# file_write(pdf_file, save_file_path)
shutil.move(tmp_save_path, save_file_path)
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!