mirror of
https://github.com/krateng/maloja.git
synced 2025-07-31 14:33:50 -04:00
Added makeshift pagination to api scrobbles list, fixes GH-52
This commit is contained in:
parent
b84712ef22
commit
755567549c
@ -52,7 +52,7 @@ def server_info():
|
|||||||
|
|
||||||
@api.get("scrobbles")
|
@api.get("scrobbles")
|
||||||
def get_scrobbles_external(**keys):
|
def get_scrobbles_external(**keys):
|
||||||
k_filter, k_time, _, k_amount, _ = uri_to_internal(keys)
|
k_filter, k_time, _, k_amount, _ = uri_to_internal(keys,api=True)
|
||||||
ckeys = {**k_filter, **k_time, **k_amount}
|
ckeys = {**k_filter, **k_time, **k_amount}
|
||||||
|
|
||||||
result = get_scrobbles(**ckeys)
|
result = get_scrobbles(**ckeys)
|
||||||
|
@ -34,6 +34,7 @@ from collections import namedtuple
|
|||||||
from threading import Lock
|
from threading import Lock
|
||||||
import yaml
|
import yaml
|
||||||
import lru
|
import lru
|
||||||
|
import math
|
||||||
|
|
||||||
# url handling
|
# url handling
|
||||||
from importlib.machinery import SourceFileLoader
|
from importlib.machinery import SourceFileLoader
|
||||||
@ -262,11 +263,10 @@ def api_key_correct(request):
|
|||||||
|
|
||||||
|
|
||||||
def get_scrobbles(**keys):
|
def get_scrobbles(**keys):
|
||||||
r = db_query(**{k:keys[k] for k in keys if k in ["artist","artists","title","since","to","within","timerange","associated","track","max_"]})
|
r = db_query(**{k:keys[k] for k in keys if k in ["artist","artists","title","since","to","within","timerange","associated","track"]})
|
||||||
#if keys.get("max_") is not None:
|
offset = (keys.get('page') * keys.get('perpage')) if keys.get('perpage') is not math.inf else 0
|
||||||
# return r[:int(keys.get("max_"))]
|
r = r[offset:]
|
||||||
#else:
|
if keys.get('perpage') is not math.inf: r = r[:keys.get('perpage')]
|
||||||
# return r
|
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import urllib
|
|||||||
import math
|
import math
|
||||||
|
|
||||||
# this also sets defaults!
|
# this also sets defaults!
|
||||||
def uri_to_internal(keys,forceTrack=False,forceArtist=False):
|
def uri_to_internal(keys,forceTrack=False,forceArtist=False,api=False):
|
||||||
|
|
||||||
# output:
|
# output:
|
||||||
# 1 keys that define the filtered object like artist or track
|
# 1 keys that define the filtered object like artist or track
|
||||||
@ -46,7 +46,7 @@ def uri_to_internal(keys,forceTrack=False,forceArtist=False):
|
|||||||
|
|
||||||
|
|
||||||
#4
|
#4
|
||||||
amountkeys = {"page":0,"perpage":100}
|
amountkeys = {"page":0,"perpage":math.inf if api else 100} # api doesnt paginate per default
|
||||||
if "max" in keys: amountkeys["page"],amountkeys["perpage"] = 0, int(keys["max"])
|
if "max" in keys: amountkeys["page"],amountkeys["perpage"] = 0, int(keys["max"])
|
||||||
#different max than the internal one! the user doesn't get to disable pagination
|
#different max than the internal one! the user doesn't get to disable pagination
|
||||||
if "page" in keys: amountkeys["page"] = int(keys["page"])
|
if "page" in keys: amountkeys["page"] = int(keys["page"])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user