mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-01-11 23:00:51 +08:00
44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
class _RoutesWrapper:
|
|
def __init__(self):
|
|
self.routes = []
|
|
|
|
def _decorator_factory(self, method):
|
|
def decorator(path):
|
|
def wrapper(func):
|
|
from comfy.cmd.server import PromptServer
|
|
if PromptServer.instance is not None:
|
|
getattr(PromptServer.instance.routes, method)(path)(func)
|
|
self.routes.append((method, path, func))
|
|
return func
|
|
|
|
return wrapper
|
|
|
|
return decorator
|
|
|
|
def get(self, path):
|
|
return self._decorator_factory('get')(path)
|
|
|
|
def post(self, path):
|
|
return self._decorator_factory('post')(path)
|
|
|
|
def put(self, path):
|
|
return self._decorator_factory('put')(path)
|
|
|
|
def delete(self, path):
|
|
return self._decorator_factory('delete')(path)
|
|
|
|
def patch(self, path):
|
|
return self._decorator_factory('patch')(path)
|
|
|
|
def head(self, path):
|
|
return self._decorator_factory('head')(path)
|
|
|
|
def options(self, path):
|
|
return self._decorator_factory('options')(path)
|
|
|
|
def route(self, method, path):
|
|
return self._decorator_factory(method.lower())(path)
|
|
|
|
|
|
prompt_server_instance_routes = _RoutesWrapper()
|