mirror of
https://github.com/krateng/maloja.git
synced 2025-07-09 03:04:07 -04:00
Added validate token endpoint to ListenBrainz API
This commit is contained in:
parent
0ee6e761da
commit
0bdc4654bf
@ -5,7 +5,7 @@ author = {
|
|||||||
"email":"maloja@krateng.dev",
|
"email":"maloja@krateng.dev",
|
||||||
"github": "krateng"
|
"github": "krateng"
|
||||||
}
|
}
|
||||||
version = 2,6,6
|
version = 2,6,7
|
||||||
versionstr = ".".join(str(n) for n in version)
|
versionstr = ".".join(str(n) for n in version)
|
||||||
links = {
|
links = {
|
||||||
"pypi":"malojaserver",
|
"pypi":"malojaserver",
|
||||||
|
@ -167,7 +167,8 @@ class GNUFM2(APIHandler):
|
|||||||
class LBrnz1(APIHandler):
|
class LBrnz1(APIHandler):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.methods = {
|
self.methods = {
|
||||||
"submit-listens":self.submit
|
"submit-listens":self.submit,
|
||||||
|
"validate-token":self.validate_token
|
||||||
}
|
}
|
||||||
self.errors = {
|
self.errors = {
|
||||||
BadAuthException:(401,{"code":401,"error":"You need to provide an Authorization header."}),
|
BadAuthException:(401,{"code":401,"error":"You need to provide an Authorization header."}),
|
||||||
@ -190,6 +191,7 @@ class LBrnz1(APIHandler):
|
|||||||
raise InvalidAuthException()
|
raise InvalidAuthException()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
log("scrobbling to listenbrainz, keys "+str(keys),module="debug")
|
||||||
if keys["listen_type"] in ["single","import"]:
|
if keys["listen_type"] in ["single","import"]:
|
||||||
payload = keys["payload"]
|
payload = keys["payload"]
|
||||||
for listen in payload:
|
for listen in payload:
|
||||||
@ -202,8 +204,18 @@ class LBrnz1(APIHandler):
|
|||||||
timestamp = int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp())
|
timestamp = int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp())
|
||||||
#database.createScrobble(artists,title,timestamp)
|
#database.createScrobble(artists,title,timestamp)
|
||||||
scrobbletrack(artiststr,titlestr,timestamp)
|
scrobbletrack(artiststr,titlestr,timestamp)
|
||||||
return 200,{"code":200,"status":"ok"}
|
return 200,{"code":200,"status":"ok"}
|
||||||
else:
|
else:
|
||||||
return 200,{"code":200,"status":"ok"}
|
return 200,{"code":200,"status":"ok"}
|
||||||
except:
|
except:
|
||||||
raise MalformedJSONException()
|
raise MalformedJSONException()
|
||||||
|
|
||||||
|
def validate_token(self,pathnodes,keys):
|
||||||
|
try:
|
||||||
|
token = keys.get("Authorization").replace("token ","").replace("Token ","").strip()
|
||||||
|
except:
|
||||||
|
raise BadAuthException()
|
||||||
|
if token not in database.allAPIkeys():
|
||||||
|
raise InvalidAuthException()
|
||||||
|
else:
|
||||||
|
return 200,{"code":200,"message":"Token valid.",valid:True}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user