Skip to content

Commit

Permalink
Update scanProduct.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
BurhanCantCode authored Aug 3, 2024
1 parent 15cabaf commit 99a655d
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions pages/api/scanProduct.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import type { NextApiRequest, NextApiResponse } from 'next'
import { scanProduct } from '../../utils/visionUtils';
import path from 'path';

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
if (req.method === 'POST') {
try {
let credentialsPath = process.env.GOOGLE_APPLICATION_CREDENTIALS;
if (credentialsPath) {
credentialsPath = path.resolve(process.cwd(), credentialsPath);
}

const { imageData } = req.body;
console.log('Received image data length:', imageData.length);
console.log('Using credentials file:', credentialsPath);
const result = await scanProduct(imageData);
console.log('Scan result:', result);
res.status(200).json({
...result,
allLabels: result.allLabels || []
});
res.status(200).json(result);
} catch (error) {
console.error('Error in scanProduct API:', error);
res.status(500).json({ error: 'Failed to scan product' });
Expand All @@ -27,4 +17,4 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
res.setHeader('Allow', ['POST']);
res.status(405).end(`Method ${req.method} Not Allowed`);
}
}
}

0 comments on commit 99a655d

Please sign in to comment.