Files
kestrelos/server/api/me/avatar.delete.js
Madison Grubb 4e51ca5509
All checks were successful
ci/woodpecker/pr/pr Pipeline was successful
new nav system
2026-02-14 22:47:05 -05: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 }
})