From a257a9ba4b7a1de7f53f751e8d8d0e93642b477c Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Wed, 8 Feb 2017 22:53:48 -0700 Subject: [PATCH] * Fix up and improve oputil file-base stuff * Specialize if user does not have upload ACS --- .github/ISSUE_TEMPLATE.md | 2 +- core/file_base_area.js | 19 ++++++++++++++++--- docs/file_base.md | 2 +- main.js | 1 - mods/upload.js | 20 +++++++++++++++----- oputil.js | 24 ++++++++++++++++-------- 6 files changed, 49 insertions(+), 19 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index a34168f3..5d3f54be 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -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): diff --git a/core/file_base_area.js b/core/file_base_area.js index 9a1a3a0a..cff77071 100644 --- a/core/file_base_area.js +++ b/core/file_base_area.js @@ -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!!! diff --git a/docs/file_base.md b/docs/file_base.md index 9da9ff53..3a10ed97 100644 --- a/docs/file_base.md +++ b/docs/file_base.md @@ -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 */ } } } diff --git a/main.js b/main.js index ab8d2652..ef624294 100755 --- a/main.js +++ b/main.js @@ -1,7 +1,6 @@ #!/usr/bin/env node /* jslint node: true */ - 'use strict'; /* diff --git a/mods/upload.js b/mods/upload.js index f2bbe888..321f6f49 100644 --- a/mods/upload.js +++ b/mods/upload.js @@ -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 || ''); diff --git a/oputil.js b/oputil.js index 20ae59da..27e7f759 100755 --- a/oputil.js +++ b/oputil.js @@ -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 + FileBase : +`usage: oputil.js file-base 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: