* Fix up and improve oputil file-base stuff

* Specialize if user does not have upload ACS
This commit is contained in:
Bryan Ashby 2017-02-08 22:53:48 -07:00
parent 1f879c8bfb
commit a257a9ba4b
6 changed files with 49 additions and 19 deletions

View File

@ -3,7 +3,7 @@ For :bug: bug reports, please fill out the information below plus any additional
**Short problem description**
**Environment**
- [ ] I am using Node.js v4.x or higher
- [ ] I am using Node.js v6.x or higher
- [ ] `npm install` reports success
- Actual Node.js version (`node --version`):
- Operating system (`uname -a` on *nix systems):

View File

@ -238,6 +238,13 @@ function attemptSetEstimatedReleaseDate(fileEntry) {
}
}
// a simple log proxy for when we call from oputil.js
function logDebug(obj, msg) {
if(Log) {
Log.debug(obj, msg);
}
}
function populateFileEntryWithArchive(fileEntry, filePath, stepInfo, iterator, cb) {
const archiveUtil = ArchiveUtil.getInstance();
const archiveType = fileEntry.meta.archive_type; // we set this previous to populateFileEntryWithArchive()
@ -334,7 +341,7 @@ function populateFileEntryWithArchive(fileEntry, filePath, stepInfo, iterator, c
const maxFileSizeKey = `max${_.upperFirst(descType)}FileByteSize`;
if(Config.fileBase[maxFileSizeKey] && stats.size > Config.fileBase[maxFileSizeKey]) {
Log.debug( { byteSize : stats.size, maxByteSize : Config.fileBase[maxFileSizeKey] }, `Skipping "${descType}"; Too large` );
logDebug( { byteSize : stats.size, maxByteSize : Config.fileBase[maxFileSizeKey] }, `Skipping "${descType}"; Too large` );
return next(null);
}
@ -355,7 +362,7 @@ function populateFileEntryWithArchive(fileEntry, filePath, stepInfo, iterator, c
// cleanup but don't wait
temptmp.cleanup( paths => {
// note: don't use client logger here - may not be avail
Log.debug( { paths : paths, sessionId : temptmp.sessionId }, 'Cleaned up temporary files' );
logDebug( { paths : paths, sessionId : temptmp.sessionId }, 'Cleaned up temporary files' );
});
return callback(null);
});
@ -571,7 +578,12 @@ function scanFile(filePath, options, iterator, cb) {
);
}
function scanFileAreaForChanges(areaInfo, cb) {
function scanFileAreaForChanges(areaInfo, iterator, cb) {
if(!cb && _.isFunction(iterator)) {
cb = iterator;
iterator = null;
}
const storageLocations = getAreaStorageLocations(areaInfo);
async.eachSeries(storageLocations, (storageLoc, nextLocation) => {
@ -604,6 +616,7 @@ function scanFileAreaForChanges(areaInfo, cb) {
areaTag : areaInfo.areaTag,
storageTag : storageLoc.storageTag
},
iterator,
(err, fileEntry, dupeEntries) => {
if(err) {
// :TODO: Log me!!!

View File

@ -55,7 +55,7 @@ areas: {
desc: Oldschool PC/DOS
storageTags: [ "retro_pc", "retro_pc_bbs" ]
acs: {
write: GM[users] /* optional, see Uploads below */
write: GM[users] /* optional, see ACS below */
}
}
}

View File

@ -1,7 +1,6 @@
#!/usr/bin/env node
/* jslint node: true */
'use strict';
/*

View File

@ -122,11 +122,14 @@ exports.getModule = class UploadModule extends MenuModule {
}
getSaveState() {
return {
uploadType : this.uploadType,
tempRecvDirectory : this.tempRecvDirectory,
areaInfo : this.availAreas[ this.viewControllers.options.getView(MciViewIds.options.area).getData() ],
};
// if no areas, we're falling back due to lack of access/areas avail to upload to
if(this.availAreas.length > 0) {
return {
uploadType : this.uploadType,
tempRecvDirectory : this.tempRecvDirectory,
areaInfo : this.availAreas[ this.viewControllers.options.getView(MciViewIds.options.area).getData() ],
};
}
}
restoreSavedState(savedState) {
@ -143,6 +146,11 @@ exports.getModule = class UploadModule extends MenuModule {
initSequence() {
const self = this;
if(0 === this.availAreas.length) {
//
return this.gotoMenu(this.menuConfig.config.noUploadAreasAvailMenu || 'fileBaseNoUploadAreasAvail');
}
async.series(
[
function before(callback) {
@ -641,6 +649,8 @@ exports.getModule = class UploadModule extends MenuModule {
const tagsView = self.viewControllers.fileDetails.getView(MciViewIds.fileDetails.tags);
const yearView = self.viewControllers.fileDetails.getView(MciViewIds.fileDetails.estYear);
self.updateCustomViewTextsWithFilter('fileDetails', MciViewIds.fileDetails.customRangeStart, fileEntry);
tagsView.setText( Array.from(fileEntry.hashTags).join(',') ); // :TODO: optional 'hashTagsSep' like file list/browse
yearView.setText(fileEntry.meta.est_release_year || '');

View File

@ -38,7 +38,7 @@ global args:
commands:
user : user utilities
config : config file management
file-area : file area management
file-base : file base management
`,
User :
@ -58,8 +58,8 @@ valid args:
valid args:
--new : generate a new/initial configuration
`,
FileArea :
`usage: oputil.js file-area <args>
FileBase :
`usage: oputil.js file-base <args>
valid args:
--scan AREA_TAG : (re)scan area specified by AREA_TAG for new files
@ -436,6 +436,14 @@ function handleConfigCommand() {
}
function fileAreaScan() {
function scanFileIterator(stepInfo, nextScanStep) {
if('start' === stepInfo.step) {
console.info(`Scanning ${stepInfo.filePath}...`);
}
return nextScanStep(null);
// :TODO: add 'finished' step when avail
}
async.waterfall(
[
function init(callback) {
@ -452,7 +460,7 @@ function fileAreaScan() {
return callback(null, fileAreaMod, areaInfo);
},
function performScan(fileAreaMod, areaInfo, callback) {
fileAreaMod.scanFileAreaForChanges(areaInfo, err => {
fileAreaMod.scanFileAreaForChanges(areaInfo, scanFileIterator, err => {
return callback(err);
});
}
@ -466,9 +474,9 @@ function fileAreaScan() {
);
}
function handleFileAreaCommand() {
function handleFileBaseCommand() {
if(true === argv.help) {
return printUsageAndSetExitCode('FileArea', ExitCodes.ERROR);
return printUsageAndSetExitCode('FileBase', ExitCodes.ERROR);
}
if(argv.scan) {
@ -499,8 +507,8 @@ function main() {
handleConfigCommand();
break;
case 'file-area' :
handleFileAreaCommand();
case 'file-base' :
handleFileBaseCommand();
break;
default: