ai generated solutions to our ai generated problems
This commit is contained in:
+5
-10
@@ -126,7 +126,7 @@ const CSP_DIRECTIVES = [
|
||||
"style-src 'self'",
|
||||
"style-src-elem 'self'",
|
||||
"style-src-attr 'unsafe-inline'",
|
||||
"img-src 'self' data: blob: https://*.basemaps.cartocdn.com https://basemaps.cartocdn.com https://lastfm.freetls.fastly.net https://*.lastfm.freetls.fastly.net",
|
||||
"img-src 'self' data: blob: https://*.basemaps.cartocdn.com https://basemaps.cartocdn.com",
|
||||
"font-src 'self' data:",
|
||||
"connect-src 'self' https://challenges.cloudflare.com",
|
||||
"frame-src https://challenges.cloudflare.com",
|
||||
@@ -179,7 +179,8 @@ let analyticsDb = null
|
||||
let latestUptimeSnapshot = null
|
||||
|
||||
function songHistoryPath() {
|
||||
return path.join(uptimeStoragePath(), LASTFM_HISTORY_FILE)
|
||||
const fileName = path.basename(LASTFM_HISTORY_FILE || 'lastfm-song-of-day.json')
|
||||
return path.join(uptimeStoragePath(), fileName)
|
||||
}
|
||||
|
||||
function readSongHistory() {
|
||||
@@ -200,12 +201,6 @@ function todayKey() {
|
||||
return new Date().toISOString().slice(0, 10)
|
||||
}
|
||||
|
||||
function lastfmImage(track) {
|
||||
const images = Array.isArray(track.image) ? track.image : []
|
||||
const image = [...images].reverse().find((item) => item?.['#text'])
|
||||
return image?.['#text'] || ''
|
||||
}
|
||||
|
||||
function normalizeLastfmTrack(track) {
|
||||
const artist = track?.artist?.['#text'] || track?.artist?.name || ''
|
||||
const name = track?.name || ''
|
||||
@@ -217,7 +212,7 @@ function normalizeLastfmTrack(track) {
|
||||
name,
|
||||
album: track?.album?.['#text'] || '',
|
||||
url: track?.url || '',
|
||||
image: lastfmImage(track),
|
||||
image: '',
|
||||
played_at: track?.date?.uts ? Number(track.date.uts) : null,
|
||||
}
|
||||
}
|
||||
@@ -1901,7 +1896,7 @@ const server = http.createServer((req, res) => {
|
||||
return
|
||||
}
|
||||
|
||||
if (req.method === 'GET' && req.url === '/api/lastfm/song-of-day') {
|
||||
if (req.method === 'GET' && req.url === '/api/song-of-day') {
|
||||
if (!isSameOriginRequest(req)) {
|
||||
sendJson(res, 403, { error: 'Song of the day is restricted to this site' })
|
||||
return
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ const apiEndpoints = {
|
||||
viewers: '/api/viewers',
|
||||
viewerEvent: '/api/viewers/event',
|
||||
viewerDelete: '/api/viewers/delete',
|
||||
songOfDay: '/api/lastfm/song-of-day',
|
||||
songOfDay: '/api/song-of-day',
|
||||
teams: '/api/tss/leaderboard/teams?limit=100',
|
||||
teamsHealth: '/api/tss/leaderboard/teams?limit=1',
|
||||
resolve: (name) => `/api/tss/teams/resolve?name=${encodeURIComponent(name)}`,
|
||||
|
||||
+5
-7
@@ -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, {
|
||||
|
||||
Reference in New Issue
Block a user