diff --git a/app/src/App.svelte b/app/src/App.svelte index 52c1ebd..f5e68a8 100644 --- a/app/src/App.svelte +++ b/app/src/App.svelte @@ -12,8 +12,13 @@ let loading = false; + let searchAlbums = []; + let total; + let next; + let query; + async function search(event) { - const query = event.target.value; + query = event.target.value; searchAlbums = []; loading = true; @@ -24,14 +29,33 @@ const response = await fetch(url); const data = await response.json(); loading = false; - searchAlbums = data; + searchAlbums = data.data; + total = data.total; + next = data.next; } catch (error) { console.error(error); loading = false; } } - let searchAlbums = []; + async function searchMore() { + loading = true; + + try { + let url = dev ? (new URL('http://localhost:4500/api/search')) : (new URL('/api/search', window.location.origin)); + url.searchParams.set('search', query); + url.searchParams.set('index', next); + const response = await fetch(url); + const data = await response.json(); + loading = false; + searchAlbums = [...searchAlbums, ...data.data]; + total = data.total; + next = data.next; + } catch (error) { + console.error(error); + loading = false; + } + }
- {#if loading} - - {/if} {#if searchAlbums.length > 0}
{#each searchAlbums as album, i} {/each}
+ + {#if total > searchAlbums.length} +
+ +
+ {/if} + {/if} + {#if loading} + {/if} diff --git a/app/src/app.css b/app/src/app.css index 013de4c..311677e 100644 --- a/app/src/app.css +++ b/app/src/app.css @@ -23,6 +23,14 @@ body { color: rgb(151, 151, 255); filter: drop-shadow( 0px 0px 2px #8383F3); } + button { + background-color: #161627; + color: #fff; + border-color: #161627; + } + button:hover { + border-color: rgb(131, 131, 243); + } } @media (prefers-color-scheme: light) { body { @@ -40,6 +48,14 @@ body { color: #f484b6; filter: drop-shadow( 0px 0px 2px #f484b6); } + button { + background-color: #ffffff; + color: #1e1e2d; + border-color: #ffffff; + } + button:hover { + border-color: #ea74ac; + } } body { @@ -57,4 +73,14 @@ body { .link { cursor: pointer; transition: 0.1s color ease-out; +} + +button { + cursor: pointer; + border-width: 2px; + border-radius: 8px; + border-style: solid; + font-size: large; + padding: 0.25em; + transition: 0.1s border-color ease-out; } \ No newline at end of file diff --git a/src/get/album.ts b/src/get/album.ts index e7aedee..c3e5592 100644 --- a/src/get/album.ts +++ b/src/get/album.ts @@ -24,13 +24,15 @@ router.get('/api/album', async (req, res) => { id: album.id, title: album.title, link: album.link, + releaseDate: album.release_date, + explicitCover: album.explicit_content_cover, tracks: album.tracks.data.map(t => { return { id: t.id, title: t.title, duration: t.duration, link: t.link, - artist: t.artist.name, + artist: t.artist.name }; }) }); diff --git a/src/get/search.ts b/src/get/search.ts index f6c3dda..26c4db4 100644 --- a/src/get/search.ts +++ b/src/get/search.ts @@ -12,19 +12,22 @@ router.get('/api/search', async (req, res) => { if (Array.isArray(req.query.search)) req.query.search = req.query.search.join(''); req.query.search = req.query.search as string; - let s: [Album]; + let s: DeezerResponse<[Album]>; try { - s = searchcache[req.query.search] || (await deezerInstance.api.search_album(req.query.search, { + s = searchcache[req.query.search+'/'+req.query.index] || (await deezerInstance.api.search_album(req.query.search, { limit: config.limits.searchLimit || 15, - })).data; + index: parseInt(req.query.index as string) || undefined + })); } catch(err) { logger.error((err as Error).toString()); return res.sendStatus(500); } - if (!searchcache[req.query.search]) searchcache[req.query.search] = s; + searchcache[req.query.search+'/'+req.query.index] = s; - let format = s.map(s => { - return { + let format = { + next: s.next && s.next.split('=').pop(), // dumb workaround of having to use regexes because i hate regexes + total: s.total, + data: s.data.map(s => ({ id: s.id, title: s.title, cover: s.md5_image, @@ -32,8 +35,8 @@ router.get('/api/search', async (req, res) => { id: s.artist.id, name: s.artist.name }, - }; - }); + })) + }; res.send(format); }); diff --git a/src/index.ts b/src/index.ts index 0e9971e..6a92b81 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,7 +10,7 @@ import { deezerInstance } from './deemix'; export const port = config.server.port || 4500; -export let searchcache: Record = {}; +export let searchcache: Record> = {}; export let albumcache: Record = {}; export let trackcache: Record = {};