fix(upload): identify image host requests

This commit is contained in:
nyan404 committed 2026-08-21 14:48:04 +03:00
1 parent d6d90f6753
commit fd4e7b395f
4 files changed
+18 -4

No files matched your search

+1 -1
View File
@@ -28,7 +28,7 @@
- 2026-08-21: project-local frontend instructions include `frontend-craft`, `frontend-design`, and `ui-ux-pro-max`; use them together for UI work. - 2026-08-21: project-local frontend instructions include `frontend-craft`, `frontend-design`, and `ui-ux-pro-max`; use them together for UI work.
- 2026-08-21: `/belki` is the single public Belki workspace: both reports and its “Заявки” tab are open without a password. The old `/applications` route remains only as a direct legacy entry point. `/admin` is the only password-protected surface. - 2026-08-21: `/belki` is the single public Belki workspace: both reports and its “Заявки” tab are open without a password. The old `/applications` route remains only as a direct legacy entry point. `/admin` is the only password-protected surface.
- 2026-08-21: `/admin` now keeps a server-memory `HttpOnly` cookie session across page refreshes instead of retaining an admin password in the browser. Its authenticated WebSocket sends a refresh signal every 25 seconds; this needs the cwshed Nginx `/api/` Upgrade proxy settings. - 2026-08-21: `/admin` now keeps a server-memory `HttpOnly` cookie session across page refreshes instead of retaining an admin password in the browser. Its authenticated WebSocket sends a refresh signal every 25 seconds; this needs the cwshed Nginx `/api/` Upgrade proxy settings.
- 2026-08-21: `img.nyan404.ru` is only the image-host viewer/frontend; Belki uploads must use the image-host API `https://nyan.nyan404.ru`. Upload failures are converted to actionable API errors rather than a generic calculator 500. - 2026-08-21: `img.nyan404.ru` is only the image-host viewer/frontend; Belki uploads must use the image-host API `https://nyan.nyan404.ru`. The API rejects the default Python `urllib` user agent, so `ImageHostClient` identifies requests as `BelkiCalculator/1.0`. Upload failures are converted to actionable API errors rather than a generic calculator 500.
- 2026-08-21: Belki Python base image `reg.nyan404.ru/cwshed-clone/belki-base:py312-d6c42c4497ce` pins `pip==26.2.1`; CI upgrades to the same version before installing requirements. - 2026-08-21: Belki Python base image `reg.nyan404.ru/cwshed-clone/belki-base:py312-d6c42c4497ce` pins `pip==26.2.1`; CI upgrades to the same version before installing requirements.
# 2026-08-16 — несколько котят в прокачке # 2026-08-16 — несколько котят в прокачке
+5 -1
View File
@@ -97,7 +97,11 @@ class ImageHostClient:
f"{self.api_url}{path}", f"{self.api_url}{path}",
data=json.dumps(payload).encode("utf-8"), data=json.dumps(payload).encode("utf-8"),
method="POST", method="POST",
headers={"Content-Type": "application/json", "Accept": "application/json"}, headers={
"Content-Type": "application/json",
"Accept": "application/json",
"User-Agent": "BelkiCalculator/1.0 (+https://cat.nyan404.ru/belki)",
},
) )
try: try:
with urlopen(request, timeout=self.timeout) as response: with urlopen(request, timeout=self.timeout) as response:
+1 -1
View File
@@ -54,7 +54,7 @@
- 2026-08-16: corrected coaching payout direction for non-self-sufficient kittens. The escort receives the 1-per-5-minutes base rate or 1.5x for non-self-sufficient ЛУ; kitten points are not reported. Added a 30-minute regression case. - 2026-08-16: corrected coaching payout direction for non-self-sufficient kittens. The escort receives the 1-per-5-minutes base rate or 1.5x for non-self-sufficient ЛУ; kitten points are not reported. Added a 30-minute regression case.
- 2026-08-16: adopted `2026-08-16-krylany-calculator-rules.md`: Krylan is the Belka/escort role, kittens always receive 1 point per 5 minutes, non-self-sufficient ЛУ multiplies escort points by 1.5, and ZU forces self-sufficient calculation. - 2026-08-16: adopted `2026-08-16-krylany-calculator-rules.md`: Krylan is the Belka/escort role, kittens always receive 1 point per 5 minutes, non-self-sufficient ЛУ multiplies escort points by 1.5, and ZU forces self-sufficient calculation.
- 2026-08-17: aligned `web/calculator.html` status controls with the VK bot and shared domain: LU allows at most one non-self-sufficient kitten, while ZU forces all kittens to self-sufficient; extra-kitten status controls are synchronized and validated before submission. - 2026-08-17: aligned `web/calculator.html` status controls with the VK bot and shared domain: LU allows at most one non-self-sufficient kitten, while ZU forces all kittens to self-sufficient; extra-kitten status controls are synchronized and validated before submission.
- 2026-08-17: web-selected screenshots are sent through `/api/web/upload` to `BELKI_IMAGE_HOST_API_URL` (production API `https://nyan.nyan404.ru`, viewer `https://img.nyan404.ru`) and persisted as report attachments. - 2026-08-17: web-selected screenshots are sent through `/api/web/upload` to `BELKI_IMAGE_HOST_API_URL` (production API `https://nyan.nyan404.ru`, viewer `https://img.nyan404.ru`) and persisted as report attachments. The image-host API requires an explicit Belki `User-Agent`; the default Python `urllib` header is rejected with HTTP 403.
- 2026-08-21: added structured community applications for feathers, kitten, flying-squirrel, and curator roles across VK, `/applications`, and the top-level `/admin` "Заявки" tab; acceptance is a status transition, not a generated forum post. - 2026-08-21: added structured community applications for feathers, kitten, flying-squirrel, and curator roles across VK, `/applications`, and the top-level `/admin` "Заявки" tab; acceptance is a status transition, not a generated forum post.
- 2026-08-21: added a disabled durable Google Sheets export outbox for application-created and application-accepted events; no external request is attempted until an approved Apps Script URL and `BELKI_GOOGLE_EXPORT_ENABLED=1` are configured. - 2026-08-21: added a disabled durable Google Sheets export outbox for application-created and application-accepted events; no external request is attempted until an approved Apps Script URL and `BELKI_GOOGLE_EXPORT_ENABLED=1` are configured.
# Обновление 2026-08-16: несколько котят # Обновление 2026-08-16: несколько котят
+11 -1
View File
@@ -1,10 +1,20 @@
import unittest import unittest
from unittest.mock import patch from unittest.mock import MagicMock, patch
from app.belki.image_host import ImageHostClient, ImageHostError from app.belki.image_host import ImageHostClient, ImageHostError
class ImageHostClientTests(unittest.TestCase): class ImageHostClientTests(unittest.TestCase):
def test_initiate_identifies_the_belki_client(self) -> None:
client = ImageHostClient(api_url="https://api.example.test")
response = MagicMock()
response.__enter__.return_value = response
with patch("app.belki.image_host.urlopen", return_value=response) as urlopen:
with patch("app.belki.image_host.json.load", return_value={"files": []}):
client._request_json("/api/uploads/initiate", {"files": []})
request = urlopen.call_args.args[0]
self.assertEqual(request.get_header("User-agent"), "BelkiCalculator/1.0 (+https://cat.nyan404.ru/belki)")
def test_upload_wraps_presigned_put_failure(self) -> None: def test_upload_wraps_presigned_put_failure(self) -> None:
client = ImageHostClient(api_url="https://api.example.test") client = ImageHostClient(api_url="https://api.example.test")
with patch.object(client, "_request_json", return_value={"files": [{"uploadUrl": "https://storage.example.test/upload"}]}): with patch.object(client, "_request_json", return_value={"files": [{"uploadUrl": "https://storage.example.test/upload"}]}):