diff --git a/core/file_base_area.js b/core/file_base_area.js index e3887b84..e9926111 100644 --- a/core/file_base_area.js +++ b/core/file_base_area.js @@ -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( [ diff --git a/core/oputil/oputil_file_base.js b/core/oputil/oputil_file_base.js index 67962fc0..308d3581 100644 --- a/core/oputil/oputil_file_base.js +++ b/core/oputil/oputil_file_base.js @@ -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); diff --git a/core/oputil/oputil_help.js b/core/oputil/oputil_help.js index c3767c92..50bc3b5e 100644 --- a/core/oputil/oputil_help.js +++ b/core/oputil/oputil_help.js @@ -101,8 +101,12 @@ cat arguments: Actions: scan AREA_TAG[@STORAGE_TAG] Scan specified area - May contain optional GLOB as last parameter. - Example: ./oputil.js fb scan d0pew4r3z *.zip + 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 diff --git a/core/string_util.js b/core/string_util.js index cde7ac3e..2f6596c8 100644 --- a/core/string_util.js +++ b/core/string_util.js @@ -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); +} \ No newline at end of file