refactor model service route registration
This commit is contained in:
@@ -2,15 +2,14 @@
|
||||
|
||||
from ..services.model_service import ModelService
|
||||
from .context import RouteContext
|
||||
from .helpers import register_service_post_route
|
||||
|
||||
|
||||
def register_civitai_search_routes(context: RouteContext):
|
||||
json_api_endpoint = context.get("json_api_endpoint")
|
||||
routes = context.get("routes")
|
||||
model_service = ModelService(context)
|
||||
|
||||
@routes.post("/model_resolver/civitai-search")
|
||||
@json_api_endpoint("civitai-search")
|
||||
async def civitai_search(request):
|
||||
"""Delegate model operation to the model service."""
|
||||
return await model_service.civitai_search(request)
|
||||
register_service_post_route(
|
||||
context,
|
||||
path="/model_resolver/civitai-search",
|
||||
error_prefix="civitai-search",
|
||||
operation=model_service.civitai_search,
|
||||
)
|
||||
|
||||
@@ -2,15 +2,14 @@
|
||||
|
||||
from ..services.model_service import ModelService
|
||||
from .context import RouteContext
|
||||
from .helpers import register_service_post_route
|
||||
|
||||
|
||||
def register_custom_url_routes(context: RouteContext):
|
||||
json_api_endpoint = context.get("json_api_endpoint")
|
||||
routes = context.get("routes")
|
||||
model_service = ModelService(context)
|
||||
|
||||
@routes.post("/model_resolver/custom-url")
|
||||
@json_api_endpoint("custom-url")
|
||||
async def custom_url(request):
|
||||
"""Delegate model operation to the model service."""
|
||||
return await model_service.custom_url(request)
|
||||
register_service_post_route(
|
||||
context,
|
||||
path="/model_resolver/custom-url",
|
||||
error_prefix="custom-url",
|
||||
operation=model_service.custom_url,
|
||||
)
|
||||
|
||||
@@ -5,6 +5,19 @@ import threading
|
||||
from functools import wraps
|
||||
|
||||
|
||||
def register_service_post_route(context, *, path, error_prefix, operation):
|
||||
"""Register a JSON POST route for a bound service operation."""
|
||||
json_api_endpoint = context.get("json_api_endpoint")
|
||||
routes = context.get("routes")
|
||||
|
||||
async def service_route(request):
|
||||
return await operation(request)
|
||||
|
||||
service_route.__name__ = getattr(operation, "__name__", "service_route")
|
||||
decorated_route = json_api_endpoint(error_prefix)(service_route)
|
||||
routes.post(path)(decorated_route)
|
||||
|
||||
|
||||
def create_route_helpers(web, logger, load_settings, hash_calculation_cancelled):
|
||||
"""Create route helpers bound to the current ComfyUI server context."""
|
||||
|
||||
|
||||
@@ -2,15 +2,14 @@
|
||||
|
||||
from ..services.model_service import ModelService
|
||||
from .context import RouteContext
|
||||
from .helpers import register_service_post_route
|
||||
|
||||
|
||||
def register_model_details_routes(context: RouteContext):
|
||||
json_api_endpoint = context.get("json_api_endpoint")
|
||||
routes = context.get("routes")
|
||||
model_service = ModelService(context)
|
||||
|
||||
@routes.post("/model_resolver/model-details")
|
||||
@json_api_endpoint("model-details")
|
||||
async def model_details(request):
|
||||
"""Delegate model operation to the model service."""
|
||||
return await model_service.model_details(request)
|
||||
register_service_post_route(
|
||||
context,
|
||||
path="/model_resolver/model-details",
|
||||
error_prefix="model-details",
|
||||
operation=model_service.model_details,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user