fix(upload): target image host API

This commit is contained in:
nyan404 committed 2026-08-21 14:26:16 +03:00
1 parent 12e9de9ba4
commit c3358f3f66
7 files changed
+55 -29

No files matched your search

+7 -4
View File
@@ -16,7 +16,7 @@ from .belki.history import CalculationStore
from .belki.applications import ApplicationError, ApplicationStore, validate_application
from .belki.google_sheets_export import GoogleSheetsExportService
from .belki.identity import IdentityDirectory
from .belki.image_host import ImageHostClient
from .belki.image_host import ImageHostClient, ImageHostError
ROOT = Path(__file__).resolve().parents[1]
@@ -229,9 +229,12 @@ class Handler(BaseHTTPRequestHandler):
raise ApiError("Не удалось прочитать изображение") from exc
if len(body) > 15 * 1024 * 1024:
raise ApiError("Файл слишком большой (максимум 15 МБ)")
url = ImageHostClient(api_url=os.getenv("BELKI_IMAGE_HOST_API_URL", "https://img.nyan404.ru")).upload_bytes(
body, str(payload.get("name", "screenshot.jpg")), str(payload.get("type", "image/jpeg"))
)
try:
url = ImageHostClient(api_url=os.getenv("BELKI_IMAGE_HOST_API_URL", "https://nyan.nyan404.ru")).upload_bytes(
body, str(payload.get("name", "screenshot.jpg")), str(payload.get("type", "image/jpeg"))
)
except ImageHostError as exc:
raise ApiError(f"Не удалось загрузить изображение: {exc}") from exc
if not url:
raise ApiError("Хранилище изображений не настроено")
self._json(200, {"url": url, "name": payload.get("name", "screenshot.jpg")})