File size: 2,088 Bytes
dacbd76 f4937a0 dacbd76 89753b1 dacbd76 fa78e21 89753b1 dacbd76 89753b1 dacbd76 89753b1 dacbd76 89753b1 f4937a0 fcaff4e f4937a0 fcaff4e f4937a0 fcaff4e f4937a0 fcaff4e 89753b1 dacbd76 55af944 f4937a0 89753b1 f4937a0 89753b1 dacbd76 89753b1 55af944 fa78e21 55af944 dacbd76 55af944 dacbd76 89753b1 dacbd76 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
import express from 'express'
import morgan from 'morgan'
import * as pup from 'puppeteer-real-browser'
import serveIndex from 'serve-index'
import { exec } from 'node:child_process'
import { tmpdir } from 'node:os'
import { setTimeout } from 'node:timers/promises'
import { format, promisify } from 'node:util'
const app = express()
const execPromise = promisify(exec)
app.set('json spaces', 2)
app.use(express.json({ limit: '200mb' }))
app.use(express.urlencoded({
extended: true,
limit: '200mb'
}))
app.use(morgan('dev'))
const tmpDir = tmpdir()
app.use(
tmpDir,
express.static(tmpDir),
serveIndex(
tmpDir,
{ hidden: true, icons: true }
)
)
app.all(
'/',
(_, res) => res.json({ msg: 'Hello World' })
)
app.get('/shell', async (req, res) => {
const { q = 'w' } = req.query
let o, output = ''
try {
o = await execPromise(q)
} catch (e) {
o = e
} finally {
const { stderr, stdout } = o
if (stderr)
output += `STDERR:\n${stderr}\n`
if (stdout)
output += `\nSTDOUT:\n${stdout}`
res.send(output.trim())
}
})
app.get('/ss', async (req, res) => {
const {
delay = 0,
full = false,
url = 'https://hf.co'
} = req.query
const conn = await pup.connect({
customConfig: {
executablePath: process.env.CHROME_BIN
},
// disableXvfb: true,
headless: 'new',
turnstile: true
})
try {
const page = conn.page
await page.goto(
url,
{ waitUntil: 'networkidle0'}
)
const name = format(
'%s/%s.png',
tmpDir,
Math.random().toString(36).slice(2)
)
if (/^\d$/.test(delay))
await setTimeout(+delay)
await page.screenshot({
fullPage: full,
path: name,
omitBackground: true
})
res.redirect(name)
} catch (e) {
console.error(e)
res
.status(500)
.json({
err: true,
msg: format(e?.message || e)
})
} finally {
await conn.browser.close()
}
})
const PORT = process.env.PORT || 7860
app.listen(
PORT,
() => console.log('App running on port', PORT)
) |