Fixes to strange bars on mobile, and addition of server which currently powers a new Last.FM-based music tracker.
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m20s

This commit is contained in:
Cameron Redmore 2025-08-08 09:53:34 +01:00
parent c65b8465b5
commit be5a61185b
No known key found for this signature in database
8 changed files with 662 additions and 1251 deletions

48
src/server.ts Normal file
View file

@ -0,0 +1,48 @@
import { Elysia, t } from 'elysia';
import { staticPlugin } from '@elysiajs/static';
const app = new Elysia()
.use(staticPlugin({
assets: 'dist',
prefix: ''
}))
.get('/api/last-song', async () => {
const apiKey = Bun.env.LASTFM_API_KEY;
const username = Bun.env.LASTFM_USERNAME;
if (!apiKey || !username) {
return new Response(
JSON.stringify({ error: 'Last.fm API key or username not configured' }),
{ status: 500, headers: { 'Content-Type': 'application/json' } }
);
}
const url = `https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=${username}&api_key=${apiKey}&format=json&limit=1`;
try {
const response = await fetch(url);
const data = await response.json();
const track = data.recenttracks.track[0];
return {
name: track.name,
artist: track.artist['#text'],
album: track.album['#text'],
url: track.url,
nowPlaying: track['@attr']?.nowplaying === 'true',
image: track.image || [],
};
} catch (error) {
console.error('Error fetching from Last.fm:', error);
return new Response(JSON.stringify({ error: 'Failed to fetch last song' }), {
status: 500,
headers: { 'Content-Type': 'application/json' },
});
}
})
.listen(3000);
console.log(
`🦊 Elysia is running at http://${app.server?.hostname}:${app.server?.port}`
);
export type App = typeof app;