24 lines
770 B
Python
24 lines
770 B
Python
"""Showcase API: scalable random sample of images."""
|
|
|
|
from quart import Blueprint, jsonify, request
|
|
|
|
from ..extensions import get_session
|
|
from ..services.showcase_service import ShowcaseService
|
|
|
|
showcase_bp = Blueprint("showcase", __name__, url_prefix="/api/showcase")
|
|
|
|
|
|
@showcase_bp.route("", methods=["GET"])
|
|
async def random_showcase():
|
|
try:
|
|
limit = int(request.args.get("limit", "60"))
|
|
except ValueError:
|
|
return jsonify({"error": "limit must be an integer"}), 400
|
|
async with get_session() as session:
|
|
svc = ShowcaseService(session)
|
|
try:
|
|
images = await svc.random_sample(limit=limit)
|
|
except ValueError as exc:
|
|
return jsonify({"error": str(exc)}), 400
|
|
return jsonify({"images": images})
|