fix(): Ajuste em renomear arquivos
This commit is contained in:
parent
4fd095aa93
commit
e11234433b
1 changed files with 2 additions and 21 deletions
|
|
@ -17,8 +17,6 @@ import os
|
|||
from pathlib import Path
|
||||
import uuid
|
||||
import datetime
|
||||
import mimetypes
|
||||
|
||||
|
||||
# Configuração da Chave AES
|
||||
DB_SETTINGS = get_database_settings()
|
||||
|
|
@ -34,23 +32,6 @@ GROUP_SIZE = int(
|
|||
UPLOAD_DIR = Path(os.environ.get("STORAGE", "./storage"))
|
||||
|
||||
|
||||
# Função utilitária para detectar tipo MIME e extensão de um base64
|
||||
def _get_file_extension_from_base64(base64_content: str) -> str:
|
||||
try:
|
||||
header, _ = (
|
||||
base64_content.split(",", 1)
|
||||
if "," in base64_content
|
||||
else ("", base64_content)
|
||||
)
|
||||
if "data:" in header and ";" in header:
|
||||
mime_type = header.split("data:")[1].split(";")[0]
|
||||
ext = mimetypes.guess_extension(mime_type)
|
||||
return ext or ".bin"
|
||||
except Exception:
|
||||
pass
|
||||
return ".bin" # fallback
|
||||
|
||||
|
||||
# Salva o arquivo Base64 em disco e retorna o caminho completo
|
||||
def _save_file_from_base64(base64_content: str, file_name: str, ato_id: int) -> str:
|
||||
"""
|
||||
|
|
@ -201,8 +182,8 @@ class SaveMultipleRepository:
|
|||
|
||||
# Se o nome do documento veio vazio, cria um nome dinâmico
|
||||
if not doc.nome_documento:
|
||||
# Detecta a extensão a partir do base64, se possível
|
||||
file_ext = _get_file_extension_from_base64(base64_content)
|
||||
# Define a extensão do arquivo - PDF
|
||||
file_ext = ".pdf"
|
||||
|
||||
# Cria um nome único com timestamp e UUID
|
||||
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue