Files
wehub-resource-sync 8f10353f0c
CI / lint (push) Has been cancelled
CI / js-syntax (push) Successful in 10m24s
CI / deps-audit (push) Has been cancelled
CI / test (push) Failing after 24m55s
CI / sast-bandit (push) Failing after 11m13s
CI / trivy (push) Failing after 9m32s
Docker Publish / build-and-push (push) Failing after 34m3s
chore: import upstream snapshot with attribution
2026-07-13 12:32:09 +08:00

26 lines
657 B
Python

from __future__ import annotations
import io
import segno
from fastapi import APIRouter, HTTPException
from fastapi.responses import Response
router = APIRouter()
_MAX_LEN = 500
@router.get("/qr")
def get_qr(url: str) -> Response:
if not url or len(url) > _MAX_LEN:
raise HTTPException(status_code=422, detail="url required (max 500 chars)")
qr = segno.make_qr(url, error="m")
buf = io.BytesIO()
qr.save(buf, kind="svg", scale=5, border=2, dark="#1a1206", light="#ffffff")
return Response(
content=buf.getvalue(),
media_type="image/svg+xml",
headers={"Cache-Control": "public, max-age=3600"},
)