File size: 856 Bytes
6a20c17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import formidable from 'formidable';
import { promises as fs } from 'fs';
import path from 'path';
import { NotebookParser } from '../../lib/notebook-parser';

export const config = {
  api: {
    bodyParser: false,
  },
};

export default async function handler(req, res) {
  if (req.method !== 'POST') {
    return res.status(405).json({ error: 'Method not allowed' });
  }

  try {
    const form = new formidable.IncomingForm();
    const [, files] = await form.parse(req);
    const file = files.file[0];

    const parser = new NotebookParser();
    const parameters = await parser.parseNotebook(file.filepath);

    // Clean up temp file
    await fs.unlink(file.filepath);

    res.status(200).json({ parameters });
  } catch (error) {
    console.error('Parse error:', error);
    res.status(500).json({ error: 'Failed to parse notebook' });
  }
}