From 2c7f15a2dfb8a39e5eb7b0adfe971e9520b7ab23 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sun, 24 Dec 2023 06:25:32 -0500 Subject: [PATCH] refactor: require sitemap filename to be provided, as it should only target the posts, not the whole site --- app/routes/api.events.siteUpdateReceived.ts | 13 ++++++++++++- app/types.d.ts | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/routes/api.events.siteUpdateReceived.ts b/app/routes/api.events.siteUpdateReceived.ts index 81d0d85..3e3bcaa 100644 --- a/app/routes/api.events.siteUpdateReceived.ts +++ b/app/routes/api.events.siteUpdateReceived.ts @@ -10,11 +10,22 @@ import { prisma } from "@/lib/prisma"; import * as cheerio from "cheerio"; import slugify from "slugify"; import path from "path"; +import { getAvailableSites } from "@/utils.js"; // Action function for POST requests export async function action({ request }: ActionFunctionArgs) { const client = new S5Client("https://s5.web3portal.com"); const data = await request.json(); + + const site = data.site; + const sites = getAvailableSites(); + + if (!(site in sites)) { + throw new Response("Site does not exist", { status: 404 }); + } + + const siteInfo = sites[site]; + const meta = (await client.getMetadata(data.cid as string)) as any; const fileMeta = meta.metadata as any; const paths = fileMeta.paths as { @@ -27,7 +38,7 @@ export async function action({ request }: ActionFunctionArgs) { throw new Response("Sitemap not found", { status: 404 }); } - const sitemapData = await client.downloadData(paths["sitemap.xml"].cid); + const sitemapData = await client.downloadData(paths[siteInfo.sitemap].cid); const sitemap = await xml2js.parseStringPromise(sitemapData); const urls = sitemap.urlset.url.map((urlEntry: any) => { diff --git a/app/types.d.ts b/app/types.d.ts index c8153a8..bdfd86c 100644 --- a/app/types.d.ts +++ b/app/types.d.ts @@ -14,6 +14,6 @@ export type SelectOptions = { export type SiteList = { [domain: string]: { name: string; - pubkey: string; + sitemap: string; }; };