-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimage.js
More file actions
45 lines (33 loc) · 1.29 KB
/
image.js
File metadata and controls
45 lines (33 loc) · 1.29 KB
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
const path = require("path");
const os = require("os");
const si = require("systeminformation");
const puppeteer = require("puppeteer");
const { durationFormatter, sizeFormatter } = require("human-readable");
const config = require("./config");
const promise = (async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.exposeFunction("formatDur", durationFormatter());
await page.exposeFunction("formatSize", sizeFormatter({ std: "IEC" }));
return page;
})();
module.exports = async () => {
const page = await promise;
let data = {};
await page.goto(`file://${path.resolve("./views/" + config.image.sample)}`);
data.user = os.userInfo();
data.loadavg = os.loadavg();
data.env = process.env;
data.graphics = await si.graphics();
data.os = await si.osInfo();
data.system = await si.system();
data.cpu = await si.cpu();
data.time = await si.time();
data.mem = await si.mem();
data.currentLoad = await si.currentLoad();
data.temp = await si.cpuTemperature();
data.fsSize = await si.fsSize();
await page.evaluate(data => render(data), data);
const container = await page.$(config.image.select);
return await container.screenshot({ type: "jpeg", quality: 100 });
};