initial commit

This commit is contained in:
Cory Dransfeldt 2024-11-16 16:43:07 -08:00
commit c70fc72952
No known key found for this signature in database
143 changed files with 13594 additions and 0 deletions

45
workers/playing/index.js Normal file
View file

@ -0,0 +1,45 @@
import { createClient } from "@supabase/supabase-js";
export default {
async fetch(request, env) {
const supabaseUrl = env.SUPABASE_URL;
const supabaseKey = env.SUPABASE_KEY;
const supabase = createClient(supabaseUrl, supabaseKey);
const { data, error } = await supabase
.from("optimized_latest_listen")
.select("*")
.single();
const headers = {
"Content-Type": "application/json",
"Cache-Control": "public, s-maxage=360, stale-while-revalidate=1080",
};
if (error) {
console.error("Error fetching data:", error);
return new Response(
JSON.stringify({ error: "Failed to fetch the latest track" }),
{ headers }
);
}
if (!data)
return new Response(
JSON.stringify({ message: "No recent tracks found" }),
{ headers }
);
const genreEmoji = data.genre_emoji;
const emoji = data.artist_emoji || genreEmoji;
return new Response(
JSON.stringify({
content: `${emoji || "🎧"} ${
data.track_name
} by <a href="https://coryd.dev${data.url}">${data.artist_name}</a>`,
}),
{ headers }
);
},
};

View file

@ -0,0 +1,12 @@
name = "now-playing-worker"
main = "./index.js" # Specify the entry point
compatibility_date = "2023-01-01"
account_id = "${CF_ACCOUNT_ID}"
workers_dev = true
[env.production]
name = "now-playing-worker-production"
routes = [
{ pattern = "coryd.dev/api/now-playing", zone_id = "${CF_ZONE_ID}" }
]