Add Ability to Import All File Areas at Once #271
* Simple wildcard support for area tags param
This commit is contained in:
parent
d6dce82a92
commit
14f7ca9dcc
|
@ -17,6 +17,7 @@ const StatLog = require('./stat_log.js');
|
||||||
const UserProps = require('./user_property.js');
|
const UserProps = require('./user_property.js');
|
||||||
const SysProps = require('./system_property.js');
|
const SysProps = require('./system_property.js');
|
||||||
const SAUCE = require('./sauce.js');
|
const SAUCE = require('./sauce.js');
|
||||||
|
const { wildcardMatch } = require('./string_util');
|
||||||
|
|
||||||
// deps
|
// deps
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
@ -40,6 +41,7 @@ exports.getAreaDefaultStorageDirectory = getAreaDefaultStorageDirectory;
|
||||||
exports.getAreaStorageLocations = getAreaStorageLocations;
|
exports.getAreaStorageLocations = getAreaStorageLocations;
|
||||||
exports.getDefaultFileAreaTag = getDefaultFileAreaTag;
|
exports.getDefaultFileAreaTag = getDefaultFileAreaTag;
|
||||||
exports.getFileAreaByTag = getFileAreaByTag;
|
exports.getFileAreaByTag = getFileAreaByTag;
|
||||||
|
exports.getFileAreasByTagWildcardRule = getFileAreasByTagWildcardRule;
|
||||||
exports.getFileEntryPath = getFileEntryPath;
|
exports.getFileEntryPath = getFileEntryPath;
|
||||||
exports.changeFileAreaWithOptions = changeFileAreaWithOptions;
|
exports.changeFileAreaWithOptions = changeFileAreaWithOptions;
|
||||||
exports.scanFile = scanFile;
|
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) {
|
function changeFileAreaWithOptions(client, areaTag, options, cb) {
|
||||||
async.waterfall(
|
async.waterfall(
|
||||||
[
|
[
|
||||||
|
|
|
@ -521,7 +521,24 @@ function scanFileAreas() {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function scanAreas(callback) {
|
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) => {
|
async.eachSeries(options.areaAndStorageInfo, (areaAndStorage, nextAreaTag) => {
|
||||||
const areaInfo = fileArea.getFileAreaByTag(areaAndStorage.areaTag);
|
const areaInfo = fileArea.getFileAreaByTag(areaAndStorage.areaTag);
|
||||||
|
|
|
@ -101,8 +101,12 @@ cat arguments:
|
||||||
Actions:
|
Actions:
|
||||||
scan AREA_TAG[@STORAGE_TAG] Scan specified area
|
scan AREA_TAG[@STORAGE_TAG] Scan specified area
|
||||||
|
|
||||||
May contain optional GLOB as last parameter.
|
Tips:
|
||||||
Example: ./oputil.js fb scan d0pew4r3z *.zip
|
- 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
|
info CRITERIA Display information about areas and/or files
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ exports.isAnsi = isAnsi;
|
||||||
exports.isAnsiLine = isAnsiLine;
|
exports.isAnsiLine = isAnsiLine;
|
||||||
exports.isFormattedLine = isFormattedLine;
|
exports.isFormattedLine = isFormattedLine;
|
||||||
exports.splitTextAtTerms = splitTextAtTerms;
|
exports.splitTextAtTerms = splitTextAtTerms;
|
||||||
|
exports.wildcardMatch = wildcardMatch;
|
||||||
|
|
||||||
// :TODO: create Unicode version of this
|
// :TODO: create Unicode version of this
|
||||||
const VOWELS = [
|
const VOWELS = [
|
||||||
|
@ -474,3 +475,8 @@ function isAnsi(input) {
|
||||||
function splitTextAtTerms(s) {
|
function splitTextAtTerms(s) {
|
||||||
return s.split(/\r\n|[\n\v\f\r\x85\u2028\u2029]/g);
|
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);
|
||||||
|
}
|
Loading…
Reference in New Issue