|
| 1 | +//Setup |
| 2 | + export default async function({login, q, imports, data, account}, {enabled = false} = {}) { |
| 3 | + //Plugin execution |
| 4 | + try { |
| 5 | + //Check if plugin is enabled and requirements are met |
| 6 | + if ((!enabled)||(!q.skyline)) |
| 7 | + return null |
| 8 | + |
| 9 | + //Load inputs |
| 10 | + let {year, frames} = imports.metadata.plugins.skyline.inputs({data, account, q}) |
| 11 | + if (Number.isNaN(year)) { |
| 12 | + year = new Date().getFullYear() |
| 13 | + console.debug(`metrics/compute/${login}/plugins > skyline > year set to ${year}`) |
| 14 | + } |
| 15 | + const width = 454 |
| 16 | + const height = 284 |
| 17 | + |
| 18 | + //Start puppeteer and navigate to skyline.github.com |
| 19 | + console.debug(`metrics/compute/${login}/plugins > skyline > starting browser`) |
| 20 | + const browser = await imports.puppeteer.launch({headless:true, executablePath:process.env.PUPPETEER_BROWSER_PATH, args:["--no-sandbox", "--disable-extensions", "--disable-setuid-sandbox", "--disable-dev-shm-usage"]}) |
| 21 | + console.debug(`metrics/compute/${login}/plugins > skyline > started ${await browser.version()}`) |
| 22 | + const page = await browser.newPage() |
| 23 | + await page.setViewport({width, height}) |
| 24 | + |
| 25 | + //Load page |
| 26 | + console.debug(`metrics/compute/${login}/plugins > skyline > loading skyline.github.com/${login}/${year}`) |
| 27 | + await page.goto(`https://skyline.github.com/${login}/${year}`, {timeout:90*1000}) |
| 28 | + console.debug(`metrics/compute/${login}/plugins > skyline > waiting for initial render`) |
| 29 | + const frame = page.mainFrame() |
| 30 | + await page.waitForFunction('[...document.querySelectorAll("span")].map(span => span.innerText).includes("Download STL file")', {timeout:90*1000}) |
| 31 | + await frame.evaluate(() => [...document.querySelectorAll("button, footer, a")].map(element => element.remove())) |
| 32 | + |
| 33 | + //Generate gif |
| 34 | + console.debug(`metrics/compute/${login}/plugins > skyline > generating frames`) |
| 35 | + const framed = await imports.puppeteergif({page, width, height, frames, scale:0.5}) |
| 36 | + |
| 37 | + //Close puppeteer |
| 38 | + await browser.close() |
| 39 | + |
| 40 | + //Results |
| 41 | + return {frames:framed} |
| 42 | + } |
| 43 | + //Handle errors |
| 44 | + catch (error) { |
| 45 | + throw {error:{message:"An error occured", instance:error}} |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + |
0 commit comments