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
Some checks failed
thehideout/TheHideout-API/pipeline/head There was a failure building this commit
This commit is contained in:
parent
b406165866
commit
f36dfb63df
@ -7,12 +7,10 @@ export async function importNotionNavigation(env) {
|
||||
const notionProperties = await queryNotionDataSource(env.PROPERTIES_DB);
|
||||
// Transform the incoming pages for the given type
|
||||
const navigationItems = (
|
||||
await Promise.all(
|
||||
notionPages.map(async (item) => transformNavigation(item, "page")),
|
||||
notionProperties.map(async (item) =>
|
||||
transformNavigation(item, "property")
|
||||
)
|
||||
)
|
||||
await Promise.all([
|
||||
...notionPages.map((item) => transformNavigation(item, "page")),
|
||||
...notionProperties.map((item) => transformNavigation(item, "property")),
|
||||
])
|
||||
).filter(Boolean);
|
||||
|
||||
// Store the updated cache
|
||||
|
||||
@ -22,13 +22,25 @@ async function processSVG(svgText, cssClass) {
|
||||
}
|
||||
}
|
||||
|
||||
// processNotionIcon fetches and validates the SVG
|
||||
export async function processNotionIcon(iconObj, cssClass = "") {
|
||||
if (iconObj?.external?.url && iconObj?.url) {
|
||||
return undefined;
|
||||
function notionIconUrl(iconObj) {
|
||||
return (
|
||||
iconObj?.external?.url ||
|
||||
iconObj?.file?.url ||
|
||||
iconObj?.custom_emoji?.url ||
|
||||
iconObj?.url
|
||||
);
|
||||
}
|
||||
|
||||
const url = iconObj?.external?.url || iconObj.url;
|
||||
// processNotionIcon fetches and validates the SVG
|
||||
export async function processNotionIcon(iconObj, cssClass = "") {
|
||||
if (iconObj?.type === "emoji") {
|
||||
return iconObj.emoji;
|
||||
}
|
||||
|
||||
const url = notionIconUrl(iconObj);
|
||||
if (!url) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const urlObject = new URL(url);
|
||||
|
||||
|
||||
@ -72,7 +72,11 @@ export async function storeNavigation(env, navigation) {
|
||||
export async function transformNavigation(notionPage, type) {
|
||||
var icon = undefined;
|
||||
if (notionPage.icon) {
|
||||
try {
|
||||
icon = await processNotionIcon(notionPage.icon, "th-icon");
|
||||
} catch (error) {
|
||||
console.error("Error processing navigation icon:", error);
|
||||
}
|
||||
}
|
||||
const properties = notionPage.properties;
|
||||
const id = notionPage.id;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user