caelum0x d56639a594
Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

93 lines
3.9 KiB
Python

"""Anonymous reel preview HTTP routes — the public one is no-sign-in required.
POST /public/reel-preview real preview for a pasted link (public)
POST /reel-preview/claim claim a preview into the caller's account
Menivor Growth: paste an App Store/Play link OR a plain website link on the
landing page and see a real opening hook plus a real frame from the page
*before* any sign-up, then "sign up to get your 3 reels." Rate-limited per
caller IP (there is no account to scope it to yet) and, once an operator
configures a real Cloudflare Turnstile widget, gated on a human-check token
too (see ``app.services.turnstile`` -- soft no-op until then). The render
itself always stays behind sign-up; this never creates a job.
"""
from __future__ import annotations
from fastapi import Request
from pydantic import BaseModel, ConfigDict, Field
from app.controllers import base
from app.controllers.v1.base import new_router
from app.core.api_dependencies import get_session, require_database, resolve_principal
from app.domains.reel_preview.service import ReelPreviewError, build_preview, claim_preview
from app.models.exception import HttpException
from app.services.abuse.device_attest import client_ip
from app.services.ratelimit import enforce_rate_limit
from app.services.turnstile import verify_turnstile
from app.utils import utils
router = new_router()
# Homepage-scale traffic (this preview is wired into the main paste box, not
# just a single acquisition page), so this is tighter than
# `appaudit`/`applisting`'s 20/hour: bounds real cost (one page/listing fetch
# + one LLM hook-write per NEW url_hash; a cache hit is nearly free but still
# counts here to bound raw request volume too).
_RATE_LIMIT = 8
_RATE_WINDOW_S = 3600
_CLAIM_RATE_LIMIT = 20
_CLAIM_RATE_WINDOW_S = 3600
class ReelPreviewBody(BaseModel):
model_config = ConfigDict(extra="forbid")
url: str = Field(..., min_length=4, max_length=2048)
# Cloudflare Turnstile token (`cf-turnstile-response`); required only
# once an operator has set TURNSTILE_SECRET_KEY (see app.services.turnstile).
turnstile_token: str = Field(default="", max_length=2048)
class ClaimBody(BaseModel):
model_config = ConfigDict(extra="forbid")
preview_id: str = Field(..., min_length=1, max_length=36)
def _error(request_id: str, status_code: int, message: str) -> HttpException:
return HttpException(task_id=request_id, status_code=status_code, message=f"{request_id}: {message}")
@router.post("/public/reel-preview", summary="Free reel preview for a pasted link (public, no sign-in)")
def reel_preview(request: Request, body: ReelPreviewBody):
request_id = base.get_task_id(request)
require_database(request_id)
enforce_rate_limit(request, "reelpreview:create", limit=_RATE_LIMIT, window_s=_RATE_WINDOW_S)
ip = client_ip(request)
if not verify_turnstile(body.turnstile_token, ip):
raise _error(request_id, 403, "human verification failed -- please try again")
with get_session() as session:
try:
data = build_preview(body.url.strip(), session=session, remote_ip=ip)
except ReelPreviewError as exc:
raise _error(request_id, exc.status_code, exc.message) from exc
return utils.get_response(200, data)
@router.post("/reel-preview/claim", summary="Claim an anonymous reel preview into the signed-in account")
def reel_preview_claim(request: Request, body: ClaimBody):
request_id = base.get_task_id(request)
require_database(request_id)
with get_session() as session:
user = resolve_principal(request, session, request_id)
user_id = str(getattr(user, "id", "") or "")
enforce_rate_limit(request, f"reelpreview:claim:{user_id}", limit=_CLAIM_RATE_LIMIT, window_s=_CLAIM_RATE_WINDOW_S)
data = claim_preview(body.preview_id.strip(), user_id, session=session)
if data is None:
raise _error(request_id, 404, "preview not found")
return utils.get_response(200, data)
__all__ = ["router"]