feat: initial brainstorming app — Nuxt 3 + SQLite + admin auth
Nuxt 3 app with: - SQLite (better-sqlite3) for persistence - Anonymous idea submission and voting - Admin auth with session cookies - AI analysis via Gemini API - Nuxt UI components + Tailwind Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
19
server/api/votes/[id].post.ts
Normal file
19
server/api/votes/[id].post.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { createHash } from 'crypto'
|
||||
import db from '../../utils/db'
|
||||
|
||||
export default defineEventHandler((event) => {
|
||||
const id = getRouterParam(event, 'id')
|
||||
const ip = getRequestIP(event, { xForwardedFor: true }) || 'unknown'
|
||||
const voterHash = createHash('sha256').update(ip + ':' + id).digest('hex')
|
||||
|
||||
try {
|
||||
db.prepare('INSERT INTO vote_log (idea_id, voter_hash) VALUES (?, ?)').run(id, voterHash)
|
||||
db.prepare('UPDATE ideas SET votes = votes + 1 WHERE id = ?').run(id)
|
||||
} catch {
|
||||
// UNIQUE constraint = already voted
|
||||
throw createError({ statusCode: 409, statusMessage: 'Already voted' })
|
||||
}
|
||||
|
||||
const row = db.prepare('SELECT votes FROM ideas WHERE id = ?').get(id) as any
|
||||
return { votes: row?.votes ?? 0 }
|
||||
})
|
||||
Reference in New Issue
Block a user