Add Ability to Import All File Areas at Once #271

* Simple wildcard support for area tags param
This commit is contained in:
Bryan Ashby 2020-05-07 20:02:12 -06:00
parent d6dce82a92
commit 14f7ca9dcc
No known key found for this signature in database
GPG Key ID: B49EB437951D2542
4 changed files with 41 additions and 3 deletions

View File

@ -17,6 +17,7 @@ const StatLog = require('./stat_log.js');
const UserProps = require('./user_property.js');
const SysProps = require('./system_property.js');
const SAUCE = require('./sauce.js');
const { wildcardMatch } = require('./string_util');
// deps
const _ = require('lodash');
@ -40,6 +41,7 @@ exports.getAreaDefaultStorageDirectory = getAreaDefaultStorageDirectory;
exports.getAreaStorageLocations = getAreaStorageLocations;
exports.getDefaultFileAreaTag = getDefaultFileAreaTag;
exports.getFileAreaByTag = getFileAreaByTag;
exports.getFileAreasByTagWildcardRule = getFileAreasByTagWildcardRule;
exports.getFileEntryPath = getFileEntryPath;
exports.changeFileAreaWithOptions = changeFileAreaWithOptions;
exports.scanFile = scanFile;
@ -143,6 +145,15 @@ function getFileAreaByTag(areaTag) {
}
}
function getFileAreasByTagWildcardRule(rule) {
const areaTags = Object.keys(Config().fileBase.areas)
.filter(areaTag => {
return !isInternalArea(areaTag) && wildcardMatch(areaTag, rule);
});
return areaTags.map(areaTag => getFileAreaByTag(areaTag));
}
function changeFileAreaWithOptions(client, areaTag, options, cb) {
async.waterfall(
[

View File

@ -521,7 +521,24 @@ function scanFileAreas() {
});
},
function scanAreas(callback) {
fileArea = require('../../core/file_base_area.js');
fileArea = require('../../core/file_base_area');
// Further expand any wildcards
let areaAndStorageInfoExpanded = [];
options.areaAndStorageInfo.forEach(info => {
if (info.areaTag.indexOf('*') > -1) {
const areas = fileArea.getFileAreasByTagWildcardRule(info.areaTag);
areas.forEach(area => {
areaAndStorageInfoExpanded.push(Object.assign({}, info, {
areaTag : area.areaTag,
}));
});
} else {
areaAndStorageInfoExpanded.push(info);
}
});
options.areaAndStorageInfo = areaAndStorageInfoExpanded;
async.eachSeries(options.areaAndStorageInfo, (areaAndStorage, nextAreaTag) => {
const areaInfo = fileArea.getFileAreaByTag(areaAndStorage.areaTag);

View File

@ -101,9 +101,13 @@ cat arguments:
Actions:
scan AREA_TAG[@STORAGE_TAG] Scan specified area
May contain optional GLOB as last parameter.
Tips:
- May contain optional GLOB as last parameter.
Example: ./oputil.js fb scan d0pew4r3z *.zip
- AREA_TAG may contain simple wildcards.
Example: ./oputil.js fb scan *warez*
info CRITERIA Display information about areas and/or files
mv SRC [SRC...] DST Move matching entry(s)

View File

@ -29,6 +29,7 @@ exports.isAnsi = isAnsi;
exports.isAnsiLine = isAnsiLine;
exports.isFormattedLine = isFormattedLine;
exports.splitTextAtTerms = splitTextAtTerms;
exports.wildcardMatch = wildcardMatch;
// :TODO: create Unicode version of this
const VOWELS = [
@ -474,3 +475,8 @@ function isAnsi(input) {
function splitTextAtTerms(s) {
return s.split(/\r\n|[\n\v\f\r\x85\u2028\u2029]/g);
}
function wildcardMatch(input, rule) {
const escapeRegex = (s) => s.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
return new RegExp("^" + rule.split("*").map(escapeRegex).join(".*") + "$").test(input);
}