Reubencf's picture
open close
ad31128
import { NextRequest, NextResponse } from 'next/server'
import fs from 'fs/promises'
import path from 'path'
export async function DELETE(request: NextRequest) {
try {
const { documentId, sessionId } = await request.json()
if (!documentId || !sessionId) {
return NextResponse.json(
{ error: 'Document ID and session ID are required' },
{ status: 400 }
)
}
// Get session-specific file path
const filePath = path.join(
process.cwd(),
'data',
'sessions',
sessionId,
'latex',
`${documentId}.json`
)
// Check if file exists and delete it
try {
await fs.access(filePath)
await fs.unlink(filePath)
} catch (error) {
console.log('File not found or already deleted')
}
return NextResponse.json({
success: true,
documentId,
sessionId
})
} catch (error) {
console.error('Error deleting LaTeX document:', error)
return NextResponse.json(
{ error: 'Failed to delete document' },
{ status: 500 }
)
}
}