fix: uploads and contributions display

- Remove duplicate FamilyUploadSection (PhotoUploadSection already handles this)
- Fix contributions POST: don't require content for timeline/media types
- Save all fields (year, month, day, location, media_filenames) in contributions INSERT
- Add user-uploaded photos from contributions to public photo gallery
- Fix PhotoUploadSection to include title in submission

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
denshooter
2026-02-18 12:43:13 +01:00
parent 2fb6dd7279
commit 40ace3522c
3 changed files with 58 additions and 22 deletions
+34 -15
View File
@@ -126,11 +126,25 @@ JSON:`
export async function POST(request: Request) {
try {
const body = await request.json()
const { name, type, title, content, photoUrl, date, category } = body
const { name, type, title, content, year, month, day, location, media_filenames } = body
if (!content || !type) {
if (!type) {
return NextResponse.json(
{ error: 'Content and type are required' },
{ error: 'Type is required' },
{ status: 400 }
)
}
// Require content for memory type, title for timeline
if (type === 'memory' && !content) {
return NextResponse.json(
{ error: 'Content is required for memories' },
{ status: 400 }
)
}
if (type === 'timeline' && !title) {
return NextResponse.json(
{ error: 'Title is required for timeline entries' },
{ status: 400 }
)
}
@@ -138,30 +152,35 @@ export async function POST(request: Request) {
const db = getDb()
// 1. Check bad words instantly - clean content is auto-approved
const badWordCheck = hasBadWords(content + ' ' + (title || ''))
const textToCheck = [content, title].filter(Boolean).join(' ')
const badWordCheck = textToCheck ? hasBadWords(textToCheck) : { flag: false }
const initialStatus = badWordCheck.flag ? 'flagged' : 'approved'
const moderationReason = badWordCheck.flag ? badWordCheck.reason : null
const moderationReason = badWordCheck.flag ? (badWordCheck as any).reason : null
// 2. Insert contribution
// 2. Insert contribution with all fields
const result = db.prepare(`
INSERT INTO contributions (name, type, title, content, status, moderation_reason)
VALUES (?, ?, ?, ?, ?, ?)
INSERT INTO contributions (name, type, title, content, year, month, day, location, media_filenames, status, moderation_reason)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`).run(
name || 'Anonym',
type,
title || null,
content,
content || null,
year || null,
month || null,
day || null,
location || null,
media_filenames || null,
initialStatus,
moderationReason || null
)
const contributionId = Number(result.lastInsertRowid)
console.log(`[API] Created contribution ${contributionId}, status: ${initialStatus}`)
console.log(`[API] Created contribution ${contributionId}, type: ${type}, status: ${initialStatus}`)
// 3. If not already flagged, run AI check in background
if (!badWordCheck.flag) {
// Fire and forget - don't await
moderateWithAI(contributionId, content).catch(e =>
// 3. If not already flagged and has text, run AI check in background
if (!badWordCheck.flag && textToCheck) {
moderateWithAI(contributionId, textToCheck).catch(e =>
console.error('[AI-Mod] Background error:', e)
)
}
@@ -169,7 +188,7 @@ export async function POST(request: Request) {
return NextResponse.json({
success: true,
id: contributionId,
message: 'Beitrag wurde gespeichert und wird geprüft'
message: 'Beitrag wurde gespeichert'
})
} catch (error) {