Harden listening data endpoints with route fallbacks

This commit is contained in:
svemagie
2026-03-08 06:19:11 +01:00
parent 5277766ea3
commit e54624f7c0
4 changed files with 92 additions and 60 deletions
+13 -5
View File
@@ -5,30 +5,38 @@
import EleventyFetch from "@11ty/eleventy-fetch";
const INDIEKIT_URL = process.env.SITE_URL || "https://example.com";
const INDIEKIT_URL =
process.env.INDIEKIT_URL || process.env.SITE_URL || "https://example.com";
const FUNKWHALE_INSTANCE = process.env.FUNKWHALE_INSTANCE || "";
/**
* Fetch from Indiekit's public Funkwhale API endpoint
*/
async function fetchFromIndiekit(endpoint) {
const urls = [
`${INDIEKIT_URL}/funkwhale/api/${endpoint}`,
`${INDIEKIT_URL}/funkwhaleapi/api/${endpoint}`,
];
for (const url of urls) {
try {
const url = `${INDIEKIT_URL}/funkwhaleapi/api/${endpoint}`;
console.log(`[funkwhaleActivity] Fetching from Indiekit: ${url}`);
const data = await EleventyFetch(url, {
duration: "15m",
type: "json",
});
console.log(`[funkwhaleActivity] Indiekit ${endpoint} success`);
console.log(`[funkwhaleActivity] Indiekit ${endpoint} success via ${url}`);
return data;
} catch (error) {
console.log(
`[funkwhaleActivity] Indiekit API unavailable for ${endpoint}: ${error.message}`
`[funkwhaleActivity] Indiekit API unavailable for ${endpoint} at ${url}: ${error.message}`
);
return null;
}
}
return null;
}
/**
* Format duration in seconds to human-readable string
*/
+13 -5
View File
@@ -5,30 +5,38 @@
import EleventyFetch from "@11ty/eleventy-fetch";
const INDIEKIT_URL = process.env.SITE_URL || "https://example.com";
const INDIEKIT_URL =
process.env.INDIEKIT_URL || process.env.SITE_URL || "https://example.com";
const LASTFM_USERNAME = process.env.LASTFM_USERNAME || "";
/**
* Fetch from Indiekit's public Last.fm API endpoint
*/
async function fetchFromIndiekit(endpoint) {
const urls = [
`${INDIEKIT_URL}/lastfmapi/api/${endpoint}`,
`${INDIEKIT_URL}/lastfm/api/${endpoint}`,
];
for (const url of urls) {
try {
const url = `${INDIEKIT_URL}/lastfmapi/api/${endpoint}`;
console.log(`[lastfmActivity] Fetching from Indiekit: ${url}`);
const data = await EleventyFetch(url, {
duration: "15m",
type: "json",
});
console.log(`[lastfmActivity] Indiekit ${endpoint} success`);
console.log(`[lastfmActivity] Indiekit ${endpoint} success via ${url}`);
return data;
} catch (error) {
console.log(
`[lastfmActivity] Indiekit API unavailable for ${endpoint}: ${error.message}`
`[lastfmActivity] Indiekit API unavailable for ${endpoint} at ${url}: ${error.message}`
);
return null;
}
}
return null;
}
export default async function () {
try {
console.log("[lastfmActivity] Fetching Last.fm data...");
+13 -5
View File
@@ -5,30 +5,38 @@
import EleventyFetch from "@11ty/eleventy-fetch";
const INDIEKIT_URL = process.env.SITE_URL || "https://example.com";
const INDIEKIT_URL =
process.env.INDIEKIT_URL || process.env.SITE_URL || "https://example.com";
const FUNKWHALE_INSTANCE = process.env.FUNKWHALE_INSTANCE || "";
/**
* Fetch from Indiekit's public Funkwhale API endpoint
*/
async function fetchFromIndiekit(endpoint) {
const urls = [
`${INDIEKIT_URL}/funkwhale/api/${endpoint}`,
`${INDIEKIT_URL}/funkwhaleapi/api/${endpoint}`,
];
for (const url of urls) {
try {
const url = `${INDIEKIT_URL}/funkwhaleapi/api/${endpoint}`;
console.log(`[funkwhaleActivity] Fetching from Indiekit: ${url}`);
const data = await EleventyFetch(url, {
duration: "15m",
type: "json",
});
console.log(`[funkwhaleActivity] Indiekit ${endpoint} success`);
console.log(`[funkwhaleActivity] Indiekit ${endpoint} success via ${url}`);
return data;
} catch (error) {
console.log(
`[funkwhaleActivity] Indiekit API unavailable for ${endpoint}: ${error.message}`
`[funkwhaleActivity] Indiekit API unavailable for ${endpoint} at ${url}: ${error.message}`
);
return null;
}
}
return null;
}
/**
* Format duration in seconds to human-readable string
*/
+13 -5
View File
@@ -5,30 +5,38 @@
import EleventyFetch from "@11ty/eleventy-fetch";
const INDIEKIT_URL = process.env.SITE_URL || "https://example.com";
const INDIEKIT_URL =
process.env.INDIEKIT_URL || process.env.SITE_URL || "https://example.com";
const LASTFM_USERNAME = process.env.LASTFM_USERNAME || "";
/**
* Fetch from Indiekit's public Last.fm API endpoint
*/
async function fetchFromIndiekit(endpoint) {
const urls = [
`${INDIEKIT_URL}/lastfmapi/api/${endpoint}`,
`${INDIEKIT_URL}/lastfm/api/${endpoint}`,
];
for (const url of urls) {
try {
const url = `${INDIEKIT_URL}/lastfmapi/api/${endpoint}`;
console.log(`[lastfmActivity] Fetching from Indiekit: ${url}`);
const data = await EleventyFetch(url, {
duration: "15m",
type: "json",
});
console.log(`[lastfmActivity] Indiekit ${endpoint} success`);
console.log(`[lastfmActivity] Indiekit ${endpoint} success via ${url}`);
return data;
} catch (error) {
console.log(
`[lastfmActivity] Indiekit API unavailable for ${endpoint}: ${error.message}`
`[lastfmActivity] Indiekit API unavailable for ${endpoint} at ${url}: ${error.message}`
);
return null;
}
}
return null;
}
export default async function () {
try {
console.log("[lastfmActivity] Fetching Last.fm data...");