clean: _guess_mime → общий mimeutil.py (убраны дубликаты)
This commit is contained in:
+2
-16
@@ -18,6 +18,7 @@ import parser as parser_mod
|
||||
import textify
|
||||
import extractor
|
||||
import differ
|
||||
import mimeutil
|
||||
|
||||
api_bp = Blueprint("api", __name__)
|
||||
|
||||
@@ -107,7 +108,7 @@ def add_supplement(contract_id):
|
||||
return jsonify({"error": "empty filename"}), 400
|
||||
|
||||
filename = file.filename
|
||||
mime_type = _guess_mime(filename) or file.content_type or "application/octet-stream"
|
||||
mime_type = mimeutil.guess_mime(filename) or file.content_type or "application/octet-stream"
|
||||
file_bytes = file.read()
|
||||
|
||||
# 2. Сохранить в documents
|
||||
@@ -260,18 +261,3 @@ def get_history(contract_id):
|
||||
|
||||
# ── Вспомогательные ─────────────────────────────────────────────
|
||||
|
||||
def _guess_mime(filename: str) -> str:
|
||||
"""MIME-тип по расширению."""
|
||||
ext = filename.lower().rsplit(".", 1)[-1] if "." in filename else ""
|
||||
return {
|
||||
"docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
"doc": "application/msword",
|
||||
"pdf": "application/pdf",
|
||||
"zip": "application/zip",
|
||||
}.get(ext, "")
|
||||
|
||||
|
||||
def _jsonb(val):
|
||||
"""Подготовить значение для JSONB-колонки."""
|
||||
import json
|
||||
return json.dumps(val, ensure_ascii=False, default=str) if val is not None else None
|
||||
|
||||
Reference in New Issue
Block a user