1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

API improvements

This commit is contained in:
Krateng 2020-10-31 19:57:49 +01:00
parent ac29f9728e
commit e70cb3e037
3 changed files with 17 additions and 10 deletions

View File

@ -5,7 +5,7 @@ author = {
"email":"maloja@krateng.dev",
"github": "krateng"
}
version = 2,10,1
version = 2,10,2
versionstr = ".".join(str(n) for n in version)
links = {
"pypi":"malojaserver",

View File

@ -4,7 +4,7 @@ from .audioscrobbler_legacy import AudioscrobblerLegacy
from .listenbrainz import Listenbrainz
import copy
from bottle import redirect, request
from bottle import redirect, request, response
from urllib.parse import urlencode
native_apis = [
@ -40,3 +40,10 @@ def init_apis(server):
server.post(altpath_empty)(alias_api)
server.get(altpath_empty_cl)(alias_api)
server.post(altpath_empty_cl)(alias_api)
def invalid_api(pth):
response.status = 404
return {"error":"Invalid API"}
server.get("/apis/<pth:path>")(invalid_api)
server.post("/apis/<pth:path>")(invalid_api)

View File

@ -20,11 +20,11 @@ class AudioscrobblerLegacy(APIHandler):
"scrobble":self.submit_scrobble
}
self.errors = {
BadAuthException:(200,"BADAUTH"),
InvalidAuthException:(200,"BADAUTH"),
InvalidMethodException:(200,"FAILED"),
InvalidSessionKey:(200,"BADSESSION"),
ScrobblingException:(500,"FAILED")
BadAuthException:(403,"BADAUTH\n"),
InvalidAuthException:(403,"BADAUTH\n"),
InvalidMethodException:(400,"FAILED\n"),
InvalidSessionKey:(403,"BADSESSION\n"),
ScrobblingException:(500,"FAILED\n")
}
def get_method(self,pathnodes,keys):
@ -61,7 +61,7 @@ class AudioscrobblerLegacy(APIHandler):
if keys.get("s") is None or keys.get("s") not in self.mobile_sessions:
raise InvalidSessionKey()
else:
return "OK"
return 200,"OK\n"
def submit_scrobble(self,pathnodes,keys):
if keys.get("s") is None or keys.get("s") not in self.mobile_sessions:
@ -80,8 +80,8 @@ class AudioscrobblerLegacy(APIHandler):
#database.createScrobble(artists,title,timestamp)
self.scrobble(artiststr,titlestr,time=timestamp)
else:
return 200,"OK"
return 200,"OK"
return 200,"OK\n"
return 200,"OK\n"
import hashlib