From 3369fb27df6c1badd39bcb59b3f71c61a47d3d91 Mon Sep 17 00:00:00 2001 From: SpenserCai Date: Fri, 25 Aug 2023 22:15:35 +0800 Subject: [PATCH] support installed extensions list api --- modules/api/api.py | 20 ++++++++++++++++++++ modules/api/models.py | 9 +++++++++ 2 files changed, 29 insertions(+) diff --git a/modules/api/api.py b/modules/api/api.py index e6edffe71..0bcf54977 100644 --- a/modules/api/api.py +++ b/modules/api/api.py @@ -243,6 +243,7 @@ class Api: self.add_api_route("/sdapi/v1/reload-checkpoint", self.reloadapi, methods=["POST"]) self.add_api_route("/sdapi/v1/scripts", self.get_scripts_list, methods=["GET"], response_model=models.ScriptsList) self.add_api_route("/sdapi/v1/script-info", self.get_script_info, methods=["GET"], response_model=List[models.ScriptInfo]) + self.add_api_route("/sdapi/v1/extensions", self.get_extensions_list, methods=["GET"], response_model=List[models.ExtensionItem]) if shared.cmd_opts.api_server_stop: self.add_api_route("/sdapi/v1/server-kill", self.kill_webui, methods=["POST"]) @@ -769,6 +770,25 @@ class Api: except Exception as err: cuda = {'error': f'{err}'} return models.MemoryResponse(ram=ram, cuda=cuda) + + def get_extensions_list(self): + from modules import extensions + extensions.list_extensions() + ext_list = [] + for ext in extensions.extensions: + ext: extensions.Extension + ext.read_info_from_repo() + if ext.remote is not None: + ext_list.append({ + "name": ext.name, + "remote": ext.remote, + "branch": ext.branch, + "commit_hash":ext.commit_hash, + "commit_date":ext.commit_date, + "version":ext.version, + "enabled":ext.enabled + }) + return ext_list def launch(self, server_name, port, root_path): self.app.include_router(self.router) diff --git a/modules/api/models.py b/modules/api/models.py index 6a574771c..731ab03da 100644 --- a/modules/api/models.py +++ b/modules/api/models.py @@ -311,3 +311,12 @@ class ScriptInfo(BaseModel): is_alwayson: bool = Field(default=None, title="IsAlwayson", description="Flag specifying whether this script is an alwayson script") is_img2img: bool = Field(default=None, title="IsImg2img", description="Flag specifying whether this script is an img2img script") args: List[ScriptArg] = Field(title="Arguments", description="List of script's arguments") + +class ExtensionItem(BaseModel): + name: str = Field(title="Name", description="Extension name") + remote: str = Field(title="Remote", description="Extension Repository URL") + branch: str = Field(title="Branch", description="Extension Repository Branch") + commit_hash: str = Field(title="Commit Hash", description="Extension Repository Commit Hash") + version: str = Field(title="Version", description="Extension Version") + commit_date: str = Field(title="Commit Date", description="Extension Repository Commit Date") + enabled: bool = Field(title="Enabled", description="Flag specifying whether this extension is enabled")