File size: 1,073 Bytes
8aad435
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
router.post('/bco', async (ctx) => {
    const { request, response } = ctx;
    const q = await request.body().value;
    const ret = await process(q)

    console.error(`ret: ${ret}`)
    response.body = ret
})

function process(o: { id: int, url: string, bco: string, name: string }): Promise<void> {
    const promises: Promise<void>[] = [];

    return puppet.run(async page => {
        const url = o.url.replace('http:', 'https:');
        promises.push(new Promise<void>((accept, _reject) => {
            page.once('load', async () => {
                const dest = `./data/images/${e.bco}.chrome.full.png`
                await fetch_logos(page, bco.name, dest)
                await page.screenshot({ path: dest, fullPage: true })
                console.log(`screenshot ok for ${o.name}`);

                accept()
            })
        }))

        try {
            await page.goto(url)
                .catch(() => page.goto(o.url))
        } catch (e) {
            console.error(`got error: ${e}`);
        }
        await Promise.all(promises);
    })
}