Files
kestrelos/server/api/me/avatar.delete.js
Keli Grubb 0aab29ea72
All checks were successful
ci/woodpecker/push/push Pipeline was successful
minor: new nav system (#5)
Co-authored-by: Madison Grubb <madison@elastiflow.com>
Reviewed-on: #5
2026-02-15 04:04:54 +00:00

15 lines
546 B
JavaScript

import { unlink } from 'node:fs/promises'
import { join } from 'node:path'
import { getDb, getAvatarsDir } from '../../utils/db.js'
import { requireAuth } from '../../utils/authHelpers.js'
export default defineEventHandler(async (event) => {
const user = requireAuth(event)
if (!user.avatar_path) return { ok: true }
const path = join(getAvatarsDir(), user.avatar_path)
await unlink(path).catch(() => {})
const { run } = await getDb()
await run('UPDATE users SET avatar_path = NULL WHERE id = ?', [user.id])
return { ok: true }
})