mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03: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",
|
||||
"github": "krateng"
|
||||
}
|
||||
version = 2,6,6
|
||||
version = 2,6,7
|
||||
versionstr = ".".join(str(n) for n in version)
|
||||
links = {
|
||||
"pypi":"malojaserver",
|
||||
|
@ -167,7 +167,8 @@ class GNUFM2(APIHandler):
|
||||
class LBrnz1(APIHandler):
|
||||
def __init__(self):
|
||||
self.methods = {
|
||||
"submit-listens":self.submit
|
||||
"submit-listens":self.submit,
|
||||
"validate-token":self.validate_token
|
||||
}
|
||||
self.errors = {
|
||||
BadAuthException:(401,{"code":401,"error":"You need to provide an Authorization header."}),
|
||||
@ -190,6 +191,7 @@ class LBrnz1(APIHandler):
|
||||
raise InvalidAuthException()
|
||||
|
||||
try:
|
||||
log("scrobbling to listenbrainz, keys "+str(keys),module="debug")
|
||||
if keys["listen_type"] in ["single","import"]:
|
||||
payload = keys["payload"]
|
||||
for listen in payload:
|
||||
@ -202,8 +204,18 @@ class LBrnz1(APIHandler):
|
||||
timestamp = int(datetime.datetime.now(tz=datetime.timezone.utc).timestamp())
|
||||
#database.createScrobble(artists,title,timestamp)
|
||||
scrobbletrack(artiststr,titlestr,timestamp)
|
||||
return 200,{"code":200,"status":"ok"}
|
||||
return 200,{"code":200,"status":"ok"}
|
||||
else:
|
||||
return 200,{"code":200,"status":"ok"}
|
||||
except:
|
||||
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…
Reference in New Issue
Block a user