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
|
from .listenbrainz import Listenbrainz
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
from bottle import redirect, request
|
||||||
|
from urllib.parse import urlencode
|
||||||
|
|
||||||
|
native_apis = [
|
||||||
apis = {
|
native_v1.api
|
||||||
"mlj_1":native_v1.api,
|
]
|
||||||
"listenbrainz/1":Listenbrainz().nimrodelapi,
|
thirdparty_apis = [
|
||||||
"audioscrobbler/2.0":Audioscrobbler().nimrodelapi
|
Listenbrainz(),
|
||||||
}
|
Audioscrobbler()
|
||||||
|
]
|
||||||
aliases = {
|
|
||||||
"native_1":"mlj_1"
|
|
||||||
}
|
|
||||||
|
|
||||||
def init_apis(server):
|
def init_apis(server):
|
||||||
|
for api in native_apis:
|
||||||
|
api.mount(server=server,path="apis/"+api.__apipath__)
|
||||||
|
|
||||||
for api in apis:
|
for api in thirdparty_apis:
|
||||||
apis[api].mount(server=server,path="apis/"+api)
|
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):
|
class Audioscrobbler(APIHandler):
|
||||||
__apiname__ = "Audioscrobbler"
|
__apiname__ = "Audioscrobbler"
|
||||||
__doclink__ = "https://www.last.fm/api/scrobbling"
|
__doclink__ = "https://www.last.fm/api/scrobbling"
|
||||||
|
__aliases__ = [
|
||||||
|
"audioscrobbler/2.0",
|
||||||
|
"gnufm/2.0",
|
||||||
|
"gnukebox/2.0",
|
||||||
|
]
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
|
|
||||||
|
@ -7,6 +7,10 @@ import datetime
|
|||||||
class Listenbrainz(APIHandler):
|
class Listenbrainz(APIHandler):
|
||||||
__apiname__ = "Listenbrainz"
|
__apiname__ = "Listenbrainz"
|
||||||
__doclink__ = "https://listenbrainz.readthedocs.io/en/production/"
|
__doclink__ = "https://listenbrainz.readthedocs.io/en/production/"
|
||||||
|
__aliases__ = [
|
||||||
|
"listenbrainz/1",
|
||||||
|
"lbrnz/1"
|
||||||
|
]
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
self.methods = {
|
self.methods = {
|
||||||
|
@ -12,6 +12,7 @@ from nimrodel import Multi
|
|||||||
|
|
||||||
|
|
||||||
api = API(delay=True)
|
api = API(delay=True)
|
||||||
|
api.__apipath__ = "mlj_1"
|
||||||
|
|
||||||
|
|
||||||
@api.get("test")
|
@api.get("test")
|
||||||
|
@ -59,9 +59,6 @@ auth.authapi.mount(server=webserver)
|
|||||||
from .apis import init_apis
|
from .apis import init_apis
|
||||||
init_apis(webserver)
|
init_apis(webserver)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# redirects for backwards compatibility
|
# redirects for backwards compatibility
|
||||||
@webserver.get("/api/s/<pth:path>")
|
@webserver.get("/api/s/<pth:path>")
|
||||||
@webserver.post("/api/s/<pth:path>")
|
@webserver.post("/api/s/<pth:path>")
|
||||||
|
Loading…
Reference in New Issue
Block a user