Skip to content

Commit

Permalink
feat: --default-filter
Browse files Browse the repository at this point in the history
  • Loading branch information
popstas committed Nov 27, 2020
1 parent d79aab0 commit 02b0129
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/actions/saveAsJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const columns = require('../presets/columns');

const defaultField = 'url';

module.exports = async (csvPath, jsonPath, lang, preset) => {
module.exports = async (csvPath, jsonPath, lang, preset, defaultFilter) => {
// read csv to workbook
const data = {};

Expand All @@ -19,6 +19,17 @@ module.exports = async (csvPath, jsonPath, lang, preset) => {

// filters
data.filters = filters;
if (defaultFilter) {
const found = data.filters.find(f => f.q === defaultFilter);
if (found) found.default = true;
else {
data.filters.push({
name: defaultFilter,
q: defaultFilter,
default: true
});
}
}

// columns
data.columns = buildColumns(columns, preset);
Expand Down
2 changes: 1 addition & 1 deletion src/actions/uploadJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = async (jsonPath, options) => {
replace('T', '_').
replace('Z', '');
// const dateStr = date.slice(0,10);
const name = path.basename(jsonPath).replace(/[^0-9a-zа-я_-.]/ig, '');
const name = path.basename(jsonPath).replace(/[^0-9a-zа-я_.-]/ig, '');
const uploadName = date + '_' + name;

console.log('\nUploading to https://site-audit.viasite.ru...');
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ program.option('-u --urls <urls>', 'Comma separated url list for scan', list).
option('-f, --fields <json>',
'Field in format --field \'title=$("title").text()\'', fieldsCustomCollect,
[]).
option('--default-filter <defaultFilter>', 'Default filter when JSON viewed, example: depth>1').
option('--no-skip-static', `Scan static files`).
option('--no-limit-domain', `Scan not only current domain`).
option('--docs-extensions',
Expand Down Expand Up @@ -234,6 +235,7 @@ async function start() {
lang: program.lang, // язык
openFile: program.openFile, // открыть файл после сканирования
fields: program.fields, // дополнительные поля, --fields 'title=$("title").text()'
defaultFilter: program.defaultFilter, //
removeCsv: program.removeCsv, // удалять csv после генерации xlsx
removeJson: program.removeJson, // удалять json после поднятия сервера
xlsx: program.xlsx, // сохранять в XLSX
Expand Down
2 changes: 1 addition & 1 deletion src/scrap-site.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ module.exports = async (baseUrl, options = {}) => {
}

if (options.json) {
await saveAsJson(csvPath, jsonPath, options.lang, options.preset);
await saveAsJson(csvPath, jsonPath, options.lang, options.preset, options.defaultFilter);
if (!options.removeJson) console.log('Saved to ' + jsonPath);
if (options.upload) webPath = await uploadJson(jsonPath, options);
// if (options.gdrive) webPath = await publishGoogleDrive(jsonPath);
Expand Down

0 comments on commit 02b0129

Please sign in to comment.