fix: update RSS feed to work with new media architecture
- Update album queries to use media relation instead of direct photos relation - Filter photography albums by checking media.isPhotography instead of album.isPhotography - Remove reference to non-existent post.excerpt field - Fix cover photo access and counts to use album.media - Fix URL concatenation for Cloudinary images to handle absolute URLs 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
f24b79da2f
commit
2dd3d60485
1 changed files with 33 additions and 23 deletions
|
|
@ -73,16 +73,15 @@ export const GET: RequestHandler = async (event) => {
|
||||||
showInUniverse: true
|
showInUniverse: true
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
photos: {
|
media: {
|
||||||
where: {
|
include: {
|
||||||
status: 'published',
|
media: true
|
||||||
showInPhotos: true
|
|
||||||
},
|
},
|
||||||
orderBy: { displayOrder: 'asc' },
|
orderBy: { displayOrder: 'asc' },
|
||||||
take: 1 // Get first photo for cover image
|
take: 1 // Get first media for cover image
|
||||||
},
|
},
|
||||||
_count: {
|
_count: {
|
||||||
select: { photos: true }
|
select: { media: true }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
orderBy: { createdAt: 'desc' },
|
orderBy: { createdAt: 'desc' },
|
||||||
|
|
@ -93,23 +92,34 @@ export const GET: RequestHandler = async (event) => {
|
||||||
const photoAlbums = await prisma.album.findMany({
|
const photoAlbums = await prisma.album.findMany({
|
||||||
where: {
|
where: {
|
||||||
status: 'published',
|
status: 'published',
|
||||||
isPhotography: true
|
media: {
|
||||||
|
some: {
|
||||||
|
media: {
|
||||||
|
isPhotography: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
photos: {
|
media: {
|
||||||
|
include: {
|
||||||
|
media: true
|
||||||
|
},
|
||||||
where: {
|
where: {
|
||||||
status: 'published',
|
media: {
|
||||||
showInPhotos: true
|
isPhotography: true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
orderBy: { displayOrder: 'asc' },
|
orderBy: { displayOrder: 'asc' },
|
||||||
take: 1 // Get first photo for cover image
|
take: 1 // Get first photo for cover image
|
||||||
},
|
},
|
||||||
_count: {
|
_count: {
|
||||||
select: {
|
select: {
|
||||||
photos: {
|
media: {
|
||||||
where: {
|
where: {
|
||||||
status: 'published',
|
media: {
|
||||||
showInPhotos: true
|
isPhotography: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -127,7 +137,7 @@ export const GET: RequestHandler = async (event) => {
|
||||||
id: post.id.toString(),
|
id: post.id.toString(),
|
||||||
title:
|
title:
|
||||||
post.title || `${post.postType.charAt(0).toUpperCase() + post.postType.slice(1)} Post`,
|
post.title || `${post.postType.charAt(0).toUpperCase() + post.postType.slice(1)} Post`,
|
||||||
description: post.excerpt || extractTextSummary(post.content) || '',
|
description: extractTextSummary(post.content) || '',
|
||||||
content: convertContentToHTML(post.content),
|
content: convertContentToHTML(post.content),
|
||||||
link: `${event.url.origin}/universe/${post.slug}`,
|
link: `${event.url.origin}/universe/${post.slug}`,
|
||||||
guid: `${event.url.origin}/universe/${post.slug}`,
|
guid: `${event.url.origin}/universe/${post.slug}`,
|
||||||
|
|
@ -143,14 +153,14 @@ export const GET: RequestHandler = async (event) => {
|
||||||
title: album.title,
|
title: album.title,
|
||||||
description:
|
description:
|
||||||
album.description ||
|
album.description ||
|
||||||
`Photo album with ${album._count.photos} photo${album._count.photos !== 1 ? 's' : ''}`,
|
`Photo album with ${album._count.media} photo${album._count.media !== 1 ? 's' : ''}`,
|
||||||
content: album.description ? `<p>${escapeXML(album.description)}</p>` : '',
|
content: album.description ? `<p>${escapeXML(album.description)}</p>` : '',
|
||||||
link: `${event.url.origin}/photos/${album.slug}`,
|
link: `${event.url.origin}/photos/${album.slug}`,
|
||||||
guid: `${event.url.origin}/photos/${album.slug}`,
|
guid: `${event.url.origin}/photos/${album.slug}`,
|
||||||
pubDate: album.createdAt,
|
pubDate: album.createdAt,
|
||||||
updatedDate: album.updatedAt,
|
updatedDate: album.updatedAt,
|
||||||
photoCount: album._count.photos,
|
photoCount: album._count.media,
|
||||||
coverPhoto: album.photos[0],
|
coverPhoto: album.media[0]?.media,
|
||||||
location: album.location
|
location: album.location
|
||||||
})),
|
})),
|
||||||
...photoAlbums
|
...photoAlbums
|
||||||
|
|
@ -162,14 +172,14 @@ export const GET: RequestHandler = async (event) => {
|
||||||
title: album.title,
|
title: album.title,
|
||||||
description:
|
description:
|
||||||
album.description ||
|
album.description ||
|
||||||
`Photography album${album.location ? ` from ${album.location}` : ''} with ${album._count.photos} photo${album._count.photos !== 1 ? 's' : ''}`,
|
`Photography album${album.location ? ` from ${album.location}` : ''} with ${album._count.media} photo${album._count.media !== 1 ? 's' : ''}`,
|
||||||
content: album.description ? `<p>${escapeXML(album.description)}</p>` : '',
|
content: album.description ? `<p>${escapeXML(album.description)}</p>` : '',
|
||||||
link: `${event.url.origin}/photos/${album.slug}`,
|
link: `${event.url.origin}/photos/${album.slug}`,
|
||||||
guid: `${event.url.origin}/photos/${album.slug}`,
|
guid: `${event.url.origin}/photos/${album.slug}`,
|
||||||
pubDate: album.createdAt,
|
pubDate: album.createdAt,
|
||||||
updatedDate: album.updatedAt,
|
updatedDate: album.updatedAt,
|
||||||
photoCount: album._count.photos,
|
photoCount: album._count.media,
|
||||||
coverPhoto: album.photos[0],
|
coverPhoto: album.media[0]?.media,
|
||||||
location: album.location,
|
location: album.location,
|
||||||
date: album.date
|
date: album.date
|
||||||
}))
|
}))
|
||||||
|
|
@ -209,9 +219,9 @@ ${item.updatedDate ? `<atom:updated>${new Date(item.updatedDate).toISOString()}<
|
||||||
${
|
${
|
||||||
item.type === 'album' && item.coverPhoto
|
item.type === 'album' && item.coverPhoto
|
||||||
? `
|
? `
|
||||||
<enclosure url="${event.url.origin}${item.coverPhoto.url}" type="image/jpeg" length="0"/>
|
<enclosure url="${item.coverPhoto.url.startsWith('http') ? item.coverPhoto.url : event.url.origin + item.coverPhoto.url}" type="image/jpeg" length="${item.coverPhoto.size || 0}"/>
|
||||||
<media:thumbnail url="${event.url.origin}${item.coverPhoto.thumbnailUrl || item.coverPhoto.url}"/>
|
<media:thumbnail url="${(item.coverPhoto.thumbnailUrl || item.coverPhoto.url).startsWith('http') ? (item.coverPhoto.thumbnailUrl || item.coverPhoto.url) : event.url.origin + (item.coverPhoto.thumbnailUrl || item.coverPhoto.url)}"/>
|
||||||
<media:content url="${event.url.origin}${item.coverPhoto.url}" type="image/jpeg"/>`
|
<media:content url="${item.coverPhoto.url.startsWith('http') ? item.coverPhoto.url : event.url.origin + item.coverPhoto.url}" type="image/jpeg"/>`
|
||||||
: ''
|
: ''
|
||||||
}
|
}
|
||||||
${item.location ? `<category domain="location">${escapeXML(item.location)}</category>` : ''}
|
${item.location ? `<category domain="location">${escapeXML(item.location)}</category>` : ''}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue