diff --git a/src/routes/admin/posts/new/+page.svelte b/src/routes/admin/posts/new/+page.svelte index 85e36bc..63655c6 100644 --- a/src/routes/admin/posts/new/+page.svelte +++ b/src/routes/admin/posts/new/+page.svelte @@ -3,6 +3,8 @@ import { onMount } from 'svelte' import EssayForm from '$lib/components/admin/EssayForm.svelte' import SimplePostForm from '$lib/components/admin/SimplePostForm.svelte' + import PhotoPostForm from '$lib/components/admin/PhotoPostForm.svelte' + import AlbumForm from '$lib/components/admin/AlbumForm.svelte' let postType: 'blog' | 'microblog' | 'link' | 'photo' | 'album' = 'blog' let mounted = false @@ -21,11 +23,9 @@ {:else if postType === 'microblog' || postType === 'link'} - {:else} - -
-

Photo and album post types coming soon!

- ← Back to posts -
+ {:else if postType === 'photo'} + + {:else if postType === 'album'} + {/if} {/if} diff --git a/src/routes/api/posts/+server.ts b/src/routes/api/posts/+server.ts index b77697b..dfb5765 100644 --- a/src/routes/api/posts/+server.ts +++ b/src/routes/api/posts/+server.ts @@ -71,15 +71,46 @@ export const POST: RequestHandler = async (event) => { data.publishedAt = new Date() } + // Handle photo attachments for posts + let featuredImageId = data.featuredImage + if (data.attachedPhotos && data.attachedPhotos.length > 0 && !featuredImageId) { + // Use first attached photo as featured image for photo posts + featuredImageId = data.attachedPhotos[0] + } + + // Handle album gallery - use first image as featured image + if (data.gallery && data.gallery.length > 0 && !featuredImageId) { + // Get the media URL for the first gallery item + const firstMedia = await prisma.media.findUnique({ + where: { id: data.gallery[0] }, + select: { url: true } + }) + if (firstMedia) { + featuredImageId = firstMedia.url + } + } + + // For albums, store gallery IDs in content field as a special structure + let postContent = data.content + if (data.type === 'album' && data.gallery) { + postContent = { + type: 'album', + gallery: data.gallery, + description: data.content + } + } + const post = await prisma.post.create({ data: { title: data.title, slug: data.slug, postType: data.type, status: data.status, - content: data.content, + content: postContent, excerpt: data.excerpt, linkUrl: data.link_url, + linkDescription: data.linkDescription, + featuredImage: featuredImageId, tags: data.tags, publishedAt: data.publishedAt } diff --git a/src/routes/api/posts/[id]/+server.ts b/src/routes/api/posts/[id]/+server.ts index 6789283..1a41e8b 100644 --- a/src/routes/api/posts/[id]/+server.ts +++ b/src/routes/api/posts/[id]/+server.ts @@ -57,6 +57,29 @@ export const PUT: RequestHandler = async (event) => { } } + // Handle album gallery updates + let featuredImageId = data.featuredImage + if (data.gallery && data.gallery.length > 0 && !featuredImageId) { + // Get the media URL for the first gallery item + const firstMedia = await prisma.media.findUnique({ + where: { id: data.gallery[0] }, + select: { url: true } + }) + if (firstMedia) { + featuredImageId = firstMedia.url + } + } + + // For albums, store gallery IDs in content field as a special structure + let postContent = data.content + if (data.type === 'album' && data.gallery) { + postContent = { + type: 'album', + gallery: data.gallery, + description: data.content + } + } + const post = await prisma.post.update({ where: { id }, data: { @@ -64,10 +87,13 @@ export const PUT: RequestHandler = async (event) => { slug: data.slug, postType: data.type, status: data.status, - content: data.content, + content: postContent, excerpt: data.excerpt, linkUrl: data.link_url, - tags: data.tags + linkDescription: data.linkDescription, + featuredImage: featuredImageId, + tags: data.tags, + publishedAt: data.publishedAt } })