import { Hono } from 'hono'; import { getNowListening } from '../services/plex/getNowListening'; import { getArtwork } from '../services/plex/getArtwork'; import { handleResult } from '../lib/handleResult'; export const plexRouter = new Hono(); plexRouter.get('/listening', async (c) => { const nowListeningResult = await getNowListening(); return handleResult(c, nowListeningResult, (result) => { return c.json({ nowPlaying: result }); }); }); plexRouter.get('/artwork/:path{.+}', async (c) => { const { path } = c.req.param(); const artworkResult = await getArtwork(path); return handleResult( c, artworkResult, ({ contentType, data }) => { c.status(200); c.header('Content-Type', contentType); c.header('Cache-Control', 'max-age=604800'); return c.body(data); }, { UnexpectedMimeType: 400, ArtworkNotFound: 404 }, ); });