feat: api endpoint for reading all available playlists
Some checks failed
Build RPi Pico firmware image / Build-Firmware (push) Successful in 4m36s
Check code formatting / Check-C-Format (push) Successful in 7s
Check code formatting / Check-Python-Flake8 (push) Failing after 10s
Check code formatting / Check-Bash-Shellcheck (push) Successful in 5s
Run unit tests on host / Run-Unit-Tests (push) Successful in 8s
Run pytests / Check-Pytest (push) Successful in 10s

This commit is contained in:
2025-12-19 18:33:42 +01:00
parent 32bf6a8d68
commit 51cb2c3a68
3 changed files with 21 additions and 2 deletions

View File

@@ -193,3 +193,6 @@ class PlayerApp:
def get_nfc(self): def get_nfc(self):
return self.nfc return self.nfc
def get_playlist_db(self):
return self.playlist_db

View File

@@ -251,6 +251,16 @@ class BTreeDB(IPlaylistDB):
if flush: if flush:
self._flush() self._flush()
def getPlaylistTags(self):
"""
Get a keys-only dict of all defined playlists. Playlists currently do not have names, but are identified by
their tag.
"""
playlist_tags = set()
for item in self.db:
playlist_tags.add(item.split(b'/')[0])
return playlist_tags
def getPlaylistForTag(self, tag: bytes): def getPlaylistForTag(self, tag: bytes):
""" """
Lookup the playlist for 'tag' and return the Playlist object. Return None if no playlist exists for the given Lookup the playlist for 'tag' and return the Playlist object. Return None if no playlist exists for the given

View File

@@ -12,14 +12,15 @@ server = None
config = None config = None
app = None app = None
nfc = None nfc = None
playlist_db = None
def start_webserver(config_, app_): def start_webserver(config_, app_):
global server, config, app, nfc global server, config, app, nfc, playlist_db
server = asyncio.create_task(webapp.start_server(port=80)) server = asyncio.create_task(webapp.start_server(port=80))
config = config_ config = config_
app = app_ app = app_
nfc = app.get_nfc() nfc = app.get_nfc()
playlist_db = app.get_playlist_db()
@webapp.before_request @webapp.before_request
@@ -72,3 +73,8 @@ async def config_put(request):
async def last_tag_uid_get(request): async def last_tag_uid_get(request):
tag, _ = nfc.get_last_uid() tag, _ = nfc.get_last_uid()
return {'tag': tag} return {'tag': tag}
@webapp.route('/api/v1/playlists', methods=['GET'])
async def playlists_get(request):
return sorted(playlist_db.getPlaylistTags())