diff --git a/pyproject.toml b/pyproject.toml index ccf3360..ac5abfa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "vmr-http" -version = "0.7.2" +version = "0.8.0" description = "HTTP API for controlling Voicemeeter" readme = "README.md" authors = [{ name = "onyx-and-iris", email = "code@onyxandiris.online" }] diff --git a/src/vmr_http/app.py b/src/vmr_http/app.py index 4c6084b..80ec7d9 100644 --- a/src/vmr_http/app.py +++ b/src/vmr_http/app.py @@ -7,7 +7,7 @@ from fastapi import Depends, FastAPI, HTTPException from voicemeeterlib.error import CAPIError from .dependencies import get_voicemeeter_client -from .web import bus, strip +from .web import bus, command, strip @asynccontextmanager @@ -29,6 +29,7 @@ app = FastAPI( ) app.include_router(strip.router, prefix='/strip/{index}') app.include_router(bus.router, prefix='/bus/{index}') +app.include_router(command.router, prefix='/command') @app.get('/health') diff --git a/src/vmr_http/web/__init__.py b/src/vmr_http/web/__init__.py index cf93d25..af8e001 100644 --- a/src/vmr_http/web/__init__.py +++ b/src/vmr_http/web/__init__.py @@ -1,5 +1,5 @@ """API endpoints for controlling various Voicemeeter components.""" -from . import bus, strip +from . import bus, command, strip -__all__ = ['bus', 'strip'] +__all__ = ['bus', 'command', 'strip'] diff --git a/src/vmr_http/web/command/__init__.py b/src/vmr_http/web/command/__init__.py new file mode 100644 index 0000000..cb85071 --- /dev/null +++ b/src/vmr_http/web/command/__init__.py @@ -0,0 +1,5 @@ +"""module for command-related endpoints.""" + +from .command import router + +__all__ = ['router'] diff --git a/src/vmr_http/web/command/command.py b/src/vmr_http/web/command/command.py new file mode 100644 index 0000000..e4385da --- /dev/null +++ b/src/vmr_http/web/command/command.py @@ -0,0 +1,56 @@ +"""module for command related endpoints.""" + +from fastapi import APIRouter, Depends + +from vmr_http.dependencies import get_voicemeeter_client + +router = APIRouter(tags=['command']) + + +### +# Although these endpoints are technically modifying the state of the Voicemeeter application, +# they are commands that trigger an action rather than resource updates. +# Therefore, they are implemented as POST. +### + + +@router.post('/show') +async def show_command(voicemeeter=Depends(get_voicemeeter_client)): + """Show the Voicemeeter application.""" + voicemeeter.command.show() + return {'status': 'Voicemeeter shown'} + + +@router.post('/hide') +async def hide_command(voicemeeter=Depends(get_voicemeeter_client)): + """Hide the Voicemeeter application.""" + voicemeeter.command.hide() + return {'status': 'Voicemeeter hidden'} + + +@router.post('/shutdown') +async def shutdown_command(voicemeeter=Depends(get_voicemeeter_client)): + """Shutdown the Voicemeeter application.""" + voicemeeter.command.shutdown() + return {'status': 'Voicemeeter shutdown'} + + +@router.post('/restart') +async def restart_command(voicemeeter=Depends(get_voicemeeter_client)): + """Restart the Voicemeeter application.""" + voicemeeter.command.restart() + return {'status': 'Voicemeeter restarted'} + + +@router.post('/lock') +async def lock_command(voicemeeter=Depends(get_voicemeeter_client)): + """Lock the Voicemeeter application.""" + voicemeeter.command.lock = True + return {'status': 'Voicemeeter locked'} + + +@router.post('/unlock') +async def unlock_command(voicemeeter=Depends(get_voicemeeter_client)): + """Unlock the Voicemeeter application.""" + voicemeeter.command.lock = False + return {'status': 'Voicemeeter unlocked'} diff --git a/uv.lock b/uv.lock index 59401f1..d365f9c 100644 --- a/uv.lock +++ b/uv.lock @@ -1151,7 +1151,7 @@ wheels = [ [[package]] name = "vmr-http" -version = "0.7.2" +version = "0.8.0" source = { editable = "." } dependencies = [ { name = "fastapi" },