@@ -36,38 +36,38 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
3636 }
3737
3838 return res . status ( 400 ) . json ( { error : 'Missing URL' } ) ;
39- } else if ( req . method === 'POST' ) {
40- try {
41- const form = new formidable . IncomingForm ( ) ;
42- const data = await new Promise < Files > ( ( resolve , reject ) => {
43- form . parse ( req , ( err , fields , files ) => {
44- if ( err ) {
45- reject ( err ) ;
46- return ;
47- } else {
48- resolve ( {
49- file : files . file ,
50- } ) ;
51- }
52- } ) ;
53- } ) ;
39+ // } else if (req.method === 'POST') {
40+ // try {
41+ // const form = new formidable.IncomingForm();
42+ // const data = await new Promise<Files>((resolve, reject) => {
43+ // form.parse(req, (err, fields, files) => {
44+ // if (err) {
45+ // reject(err);
46+ // return;
47+ // } else {
48+ // resolve({
49+ // file: files.file,
50+ // });
51+ // }
52+ // });
53+ // });
5454
55- const uploadedFile = data [ 'file' ] ;
55+ // const uploadedFile = data['file'];
5656
57- if ( Array . isArray ( uploadedFile ) ) {
58- res . status ( 400 ) . json ( { error : 'Multiple files not supported' } ) ;
59- } else if ( uploadedFile . mimetype ?. includes ( 'pdf' ) ) {
60- const fileContentBuffer = await readFileAsync ( uploadedFile . filepath ) ;
61- const pdfData = await pdf ( fileContentBuffer ) ;
62- return res . status ( 200 ) . json ( { text : pdfData . text } ) ;
63- } else {
64- const fileContent = await readFileAsync ( uploadedFile . filepath , 'binary' ) ;
65- const fileContentStr = Buffer . from ( fileContent , 'binary' ) . toString ( 'utf-8' ) ;
66- return res . status ( 200 ) . json ( { text : fileContentStr } ) ;
67- }
68- } catch ( error ) {
69- return res . status ( 500 ) . json ( { error : 'Error processing the file' } ) ;
70- }
57+ // if (Array.isArray(uploadedFile)) {
58+ // return res.status(400).json({ error: 'Multiple files not supported' });
59+ // } else if (uploadedFile.mimetype?.includes('pdf')) {
60+ // const fileContentBuffer = await readFileAsync(uploadedFile.filepath);
61+ // const pdfData = await pdf(fileContentBuffer);
62+ // return res.status(200).json({ text: pdfData.text });
63+ // } else {
64+ // const fileContent = await readFileAsync(uploadedFile.filepath, 'binary');
65+ // const fileContentStr = Buffer.from(fileContent, 'binary').toString('utf-8');
66+ // return res.status(200).json({ text: fileContentStr });
67+ // }
68+ // } catch (error) {
69+ // return res.status(500).json({ error: 'Error processing the file' });
70+ // }
7171 } else {
7272 return res . status ( 405 ) . json ( { error : 'Method not allowed' } ) ;
7373 }
0 commit comments