auths
objectTake a screenshot of this URL
return
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps, params, auths) => {
}
const axios = require('axios')
const type = params.type || 'png'
const config = {
method: 'GET',
url: 'https://ssfy.sh/dev/puppet-master@6cc8d95d/screenshot',
params: {
url: params.url,
type,
fullPage: params.fullPage,
omitBackground: params.omitBackground,
clip: params.clip,
gotoOptions: params.gotoOptions,
viewport: params.viewport,
userAgent: params.userAgent,
emulateDevice: params.emulateDevice,
},
responseType: 'arraybuffer',
}
// If you get rate limited, you can sign up for an API key here:
// https://puppet-master.sh/pricing
if (params.api_key) config.headers['Authorization'] = params.api_key
const resp = await axios(config)
this.screenshot = resp.data.toString('base64')
// Export the rate limit data for debugging
const { headers } = resp
this.remaining_rate_limit = headers["x-ratelimit-remaining"]
this.rate_limit_reset_in = `Rate limit resets in ${(((headers["x-ratelimit-reset"] * 1000) - +new Date()) / 1000 / 60)} minutes`
// Pass the URL to the next step as the filename
this.url = params.url
this.type = type
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps, params, auths) => {
}
const AWS = require("aws-sdk")
const { bucket } = params
const { url, screenshot, type } = steps.take_screenshot
const { accessKeyId, secretAccessKey } = auths.aws
const s3 = new AWS.S3({
accessKeyId,
secretAccessKey,
})
// Store screenshot at object tied to site + current epoch
const Key = `${url.replace(/[&\/\\#, +()$~%.'":*?<>{}]/g, '_')}-${+new Date()}.${type}`
const uploadParams = {
Bucket: bucket,
Key,
Body: Buffer.from(screenshot, 'base64'),
ContentType: `image/${type}`
}
this.S3Response = await s3.upload(uploadParams).promise()
console.log(`Uploaded file to S3!`)