mirror of
https://github.com/tcsenpai/pensieve.git
synced 2025-06-06 03:05:25 +00:00
feat(plugin): bind lib and plugin
This commit is contained in:
parent
64dd3a50f1
commit
649ed434c7
@ -273,5 +273,22 @@ def create(name: str, webhook_url: str, description: str = ""):
|
||||
print(f"Failed to create plugin: {response.status_code} - {response.text}")
|
||||
|
||||
|
||||
@plugin_app.command("bind")
|
||||
def bind(
|
||||
library_id: int = typer.Option(..., "--lib", help="ID of the library"),
|
||||
plugin_id: int = typer.Option(..., "--plugin", help="ID of the plugin"),
|
||||
):
|
||||
response = httpx.post(
|
||||
f"{BASE_URL}/libraries/{library_id}/plugins",
|
||||
json={"plugin_id": plugin_id},
|
||||
)
|
||||
if 200 <= response.status_code < 300:
|
||||
print("Plugin bound to library successfully")
|
||||
else:
|
||||
print(
|
||||
f"Failed to bind plugin to library: {response.status_code} - {response.text}"
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app()
|
||||
|
@ -211,6 +211,12 @@ def list_plugins(db: Session = Depends(get_db)):
|
||||
def add_library_plugin(
|
||||
library_id: int, new_plugin: NewLibraryPluginParam, db: Session = Depends(get_db)
|
||||
):
|
||||
library = crud.get_library_by_id(library_id, db)
|
||||
if any(plugin.id == new_plugin.plugin_id for plugin in library.plugins):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="Plugin already exists in the library",
|
||||
)
|
||||
crud.add_plugin_to_library(library_id, new_plugin.plugin_id, db)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user