Skip to content

Commit

Permalink
feat(json): save scan options for rescan
Browse files Browse the repository at this point in the history
  • Loading branch information
popstas committed Mar 13, 2021
1 parent dad7d54 commit 0d5fd47
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/actions/saveAsJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const columns = require('../presets/columns');
const defaultField = 'url';

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

Expand Down Expand Up @@ -35,6 +36,12 @@ module.exports = async (csvPath, jsonPath, lang, preset, defaultFilter) => {
// columns
data.columns = buildColumns(columns, preset);

data.scan = {
url: url,
args: args,
version: require('../../package.json').version,
}

// write
const raw = JSON.stringify(data);
fs.writeFileSync(jsonPath, raw);
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function start() {
}

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

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

Expand All @@ -52,6 +52,7 @@ async function start() {
}

const opts = program.getOptions();
opts.args = process.argv.slice(2);
program.outBrief(opts);

const sites = program.urls;
Expand Down
2 changes: 1 addition & 1 deletion src/scrap-site.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ module.exports = async (baseUrl, options = {}) => {
}

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

// user plugins
Expand Down
1 change: 1 addition & 0 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ async function onScan(url, args, socket) {
await program.postParse();

const opts = program.getOptions();
opts.args = args;
opts.webService = true;
opts.consoleValidate = false; // not needed
opts.socket = socket;
Expand Down

0 comments on commit 0d5fd47

Please sign in to comment.