from __future__ import annotations from fastapi import APIRouter, Request from app.api.media import execute_operation from app.core.response import SuccessResponse from app.operations.concat import image_sequence, image_slideshow, image_to_video from app.operations.convert import convert_image from app.operations.crop import crop_image from app.operations.resize import resize_image from app.operations.watermark import overlay_image, watermark_image from app.services.media_service import Operation router = APIRouter(prefix="/v1/image", tags=["image"]) def operation_route(path: str, name: str, operation: Operation) -> None: async def endpoint(request: Request) -> SuccessResponse: return await execute_operation(request, name, operation) endpoint.__name__ = name.replace(".", "_") router.add_api_route( path, endpoint, methods=["POST"], response_model=SuccessResponse, name=name ) operation_route("/resize", "image.resize", resize_image) operation_route("/crop", "image.crop", crop_image) operation_route("/convert", "image.convert", convert_image) operation_route("/slideshow", "image.slideshow", image_slideshow) operation_route("/sequence", "image.sequence", image_sequence) operation_route("/video", "image.video", image_to_video) operation_route("/watermark", "image.watermark", watermark_image) operation_route("/overlay", "image.overlay", overlay_image)