simoncck commited on
Commit
e67626f
·
verified ·
1 Parent(s): f0dc812

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +11 -11
server.js CHANGED
@@ -47,19 +47,19 @@ async function extract(url, res){
47
  app.get ('/extract',(req,res)=>extract(req.query.url,res));
48
  app.post('/extract',(req,res)=>extract(req.body.url,res));
49
 
50
- /* POST /login { "key": "secret" } */
51
- app.post('/login', async (req, res) => {
52
- /* if (TOKEN && req.body.key !== TOKEN)
53
- return res.status(401).json({ error: 'unauthorized' });*/
54
 
55
- // optional: debounce so two calls don't overlap
56
- if (app.locals.running) return res.status(429).json({ error: 'busy' });
57
- app.locals.running = true;
58
 
59
- const result = await runLogin();
60
- app.locals.running = false;
61
-
62
- res.json(result);
 
63
  });
64
 
65
  console.log('🛰️ Public URL will be:', HOSTNAME);
 
47
  app.get ('/extract',(req,res)=>extract(req.query.url,res));
48
  app.post('/extract',(req,res)=>extract(req.body.url,res));
49
 
50
+ /* POST /login { ok, screenshot_b64 } */
51
+ app.post('/login', async (_req, res) => {
52
+ const out = await runLogin();
 
53
 
54
+ if (!out.ok) {
55
+ return res.status(500).json(out);
56
+ }
57
 
58
+ const b64 = out.png.toString('base64');
59
+ res.json({
60
+ ok: true,
61
+ screenshot_b64: 'data:image/png;base64,' + b64.slice(0), // ready for <img src=...>
62
+ });
63
  });
64
 
65
  console.log('🛰️ Public URL will be:', HOSTNAME);