aripbae commited on
Commit
55af944
·
verified ·
1 Parent(s): a2f1132

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +26 -8
index.js CHANGED
@@ -34,24 +34,42 @@ app.all(
34
  )
35
 
36
  app.get('/ss', async (req, res) => {
37
- const { url = process.env.SPACE_HOST } = req.query
 
 
 
 
38
  const browser = await puppeteer.launch({
39
  executablePath: process.env.CHROME_BIN,
40
  headless: 'new'
41
  })
42
  try {
43
  const page = await browser.newPage()
44
- await page.goto(url)
45
- const name =
46
- tmpDir + '/' +
47
- Math.random().toString(36).slice(2) + '.jpg'
48
- const ss = await page.screenshot({ path: name })
49
- res.status(200).redirect(name)
 
 
 
 
 
 
 
 
 
 
 
50
  } catch (e) {
51
  console.error(e)
52
  res
53
  .status(500)
54
- .json({ error: true, msg: format(e) })
 
 
 
55
  } finally {
56
  await browser.close()
57
  }
 
34
  )
35
 
36
  app.get('/ss', async (req, res) => {
37
+ const {
38
+ delay = 0,
39
+ full = false,
40
+ url = 'https://hf.co'
41
+ } = req.query
42
  const browser = await puppeteer.launch({
43
  executablePath: process.env.CHROME_BIN,
44
  headless: 'new'
45
  })
46
  try {
47
  const page = await browser.newPage()
48
+ await page.goto(
49
+ url,
50
+ { waitUntil: 'networkidle0'}
51
+ )
52
+ const name = format(
53
+ '%s/%s.png',
54
+ tmpDir,
55
+ Math.random().toString(36).slice(2)
56
+ )
57
+ if (/^\d$/.test(delay))
58
+ await page.waitForTimeout(+delay)
59
+ await page.screenshot({
60
+ fullPage: full,
61
+ path: name,
62
+ omitBackground: true
63
+ })
64
+ res.redirect(name)
65
  } catch (e) {
66
  console.error(e)
67
  res
68
  .status(500)
69
+ .json({
70
+ err: true,
71
+ msg: format(e?.message || e)
72
+ })
73
  } finally {
74
  await browser.close()
75
  }