* 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** **Short problem description**
**Environment** **Environment**
- [ ] I am using Node.js v4.x or higher - [ ] I am using Node.js v6.x or higher
- [ ] `npm install` reports success - [ ] `npm install` reports success
- Actual Node.js version (`node --version`): - Actual Node.js version (`node --version`):
- Operating system (`uname -a` on *nix systems): - 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) { function populateFileEntryWithArchive(fileEntry, filePath, stepInfo, iterator, cb) {
const archiveUtil = ArchiveUtil.getInstance(); const archiveUtil = ArchiveUtil.getInstance();
const archiveType = fileEntry.meta.archive_type; // we set this previous to populateFileEntryWithArchive() 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`; const maxFileSizeKey = `max${_.upperFirst(descType)}FileByteSize`;
if(Config.fileBase[maxFileSizeKey] && stats.size > Config.fileBase[maxFileSizeKey]) { 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); return next(null);
} }
@ -355,7 +362,7 @@ function populateFileEntryWithArchive(fileEntry, filePath, stepInfo, iterator, c
// cleanup but don't wait // cleanup but don't wait
temptmp.cleanup( paths => { temptmp.cleanup( paths => {
// note: don't use client logger here - may not be avail // 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); 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); const storageLocations = getAreaStorageLocations(areaInfo);
async.eachSeries(storageLocations, (storageLoc, nextLocation) => { async.eachSeries(storageLocations, (storageLoc, nextLocation) => {
@ -604,6 +616,7 @@ function scanFileAreaForChanges(areaInfo, cb) {
areaTag : areaInfo.areaTag, areaTag : areaInfo.areaTag,
storageTag : storageLoc.storageTag storageTag : storageLoc.storageTag
}, },
iterator,
(err, fileEntry, dupeEntries) => { (err, fileEntry, dupeEntries) => {
if(err) { if(err) {
// :TODO: Log me!!! // :TODO: Log me!!!

View File

@ -55,7 +55,7 @@ areas: {
desc: Oldschool PC/DOS desc: Oldschool PC/DOS
storageTags: [ "retro_pc", "retro_pc_bbs" ] storageTags: [ "retro_pc", "retro_pc_bbs" ]
acs: { 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 #!/usr/bin/env node
/* jslint node: true */ /* jslint node: true */
'use strict'; 'use strict';
/* /*

View File

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

View File

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