VulpesOS/gaia/apps/music/js/services/albums.js
OverSu b38dea0597 Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
2026-09-30 23:13:03 +02:00

38 lines
1 KiB
JavaScript
Executable file

/* exported AlbumsService */
/* global Response, ServiceWorkerWare, bridge */
'use strict';
importScripts('components/bridge/client.js');
var client = bridge.client({
service: 'music-service',
endpoint: new BroadcastChannel('music-service')
});
function AlbumsService(worker) {
var stopAfter = ServiceWorkerWare.decorators.stopAfter;
worker.get('/api/albums/list', stopAfter((request) => {
return new Promise((resolve) => {
client.method('getAlbums')
.then(albums => resolve(respond(albums)));
});
}));
worker.get('/api/albums/info/:filePath', stopAfter((request) => {
return new Promise((resolve) => {
var filePath = decodeURIComponent(request.parameters.filePath);
client.method('getAlbum', filePath)
.then(songs => resolve(respond(songs)))
.catch((error) => {
resolve(new Response('', { status: 404 }));
});
});
}));
function respond(response) {
return new Response(JSON.stringify(response), {
headers: { 'Content-Type': 'application/json' }
});
}
}