ai generated solutions to our ai generated problems

This commit is contained in:
Heidi
2026-05-27 15:00:16 +01:00
parent 8596674de1
commit e59bb87512
3 changed files with 11 additions and 18 deletions
+5 -7
View File
@@ -47,7 +47,8 @@ function expandHome(filePath) {
function devSongHistoryPath(env) {
const storageDir = path.resolve(expandHome(env.UPTIME_STORAGE_DIR || '~/tsswebstorage'))
return path.join(storageDir, env.LASTFM_HISTORY_FILE || 'lastfm-song-of-day.json')
const fileName = path.basename(env.LASTFM_HISTORY_FILE || 'lastfm-song-of-day.json')
return path.join(storageDir, fileName)
}
function readDevSongHistory(env) {
@@ -69,16 +70,13 @@ function normalizeLastfmTrack(track) {
const name = track?.name || ''
if (!artist || !name) return null
const images = Array.isArray(track.image) ? track.image : []
const image = [...images].reverse().find((item) => item?.['#text'])
return {
id: `${artist.toLowerCase()}::${name.toLowerCase()}`,
artist,
name,
album: track?.album?.['#text'] || '',
url: track?.url || '',
image: image?.['#text'] || '',
image: '',
played_at: track?.date?.uts ? Number(track.date.uts) : null,
}
}
@@ -176,7 +174,7 @@ function isAllowedApiUrl(req) {
if (url.pathname === '/api/viewers' && (req.method === 'GET' || req.method === 'HEAD')) return true
if (url.pathname === '/api/viewers/event' && req.method === 'POST') return true
if (url.pathname === '/api/lastfm/song-of-day' && (req.method === 'GET' || req.method === 'HEAD')) return true
if (url.pathname === '/api/song-of-day' && (req.method === 'GET' || req.method === 'HEAD')) return true
if (req.method !== 'GET' && req.method !== 'HEAD') return false
@@ -228,7 +226,7 @@ function apiGuard(env) {
}
const url = new URL(req.url, 'http://localhost')
if (url.pathname === '/api/lastfm/song-of-day' && req.method === 'GET') {
if (url.pathname === '/api/song-of-day' && req.method === 'GET') {
try {
const result = await devSongOfTheDay(env)
res.writeHead(result.status, {