Commit inicial - upload de todos os arquivos da pasta

This commit is contained in:
2026-07-24 23:55:21 -03:00
commit 9d4d395881
88 changed files with 9484 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
"""Helpers de armazenamento seguro dos arquivos enviados."""
from __future__ import annotations
import os
import re
from pathlib import Path
from .config import get_settings
def safe_original_name(name: str) -> str:
return os.path.basename(name or "").replace("\x00", "") or "upload"
def unique_storage_name(original: str) -> str:
upload_dir = get_settings().upload_dir
stem = re.sub(r"[^A-Za-z0-9_.-]+", "_", Path(original).stem).strip("._") or "upload"
suffix = Path(original).suffix.lower()
index = 0
while True:
candidate = f"{stem}{'-' + str(index) if index else ''}{suffix}"
if not (upload_dir / candidate).exists():
return candidate
index += 1
def money(value: object) -> str:
try:
amount = float(value or 0)
except (TypeError, ValueError):
amount = 0.0
return f"R$ {amount:,.2f}".replace(",", "X").replace(".", ",").replace("X", ".")