Skip to content

Commit

Permalink
feat: save report scan time
Browse files Browse the repository at this point in the history
  • Loading branch information
popstas committed Apr 21, 2021
1 parent 2b752c9 commit 05dc3af
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ SERVER_URL=http://localhost:5301
FRONTEND_URL=http://localhost:5302
SCAN_DEFAULT_MAX_REQUESTS=0
YAKE_SERVER_URL=http://yake:5000/yake/
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
# PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
3 changes: 2 additions & 1 deletion src/actions/saveAsJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const defaultField = 'url';

// return json object
// TODO: too much arguments
module.exports = async (csvPath, jsonPath, lang, preset, defaultFilter, url, args) => {
module.exports = async (csvPath, jsonPath, lang, preset, defaultFilter, url, args, scanTime) => {
// read csv to workbook
const data = {};

Expand Down Expand Up @@ -40,6 +40,7 @@ module.exports = async (csvPath, jsonPath, lang, preset, defaultFilter, url, arg
url: url,
args: args,
version: require('../../package.json').version,
time: scanTime,
}

// write
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ async function start() {
await program.postParse();

// convert csv and exit
// TODO: legacy, remove it!
if (program.csv) {
program.removeCsv = false;
const csvPath = expandHomedir(program.csv);
Expand All @@ -32,7 +33,7 @@ async function start() {
}

if (program.json) {
await saveAsJson(csvPath, jsonPath, program.lang, program.preset, false, program.urls[0], args);
await saveAsJson(csvPath, jsonPath, program.lang, program.preset, false, program.urls[0], args, 0);

if (program.upload) webPath = await uploadJson(jsonPath);

Expand Down
10 changes: 5 additions & 5 deletions src/scrap-site.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,8 @@ module.exports = async (baseUrl, options = {}) => {
await crawler.close();

// after scan
const t = Math.round((Date.now() - start) / 1000);
const perPage = Math.round((t / requestedCount) * 100) / 100;
const scanTime = Math.round((Date.now() - start) / 1000);
const perPage = Math.round((scanTime / requestedCount) * 100) / 100;

// close lighthouse's chrome
await chromeLauncher.killAll();
Expand Down Expand Up @@ -592,7 +592,7 @@ module.exports = async (baseUrl, options = {}) => {
}

if (options.json) {
await saveAsJson(csvPath, jsonPath, options.lang, options.preset, options.defaultFilter, baseUrl, options.args);
await saveAsJson(csvPath, jsonPath, options.lang, options.preset, options.defaultFilter, baseUrl, options.args, scanTime);
if (!options.removeJson) console.log('Saved to ' + jsonPath);

// user plugins
Expand All @@ -616,7 +616,7 @@ module.exports = async (baseUrl, options = {}) => {
socketSend(options.socket, 'result', {json: webPath});
}

const mins = Number(t / 60).toFixed(1);
const mins = Number(scanTime / 60).toFixed(1);
log(`Finish: ${mins} mins (${perPage} sec per page)`, options.socket);

// return stats
Expand All @@ -632,7 +632,7 @@ module.exports = async (baseUrl, options = {}) => {

if (options.removeCsv) fs.unlinkSync(csvPath);

const mins = Number(t / 60).toFixed(1);
const mins = Number(scanTime / 60).toFixed(1);
log(`Finish: ${mins} mins (${perPage} sec per page)`, options.socket);
};

Expand Down

0 comments on commit 05dc3af

Please sign in to comment.