Update index.js
Browse files
index.js
CHANGED
|
@@ -84,7 +84,15 @@ app.get('/qrcode', async (req, res) => {
|
|
| 84 |
} else if (['read', 'scan'].includes(mode)) {
|
| 85 |
// Fetch the image and read the QR code
|
| 86 |
const response = await fetch(url);
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
const image = await Jimp.read(buffer);
|
| 89 |
|
| 90 |
// Preprocess the image to enhance QR code readability
|
|
@@ -246,7 +254,7 @@ async function processScreenshot(req, res, {
|
|
| 246 |
'Content-Length': screenshot.length,
|
| 247 |
});
|
| 248 |
res.end(screenshot);
|
| 249 |
-
|
| 250 |
await browser.close();
|
| 251 |
} catch (e) {
|
| 252 |
log(e)
|
|
|
|
| 84 |
} else if (['read', 'scan'].includes(mode)) {
|
| 85 |
// Fetch the image and read the QR code
|
| 86 |
const response = await fetch(url);
|
| 87 |
+
if (!rts.ok || rts.status !== 200) return res.send({
|
| 88 |
+
status: 400,
|
| 89 |
+
message: 'Can\'t buffer url'
|
| 90 |
+
})
|
| 91 |
+
if (!/image/.test(rts.headers.get('content-type'))) return res.send({
|
| 92 |
+
status: 400,
|
| 93 |
+
message: 'Only image type'
|
| 94 |
+
})
|
| 95 |
+
const buffer = Buffer.from(await response.arrayBuffer());
|
| 96 |
const image = await Jimp.read(buffer);
|
| 97 |
|
| 98 |
// Preprocess the image to enhance QR code readability
|
|
|
|
| 254 |
'Content-Length': screenshot.length,
|
| 255 |
});
|
| 256 |
res.end(screenshot);
|
| 257 |
+
console.log('process done');
|
| 258 |
await browser.close();
|
| 259 |
} catch (e) {
|
| 260 |
log(e)
|