Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uninstall library APIの追加 #692

Merged
merged 3 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,26 @@ async def install_library(library_uuid: str, request: Request):
)
return Response(status_code=204)

@app.post(
"/uninstall_library/{library_uuid}",
status_code=204,
tags=["音声ライブラリ管理"],
)
def uninstall_library(library_uuid: str):
"""
音声ライブラリをアンインストールします。

Parameters
----------
library_uuid: str
音声ライブラリのID
"""
manifest = engine_manifest_loader.load_manifest()
if not manifest.supported_features.manage_library:
raise HTTPException(status_code=404, detail="この機能は実装されていません")
library_manager.uninstall_library(library_uuid)
return Response(status_code=204)

@app.post("/initialize_speaker", status_code=204, tags=["その他"])
def initialize_speaker(
speaker: int,
Expand Down
14 changes: 14 additions & 0 deletions voicevox_engine/downloadable_library.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import base64
import json
import os
import zipfile
from io import BytesIO
from pathlib import Path
Expand Down Expand Up @@ -86,3 +87,16 @@ def install_library(self, library_id: str, file: BytesIO):

zf.extractall(library_dir)
return library_dir

def uninstall_library(self, library_id: str):
installed_libraries = self.installed_libraries()
if library_id not in installed_libraries.keys():
raise HTTPException(status_code=404, detail="指定された音声ライブラリはインストールされていません。")
Copy link
Member

@Hiroshiba Hiroshiba Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最近ログやエラーはそこそこ詳細に書いておくと利便性が上がることに気づきました。
音声ライブラリーのIDも返してあげるとかどうでしょう。(あまりこだわりはないです!)

Suggested change
raise HTTPException(status_code=404, detail="指定された音声ライブラリはインストールされていません。")
raise HTTPException(status_code=404, detail=f"指定された音声ライブラリ ${library_id} はインストールされていません。")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

確かにそのほうがいいと思います!
ちょっと他の音声ライブラリ操作関連でも同じような修正をするべきだと思うので、そのためのPRを別で作る方向で解決しようかなと思います...!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

たしかに、了解です!


if not installed_libraries[library_id]["uninstallable"]:
raise HTTPException(status_code=403, detail="指定された音声ライブラリはアンインストールできません。")

try:
os.remove(self.library_root_dir / library_id)
y-chan marked this conversation as resolved.
Show resolved Hide resolved
except Exception:
raise HTTPException(status_code=500, detail="ライブラリの削除に失敗しました。")