ConusAI vendor v0.1.0-dev.20261013+85463d22
This commit is contained in:
parent
c3c6526952
commit
0da8a2a81b
@@ -3,16 +3,25 @@
|
||||
import { revalidatePath } from 'next/cache'
|
||||
import { fileRepository } from '@/entities/file'
|
||||
import { noteId } from '@/entities/note'
|
||||
import { audit, blob, db } from '@/shared/api'
|
||||
import { audit, blob, db, logger } from '@/shared/api'
|
||||
import { ensureVisitor } from '@/shared/lib/visitor-session'
|
||||
|
||||
/** Remove an attachment the visitor attached: its row first, then its stored bytes. */
|
||||
export async function deleteFile(id: string): Promise<void> {
|
||||
const key = noteId.parse(id)
|
||||
const actor = await ensureVisitor()
|
||||
const removed = await fileRepository(db()).remove(key, actor)
|
||||
if (!removed) return
|
||||
await blob().del(removed.url)
|
||||
await audit().log('file.deleted', { actor: { kind: 'human', id: actor }, target: { id: key } })
|
||||
revalidatePath('/')
|
||||
try {
|
||||
const key = noteId.parse(id)
|
||||
const actor = await ensureVisitor()
|
||||
const removed = await fileRepository(db()).remove(key, actor)
|
||||
if (!removed) {
|
||||
logger()?.info('file.deleted', { 'file.id': key, outcome: 'denied' })
|
||||
return
|
||||
}
|
||||
await blob().del(removed.url)
|
||||
await audit().log('file.deleted', { actor: { kind: 'human', id: actor }, target: { id: key } })
|
||||
logger()?.info('file.deleted', { 'file.id': key, outcome: 'ok' })
|
||||
revalidatePath('/')
|
||||
} catch (error) {
|
||||
logger()?.recordException(error, { 'conusai.action': 'file.deleted', 'file.id': id })
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user