Refactored navigation icon processing and improved error handling in transformNavigation function
Some checks failed
thehideout/TheHideout-API/pipeline/head There was a failure building this commit

This commit is contained in:
Tom Butcher 2026-09-24 21:58:08 +01:00
parent b406165866
commit f36dfb63df
3 changed files with 24 additions and 10 deletions

View File

@ -7,12 +7,10 @@ export async function importNotionNavigation(env) {
const notionProperties = await queryNotionDataSource(env.PROPERTIES_DB); const notionProperties = await queryNotionDataSource(env.PROPERTIES_DB);
// Transform the incoming pages for the given type // Transform the incoming pages for the given type
const navigationItems = ( const navigationItems = (
await Promise.all( await Promise.all([
notionPages.map(async (item) => transformNavigation(item, "page")), ...notionPages.map((item) => transformNavigation(item, "page")),
notionProperties.map(async (item) => ...notionProperties.map((item) => transformNavigation(item, "property")),
transformNavigation(item, "property") ])
)
)
).filter(Boolean); ).filter(Boolean);
// Store the updated cache // Store the updated cache

View File

@ -22,13 +22,25 @@ async function processSVG(svgText, cssClass) {
} }
} }
function notionIconUrl(iconObj) {
return (
iconObj?.external?.url ||
iconObj?.file?.url ||
iconObj?.custom_emoji?.url ||
iconObj?.url
);
}
// processNotionIcon fetches and validates the SVG // processNotionIcon fetches and validates the SVG
export async function processNotionIcon(iconObj, cssClass = "") { export async function processNotionIcon(iconObj, cssClass = "") {
if (iconObj?.external?.url && iconObj?.url) { if (iconObj?.type === "emoji") {
return undefined; return iconObj.emoji;
} }
const url = iconObj?.external?.url || iconObj.url; const url = notionIconUrl(iconObj);
if (!url) {
return undefined;
}
const urlObject = new URL(url); const urlObject = new URL(url);

View File

@ -72,7 +72,11 @@ export async function storeNavigation(env, navigation) {
export async function transformNavigation(notionPage, type) { export async function transformNavigation(notionPage, type) {
var icon = undefined; var icon = undefined;
if (notionPage.icon) { if (notionPage.icon) {
icon = await processNotionIcon(notionPage.icon, "th-icon"); try {
icon = await processNotionIcon(notionPage.icon, "th-icon");
} catch (error) {
console.error("Error processing navigation icon:", error);
}
} }
const properties = notionPage.properties; const properties = notionPage.properties;
const id = notionPage.id; const id = notionPage.id;