File size: 1,072 Bytes
ad31128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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 }
    )
  }
}