Spaces:
Build error
Build error
| 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' }); | |
| } | |
| } |