Rename rest methods, edit /load input from body to form argument, add error handling for api input
This commit is contained in:
parent
226e807f24
commit
bca1ec78b3
@ -31,6 +31,8 @@ def response_text(func):
|
|||||||
return response.text(body)
|
return response.text(body)
|
||||||
return newfunc
|
return newfunc
|
||||||
|
|
||||||
|
class APIError(Exception): pass
|
||||||
|
|
||||||
#routes:
|
#routes:
|
||||||
@bp.get("/")
|
@bp.get("/")
|
||||||
@response_text
|
@response_text
|
||||||
@ -40,34 +42,38 @@ async def root(request):
|
|||||||
@bp.post("/load")
|
@bp.post("/load")
|
||||||
@response_json
|
@response_json
|
||||||
async def loadfile(request, mpv_control):
|
async def loadfile(request, mpv_control):
|
||||||
if "source" not in request.json:
|
if "path" not in request.form:
|
||||||
return {"error", "no param \"source\""}
|
raise APIError("no form argument \"path\" provided")
|
||||||
success = await mpv_control.loadfile(request.json["source"])
|
success = await mpv_control.loadfile(request.form["path"][0])
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
@bp.get("/play")
|
@bp.get("/play")
|
||||||
@response_json
|
@response_json
|
||||||
async def get_play(request, mpv_control):
|
async def play_get(request, mpv_control):
|
||||||
value = await mpv_control.pause_get() == False
|
value = await mpv_control.pause_get() == False
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
@bp.post("/play")
|
@bp.post("/play")
|
||||||
@response_json
|
@response_json
|
||||||
async def set_play(request, mpv_control):
|
async def play_set(request, mpv_control):
|
||||||
success = await request.app.config["mpv_control"] \
|
if "play" not in request.form:
|
||||||
|
raise APIError("No form argument \"play\" provided")
|
||||||
|
success = await mpv_control \
|
||||||
.pause_set(request.form["play"][0] not in ["true", "1"])
|
.pause_set(request.form["play"][0] not in ["true", "1"])
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
@bp.get("/volume")
|
@bp.get("/volume")
|
||||||
@response_json
|
@response_json
|
||||||
async def get_volume(request, mpv_control):
|
async def volume_get(request, mpv_control):
|
||||||
value = await mpv_control.volume_get()
|
value = await mpv_control.volume_get()
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
@bp.post("/volume")
|
@bp.post("/volume")
|
||||||
@response_json
|
@response_json
|
||||||
async def set_volume(request, mpv_control):
|
async def volume_set(request, mpv_control):
|
||||||
success = await request.app.config["mpv_control"] \
|
if "volume" not in request.form:
|
||||||
|
raise APIError("No form argument \"volume\" provided")
|
||||||
|
success = await mpv_control \
|
||||||
.volume_set(int(request.form["volume"][0]))
|
.volume_set(int(request.form["volume"][0]))
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
@ -97,7 +103,7 @@ async def noe(request, mpv_control):
|
|||||||
|
|
||||||
@bp.get("/playlist")
|
@bp.get("/playlist")
|
||||||
@response_json
|
@response_json
|
||||||
async def noe(request, mpv_control):
|
async def playlist_get(request, mpv_control):
|
||||||
value = await mpv_control.playlist_get()
|
value = await mpv_control.playlist_get()
|
||||||
for i, v in enumerate(value):
|
for i, v in enumerate(value):
|
||||||
pass
|
pass
|
||||||
@ -105,13 +111,13 @@ async def noe(request, mpv_control):
|
|||||||
|
|
||||||
@bp.post("/playlist/next")
|
@bp.post("/playlist/next")
|
||||||
@response_json
|
@response_json
|
||||||
async def noe(request, mpv_control):
|
async def playlist_next(request, mpv_control):
|
||||||
success = await mpv_control.playlist_next()
|
success = await mpv_control.playlist_next()
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
@bp.post("/playlist/previous")
|
@bp.post("/playlist/previous")
|
||||||
@response_json
|
@response_json
|
||||||
async def noe(request, mpv_control):
|
async def playlist_previous(request, mpv_control):
|
||||||
success = await mpv_control.playlist_prev()
|
success = await mpv_control.playlist_prev()
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user