refactor: require sitemap filename to be provided, as it should only target the posts, not the whole site

This commit is contained in:
Derrick Hammer 2023-12-24 06:25:32 -05:00
parent 794f71b0e7
commit 2c7f15a2df
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 13 additions and 2 deletions

View File

@ -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) => {

2
app/types.d.ts vendored
View File

@ -14,6 +14,6 @@ export type SelectOptions = {
export type SiteList = {
[domain: string]: {
name: string;
pubkey: string;
sitemap: string;
};
};