mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Implemented aliases
This commit is contained in:
parent
879b3cf170
commit
dad75dbbc2
@ -3,19 +3,38 @@ from .audioscrobbler import Audioscrobbler
|
||||
from .listenbrainz import Listenbrainz
|
||||
|
||||
import copy
|
||||
from bottle import redirect, request
|
||||
from urllib.parse import urlencode
|
||||
|
||||
|
||||
apis = {
|
||||
"mlj_1":native_v1.api,
|
||||
"listenbrainz/1":Listenbrainz().nimrodelapi,
|
||||
"audioscrobbler/2.0":Audioscrobbler().nimrodelapi
|
||||
}
|
||||
|
||||
aliases = {
|
||||
"native_1":"mlj_1"
|
||||
}
|
||||
native_apis = [
|
||||
native_v1.api
|
||||
]
|
||||
thirdparty_apis = [
|
||||
Listenbrainz(),
|
||||
Audioscrobbler()
|
||||
]
|
||||
|
||||
def init_apis(server):
|
||||
for api in native_apis:
|
||||
api.mount(server=server,path="apis/"+api.__apipath__)
|
||||
|
||||
for api in apis:
|
||||
apis[api].mount(server=server,path="apis/"+api)
|
||||
for api in thirdparty_apis:
|
||||
aliases = api.__aliases__
|
||||
canonical = aliases[0]
|
||||
api.nimrodelapi.mount(server=server,path="apis/" + canonical)
|
||||
|
||||
# redirects
|
||||
for alias in aliases[1:]:
|
||||
altpath = "/apis/" + alias + "/<pth:path>"
|
||||
altpath_empty = "/apis/" + alias
|
||||
altpath_empty_cl = "/apis/" + alias + "/"
|
||||
|
||||
def alias_api(pth=""):
|
||||
redirect("/apis/" + canonical + "/" + pth + "?" + urlencode(request.query))
|
||||
|
||||
server.get(altpath)(alias_api)
|
||||
server.post(altpath)(alias_api)
|
||||
server.get(altpath_empty)(alias_api)
|
||||
server.post(altpath_empty)(alias_api)
|
||||
server.get(altpath_empty_cl)(alias_api)
|
||||
server.post(altpath_empty_cl)(alias_api)
|
||||
|
@ -5,6 +5,11 @@ from .. import database
|
||||
class Audioscrobbler(APIHandler):
|
||||
__apiname__ = "Audioscrobbler"
|
||||
__doclink__ = "https://www.last.fm/api/scrobbling"
|
||||
__aliases__ = [
|
||||
"audioscrobbler/2.0",
|
||||
"gnufm/2.0",
|
||||
"gnukebox/2.0",
|
||||
]
|
||||
|
||||
def init(self):
|
||||
|
||||
|
@ -7,6 +7,10 @@ import datetime
|
||||
class Listenbrainz(APIHandler):
|
||||
__apiname__ = "Listenbrainz"
|
||||
__doclink__ = "https://listenbrainz.readthedocs.io/en/production/"
|
||||
__aliases__ = [
|
||||
"listenbrainz/1",
|
||||
"lbrnz/1"
|
||||
]
|
||||
|
||||
def init(self):
|
||||
self.methods = {
|
||||
|
@ -12,6 +12,7 @@ from nimrodel import Multi
|
||||
|
||||
|
||||
api = API(delay=True)
|
||||
api.__apipath__ = "mlj_1"
|
||||
|
||||
|
||||
@api.get("test")
|
||||
|
@ -59,9 +59,6 @@ auth.authapi.mount(server=webserver)
|
||||
from .apis import init_apis
|
||||
init_apis(webserver)
|
||||
|
||||
|
||||
|
||||
|
||||
# redirects for backwards compatibility
|
||||
@webserver.get("/api/s/<pth:path>")
|
||||
@webserver.post("/api/s/<pth:path>")
|
||||
|
Loading…
Reference in New Issue
Block a user