diff --git a/tutordeck/server/app.py b/tutordeck/server/app.py index ab28210..47332eb 100644 --- a/tutordeck/server/app.py +++ b/tutordeck/server/app.py @@ -125,24 +125,13 @@ async def plugin_installed_list() -> str: @app.get("/plugin/") async def plugin(name: str) -> Response: - # TODO check that plugin exists + index_entry = tutorclient.Client.plugin_in_store(name) + if not index_entry: + return Response("Plugin not found", status=404) + seq_command_executed = request.args.get("seq_command_executed") - author = next( - ( - p.author.split("<")[0].strip() - for p in tutorclient.Client.plugins_in_store() - if p.name == name - ), - "", - ) - description = next( - ( - markdown(p.description) - for p in tutorclient.Client.plugins_in_store() - if p.name == name - ), - "", - ) + author = index_entry.author.split("<")[0].strip() + description = markdown(index_entry.description) rendered_template = await render_template( "plugin.html", plugin_name=name, diff --git a/tutordeck/server/tutorclient.py b/tutordeck/server/tutorclient.py index 6aa080f..fe43f8a 100644 --- a/tutordeck/server/tutorclient.py +++ b/tutordeck/server/tutorclient.py @@ -302,6 +302,13 @@ class CliPool: class Client: + @classmethod + def plugin_in_store(cls, name: str) -> tutor.plugins.indexes.IndexEntry | None: + for plugin in cls.plugins_in_store(): + if plugin.name == name: + return plugin + return None + @classmethod def plugins_in_store(cls) -> list[tutor.plugins.indexes.IndexEntry]: if not os.path.exists(tutor.plugins.indexes.Indexes.CACHE_PATH):