mirror of
https://github.com/krateng/maloja.git
synced 2025-04-19 18:17:36 +03: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")
|
||||
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}
|
||||
|
||||
result = get_scrobbles(**ckeys)
|
||||
|
@ -34,6 +34,7 @@ from collections import namedtuple
|
||||
from threading import Lock
|
||||
import yaml
|
||||
import lru
|
||||
import math
|
||||
|
||||
# url handling
|
||||
from importlib.machinery import SourceFileLoader
|
||||
@ -262,11 +263,10 @@ def api_key_correct(request):
|
||||
|
||||
|
||||
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_"]})
|
||||
#if keys.get("max_") is not None:
|
||||
# return r[:int(keys.get("max_"))]
|
||||
#else:
|
||||
# return r
|
||||
r = db_query(**{k:keys[k] for k in keys if k in ["artist","artists","title","since","to","within","timerange","associated","track"]})
|
||||
offset = (keys.get('page') * keys.get('perpage')) if keys.get('perpage') is not math.inf else 0
|
||||
r = r[offset:]
|
||||
if keys.get('perpage') is not math.inf: r = r[:keys.get('perpage')]
|
||||
return r
|
||||
|
||||
|
||||
|
@ -4,7 +4,7 @@ import urllib
|
||||
import math
|
||||
|
||||
# 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:
|
||||
# 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
|
||||
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"])
|
||||
#different max than the internal one! the user doesn't get to disable pagination
|
||||
if "page" in keys: amountkeys["page"] = int(keys["page"])
|
||||
|
Loading…
x
Reference in New Issue
Block a user