chore: cleanup

This commit is contained in:
Cory Dransfeldt 2024-04-29 04:44:51 -07:00
parent 653ea1dcc7
commit 4a0609d94f
No known key found for this signature in database
2 changed files with 59 additions and 61 deletions

View file

@ -1,48 +1,48 @@
import { getStore } from '@netlify/blobs' import { getStore } from '@netlify/blobs'
const emojiMap = (genre, artist) => { const emojiMap = (genre, artist) => {
const DEFAULT = "🎧"; const DEFAULT = "🎧"
const normalizedArtist = artist?.toLowerCase(); const normalizedArtist = artist?.toLowerCase()
if (normalizedArtist === "afi") return "⛵️🌅"; if (normalizedArtist === "afi") return "⛵️🌅"
if (normalizedArtist === "agalloch") return "🏔️"; if (normalizedArtist === "agalloch") return "🏔️"
if (normalizedArtist === "augury") return "☄️"; if (normalizedArtist === "augury") return "☄️"
if (normalizedArtist === "autopsy") return "🧟"; if (normalizedArtist === "autopsy") return "🧟"
if (normalizedArtist === "balance and composure") return "🪂"; if (normalizedArtist === "balance and composure") return "🪂"
if (normalizedArtist === "bedsore") return "🛏️"; if (normalizedArtist === "bedsore") return "🛏️"
if (normalizedArtist === "birds in row") return "🦅🦉🦢"; if (normalizedArtist === "birds in row") return "🦅🦉🦢"
if (normalizedArtist === "black flag") return "🏴"; if (normalizedArtist === "black flag") return "🏴"
if (normalizedArtist === "blink-182") return "😵"; if (normalizedArtist === "blink-182") return "😵"
if (normalizedArtist === "blood incantation") return "👽"; if (normalizedArtist === "blood incantation") return "👽"
if (normalizedArtist === "bolt thrower") return "⚔️" if (normalizedArtist === "bolt thrower") return "⚔️"
if (normalizedArtist === "bruce springsteen") return "🇺🇸"; if (normalizedArtist === "bruce springsteen") return "🇺🇸"
if (normalizedArtist === "carcass") return "🥼"; if (normalizedArtist === "carcass") return "🥼"
if (normalizedArtist === "counting crows") return "🐦‍⬛"; if (normalizedArtist === "counting crows") return "🐦‍⬛"
if (normalizedArtist === "david bowie") return "👨🏻‍🎤"; if (normalizedArtist === "david bowie") return "👨🏻‍🎤"
if (normalizedArtist === "cevoid of thought") return "🚫💭"; if (normalizedArtist === "cevoid of thought") return "🚫💭"
if (normalizedArtist === "drug church") return "💊⛪️"; if (normalizedArtist === "drug church") return "💊⛪️"
if (normalizedArtist === "fleshwater") return "🐤"; if (normalizedArtist === "fleshwater") return "🐤"
if (normalizedArtist === "full of hell & nothing") return "🫨🎸"; if (normalizedArtist === "full of hell & nothing") return "🫨🎸"
if (normalizedArtist === "imperial triumphant") return "🎭"; if (normalizedArtist === "imperial triumphant") return "🎭"
if (normalizedArtist === "mastodon") return "🐋"; if (normalizedArtist === "mastodon") return "🐋"
if (normalizedArtist === "minor threat") return "👨🏻‍🦲"; if (normalizedArtist === "minor threat") return "👨🏻‍🦲"
if (normalizedArtist === "nomeansno") return "🐵🐮🚬"; if (normalizedArtist === "nomeansno") return "🐵🐮🚬"
if (normalizedArtist === "nothing") return "🏳️"; if (normalizedArtist === "nothing") return "🏳️"
if (normalizedArtist === "panopticon") return "🪕🪦"; if (normalizedArtist === "panopticon") return "🪕🪦"
if (normalizedArtist === "radiohead") return "📻"; if (normalizedArtist === "radiohead") return "📻"
if (normalizedArtist === "taylor swift") return "👸🏼"; if (normalizedArtist === "taylor swift") return "👸🏼"
if (normalizedArtist === "the mars volta") return "💡😮"; if (normalizedArtist === "the mars volta") return "💡😮"
if (normalizedArtist === "thrice") return "👨‍🎨🚑"; if (normalizedArtist === "thrice") return "👨‍🎨🚑"
if (normalizedArtist === "tom waits") return "🤹🏻" if (normalizedArtist === "tom waits") return "🤹🏻"
if (normalizedArtist === "webbed wing") return "🤡"; if (normalizedArtist === "webbed wing") return "🤡"
// early return for bad input // early return for bad input
if (!genre) return DEFAULT; if (!genre) return DEFAULT
if (genre.includes("death metal") || genre.includes("death-doom")) return "💀"; if (genre.includes("death metal") || genre.includes("death-doom")) return "💀"
if (genre.includes("black metal") || genre.includes("blackgaze")) return "🪦"; if (genre.includes("black metal") || genre.includes("blackgaze")) return "🪦"
if (genre.includes("metal")) return "🤘"; if (genre.includes("metal")) return "🤘"
if (genre.includes("emo") || genre.includes("blues")) return "😢"; if (genre.includes("emo") || genre.includes("blues")) return "😢"
if (genre.includes("grind") || genre.includes("powerviolence")) return "🫨"; if (genre.includes("grind") || genre.includes("powerviolence")) return "🫨"
if ( if (
genre.includes("country") || genre.includes("country") ||
genre.includes("americana") || genre.includes("americana") ||
@ -50,17 +50,17 @@ const emojiMap = (genre, artist) => {
genre.includes("folk") || genre.includes("folk") ||
genre.includes("songwriter") genre.includes("songwriter")
) )
return "🪕"; return "🪕"
if (genre.includes("post-punk")) return "😔"; if (genre.includes("post-punk")) return "😔"
if (genre.includes("dance-punk")) return "🪩"; if (genre.includes("dance-punk")) return "🪩"
if (genre.includes("punk") || genre.includes("hardcore")) return "✊"; if (genre.includes("punk") || genre.includes("hardcore")) return "✊"
if (genre.includes("hip hop")) return "🎤"; if (genre.includes("hip hop")) return "🎤"
if (genre.includes("progressive") || genre.includes("experimental")) if (genre.includes("progressive") || genre.includes("experimental"))
return "🤓"; return "🤓"
if (genre.includes("jazz")) return "🎺"; if (genre.includes("jazz")) return "🎺"
if (genre.includes("psychedelic")) return "💊"; if (genre.includes("psychedelic")) return "💊"
if (genre.includes("dance") || genre.includes("electronic")) return "💻"; if (genre.includes("dance") || genre.includes("electronic")) return "💻"
if (genre.includes("ambient")) return "🤫"; if (genre.includes("ambient")) return "🤫"
if ( if (
genre.includes("alternative") || genre.includes("alternative") ||
genre.includes("rock") || genre.includes("rock") ||
@ -68,18 +68,17 @@ const emojiMap = (genre, artist) => {
genre.includes("screamo") || genre.includes("screamo") ||
genre.includes("grunge") genre.includes("grunge")
) )
return "🎸"; return "🎸"
return DEFAULT; return DEFAULT
}; }
export default async () => { export default async () => {
const TV_KEY = Netlify.env.get("API_KEY_TRAKT"); const TV_KEY = Netlify.env.get("API_KEY_TRAKT")
const scrobbles = getStore('scrobbles') const scrobbles = getStore('scrobbles')
const headers = { const headers = {
"Content-Type": "application/json", "Content-Type": "application/json",
"Cache-Control": "public, s-maxage=360, stale-while-revalidate=1080", "Cache-Control": "public, s-maxage=360, stale-while-revalidate=1080",
}; }
const traktRes = await fetch("https://api.trakt.tv/users/cdransf/watching", { const traktRes = await fetch("https://api.trakt.tv/users/cdransf/watching", {
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
@ -89,13 +88,13 @@ export default async () => {
}) })
.then((data) => { .then((data) => {
if (data.status === 204) return {} if (data.status === 204) return {}
if (data.ok) return data?.json(); if (data.ok) return data?.json()
throw new Error('Something went wrong with the Trakt endpoint.'); throw new Error('Something went wrong with the Trakt endpoint.')
}) })
.catch(err => { .catch(err => {
console.log(err); console.log(err)
return {} return {}
}); })
if (Object.keys(traktRes).length) { if (Object.keys(traktRes).length) {
if (traktRes["type"] === "episode") { if (traktRes["type"] === "episode") {
@ -114,7 +113,6 @@ export default async () => {
) )
} }
} }
const scrobbleData = await scrobbles.get('now-playing', { type: 'json'}) const scrobbleData = await scrobbles.get('now-playing', { type: 'json'})
if (!scrobbleData) return new Response(JSON.stringify({}, { headers })) if (!scrobbleData) return new Response(JSON.stringify({}, { headers }))
@ -129,9 +127,9 @@ export default async () => {
}), }),
{ headers } { headers }
) )
}; }
export const config = { export const config = {
cache: "manual", cache: "manual",
path: "/api/now-playing" path: "/api/now-playing"
}; }

View file

@ -1,6 +1,6 @@
{ {
"name": "coryd.dev", "name": "coryd.dev",
"version": "13.0.5", "version": "13.0.6",
"description": "The source for my personal site. Built using 11ty.", "description": "The source for my personal site. Built using 11ty.",
"type": "module", "type": "module",
"scripts": { "scripts": {