Make data static endpoints more resilient

This commit is contained in:
Sam Becker 2025-06-12 23:34:16 -05:00
parent 279454b288
commit 7373a1b1f9
4 changed files with 14 additions and 8 deletions

View File

@ -11,7 +11,7 @@ export async function GET() {
const photos = await getPhotosCached({
limit: FEED_PHOTO_REQUEST_LIMIT,
sortBy: 'createdAt',
});
}).catch(() => []);
return Response.json(formatFeedJson(photos));
} else {
return new Response('Feeds disabled', { status: 404 });

View File

@ -1,7 +1,7 @@
import { getPhotosCached } from '@/photo/cache';
import { SITE_FEEDS_ENABLED } from '@/app/config';
import { FEED_PHOTO_REQUEST_LIMIT } from '@/feed';
import { formatFeedRss } from '@/feed/rss';
import { formatFeedRssXml } from '@/feed/rss';
// Cache for 24 hours
export const revalidate = 86_400;
@ -11,10 +11,9 @@ export async function GET() {
const photos = await getPhotosCached({
limit: FEED_PHOTO_REQUEST_LIMIT,
sortBy: 'createdAt',
});
}).catch(() => []);
return new Response(
formatFeedRss(photos),
formatFeedRssXml(photos),
{ headers: { 'Content-Type': 'text/xml' } },
);
} else {

View File

@ -34,8 +34,15 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
},
photos,
] = await Promise.all([
getDataForCategoriesCached(),
getPhotoIdsAndUpdatedAt(),
getDataForCategoriesCached().catch(() => ({
cameras: [],
lenses: [],
tags: [],
recipes: [],
films: [],
focalLengths: [],
})),
getPhotoIdsAndUpdatedAt().catch(() => []),
]);
const lastModifiedSite = [

View File

@ -57,7 +57,7 @@ const feedPhotoToXml = (photo: FeedPhotoRss): string => {
</item>`;
};
export const formatFeedRss = (photos: Photo[]) =>
export const formatFeedRssXml = (photos: Photo[]) =>
`<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"