Pardon the noise. More tab to space conversion!

This commit is contained in:
Bryan Ashby 2018-06-22 21:26:46 -06:00
parent c3635bb26b
commit 1d8be6b014
128 changed files with 8017 additions and 8017 deletions

View file

@ -1,70 +1,70 @@
/* jslint node: true */
'use strict';
// enigma-bbs
const MenuModule = require('./menu_module.js').MenuModule;
const stringFormat = require('./string_format.js');
const getSortedAvailableFileAreas = require('./file_base_area.js').getSortedAvailableFileAreas;
const getAreaDefaultStorageDirectory = require('./file_base_area.js').getAreaDefaultStorageDirectory;
const scanFile = require('./file_base_area.js').scanFile;
const getFileAreaByTag = require('./file_base_area.js').getFileAreaByTag;
const getDescFromFileName = require('./file_base_area.js').getDescFromFileName;
const ansiGoto = require('./ansi_term.js').goto;
const moveFileWithCollisionHandling = require('./file_util.js').moveFileWithCollisionHandling;
const pathWithTerminatingSeparator = require('./file_util.js').pathWithTerminatingSeparator;
const Log = require('./logger.js').log;
const Errors = require('./enig_error.js').Errors;
const FileEntry = require('./file_entry.js');
const isAnsi = require('./string_util.js').isAnsi;
const Events = require('./events.js');
// enigma-bbs
const MenuModule = require('./menu_module.js').MenuModule;
const stringFormat = require('./string_format.js');
const getSortedAvailableFileAreas = require('./file_base_area.js').getSortedAvailableFileAreas;
const getAreaDefaultStorageDirectory = require('./file_base_area.js').getAreaDefaultStorageDirectory;
const scanFile = require('./file_base_area.js').scanFile;
const getFileAreaByTag = require('./file_base_area.js').getFileAreaByTag;
const getDescFromFileName = require('./file_base_area.js').getDescFromFileName;
const ansiGoto = require('./ansi_term.js').goto;
const moveFileWithCollisionHandling = require('./file_util.js').moveFileWithCollisionHandling;
const pathWithTerminatingSeparator = require('./file_util.js').pathWithTerminatingSeparator;
const Log = require('./logger.js').log;
const Errors = require('./enig_error.js').Errors;
const FileEntry = require('./file_entry.js');
const isAnsi = require('./string_util.js').isAnsi;
const Events = require('./events.js');
// deps
const async = require('async');
const _ = require('lodash');
const temptmp = require('temptmp').createTrackedSession('upload');
const paths = require('path');
const sanatizeFilename = require('sanitize-filename');
// deps
const async = require('async');
const _ = require('lodash');
const temptmp = require('temptmp').createTrackedSession('upload');
const paths = require('path');
const sanatizeFilename = require('sanitize-filename');
exports.moduleInfo = {
name : 'Upload',
desc : 'Module for classic file uploads',
author : 'NuSkooler',
name : 'Upload',
desc : 'Module for classic file uploads',
author : 'NuSkooler',
};
const FormIds = {
options : 0,
processing : 1,
fileDetails : 2,
dupes : 3,
options : 0,
processing : 1,
fileDetails : 2,
dupes : 3,
};
const MciViewIds = {
options : {
area : 1, // area selection
uploadType : 2, // blind vs specify filename
fileName : 3, // for non-blind; not editable for blind
navMenu : 4, // next/cancel/etc.
errMsg : 5, // errors (e.g. filename cannot be blank)
area : 1, // area selection
uploadType : 2, // blind vs specify filename
fileName : 3, // for non-blind; not editable for blind
navMenu : 4, // next/cancel/etc.
errMsg : 5, // errors (e.g. filename cannot be blank)
},
processing : {
calcHashIndicator : 1,
archiveListIndicator : 2,
descFileIndicator : 3,
logStep : 4,
customRangeStart : 10, // 10+ = customs
calcHashIndicator : 1,
archiveListIndicator : 2,
descFileIndicator : 3,
logStep : 4,
customRangeStart : 10, // 10+ = customs
},
fileDetails : {
desc : 1, // defaults to 'desc' (e.g. from FILE_ID.DIZ)
tags : 2, // tag(s) for item
estYear : 3,
accept : 4, // accept fields & continue
customRangeStart : 10, // 10+ = customs
desc : 1, // defaults to 'desc' (e.g. from FILE_ID.DIZ)
tags : 2, // tag(s) for item
estYear : 3,
accept : 4, // accept fields & continue
customRangeStart : 10, // 10+ = customs
},
dupes : {
dupeList : 1,
dupeList : 1,
}
};
@ -85,14 +85,14 @@ exports.getModule = class UploadModule extends MenuModule {
},
fileDetailsContinue : (formData, extraArgs, cb) => {
// see displayFileDetailsPageForUploadEntry() for this hackery:
// see displayFileDetailsPageForUploadEntry() for this hackery:
cb(null);
return this.fileDetailsCurrentEntrySubmitCallback(null, formData.value); // move on to the next entry, if any
return this.fileDetailsCurrentEntrySubmitCallback(null, formData.value); // move on to the next entry, if any
},
// validation
// validation
validateNonBlindFileName : (fileName, cb) => {
fileName = sanatizeFilename(fileName); // remove unsafe chars, path info, etc.
fileName = sanatizeFilename(fileName); // remove unsafe chars, path info, etc.
if(0 === fileName.length) {
return cb(new Error('Invalid filename'));
}
@ -101,7 +101,7 @@ exports.getModule = class UploadModule extends MenuModule {
return cb(new Error('Filename cannot be empty'));
}
// At least SEXYZ doesn't like non-blind names that start with a number - it becomes confused
// At least SEXYZ doesn't like non-blind names that start with a number - it becomes confused
if(/^[0-9].*$/.test(fileName)) {
return cb(new Error('Invalid filename'));
}
@ -124,21 +124,21 @@ exports.getModule = class UploadModule extends MenuModule {
}
getSaveState() {
// if no areas, we're falling back due to lack of access/areas avail to upload to
// 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() ],
uploadType : this.uploadType,
tempRecvDirectory : this.tempRecvDirectory,
areaInfo : this.availAreas[ this.viewControllers.options.getView(MciViewIds.options.area).getData() ],
};
}
}
restoreSavedState(savedState) {
if(savedState.areaInfo) {
this.uploadType = savedState.uploadType;
this.areaInfo = savedState.areaInfo;
this.tempRecvDirectory = savedState.tempRecvDirectory;
this.uploadType = savedState.uploadType;
this.areaInfo = savedState.areaInfo;
this.tempRecvDirectory = savedState.tempRecvDirectory;
}
}
@ -184,24 +184,24 @@ exports.getModule = class UploadModule extends MenuModule {
return cb(err);
}
// need a terminator for various external protocols
// need a terminator for various external protocols
this.tempRecvDirectory = pathWithTerminatingSeparator(tempRecvDirectory);
const modOpts = {
extraArgs : {
recvDirectory : this.tempRecvDirectory, // we'll move files from here to their area container once processed/confirmed
direction : 'recv',
recvDirectory : this.tempRecvDirectory, // we'll move files from here to their area container once processed/confirmed
direction : 'recv',
}
};
if(!this.isBlindUpload()) {
// data has been sanatized at this point
// data has been sanatized at this point
modOpts.extraArgs.recvFileName = this.viewControllers.options.getView(MciViewIds.options.fileName).getData();
}
//
// Move along to protocol selection -> file transfer
// Upon completion, we'll re-enter the module with some file paths handed to us
// Move along to protocol selection -> file transfer
// Upon completion, we'll re-enter the module with some file paths handed to us
//
return this.gotoMenu(
this.menuConfig.config.fileTransferProtocolSelection || 'fileTransferProtocolSelection',
@ -216,7 +216,7 @@ exports.getModule = class UploadModule extends MenuModule {
}
updateScanStepInfoViews(stepInfo) {
// :TODO: add some blinking (e.g. toggle items) indicators - see OBV.DOC
// :TODO: add some blinking (e.g. toggle items) indicators - see OBV.DOC
const fmtObj = Object.assign( {}, stepInfo);
let stepIndicatorFmt = '';
@ -224,8 +224,8 @@ exports.getModule = class UploadModule extends MenuModule {
const fmtConfig = this.menuConfig.config;
const indicatorStates = fmtConfig.indicatorStates || [ '|', '/', '-', '\\' ];
const indicatorFinished = fmtConfig.indicatorFinished || '√';
const indicatorStates = fmtConfig.indicatorStates || [ '|', '/', '-', '\\' ];
const indicatorFinished = fmtConfig.indicatorFinished || '√';
const indicator = { };
const self = this;
@ -310,8 +310,8 @@ exports.getModule = class UploadModule extends MenuModule {
const self = this;
const results = {
newEntries : [],
dupes : [],
newEntries : [],
dupes : [],
};
self.client.log.debug('Scanning upload(s)', { paths : this.recvFilePaths } );
@ -319,22 +319,22 @@ exports.getModule = class UploadModule extends MenuModule {
let currentFileNum = 0;
async.eachSeries(this.recvFilePaths, (filePath, nextFilePath) => {
// :TODO: virus scanning/etc. should occur around here
// :TODO: virus scanning/etc. should occur around here
currentFileNum += 1;
self.scanStatus = {
indicatorPos : 0,
indicatorPos : 0,
};
const scanOpts = {
areaTag : self.areaInfo.areaTag,
storageTag : self.areaInfo.storageTags[0],
areaTag : self.areaInfo.areaTag,
storageTag : self.areaInfo.storageTags[0],
};
function handleScanStep(stepInfo, nextScanStep) {
stepInfo.totalFileNum = self.recvFilePaths.length;
stepInfo.currentFileNum = currentFileNum;
stepInfo.totalFileNum = self.recvFilePaths.length;
stepInfo.currentFileNum = currentFileNum;
self.updateScanStepInfoViews(stepInfo);
return nextScanStep(null);
@ -347,14 +347,14 @@ exports.getModule = class UploadModule extends MenuModule {
return nextFilePath(err);
}
// new or dupe?
// new or dupe?
if(dupeEntries.length > 0) {
// 1:n dupes found
// 1:n dupes found
self.client.log.debug('Duplicate file(s) found', { dupeEntries : dupeEntries } );
results.dupes = results.dupes.concat(dupeEntries);
} else {
// new one
// new one
results.newEntries.push(fileEntry);
}
@ -377,37 +377,37 @@ exports.getModule = class UploadModule extends MenuModule {
const self = this;
async.eachSeries(newEntries, (newEntry, nextEntry) => {
const src = paths.join(self.tempRecvDirectory, newEntry.fileName);
const dst = paths.join(areaStorageDir, newEntry.fileName);
const src = paths.join(self.tempRecvDirectory, newEntry.fileName);
const dst = paths.join(areaStorageDir, newEntry.fileName);
moveFileWithCollisionHandling(src, dst, (err, finalPath) => {
moveFileWithCollisionHandling(src, dst, (err, finalPath) => {
if(err) {
self.client.log.error(
'Failed moving physical upload file', { error : err.message, fileName : newEntry.fileName, source : src, dest : dst }
);
if(dst !== finalPath) {
// name changed; ajust before persist
// name changed; ajust before persist
newEntry.fileName = paths.basename(finalPath);
}
return nextEntry(null); // still try next file
return nextEntry(null); // still try next file
}
self.client.log.debug('Moved upload to area', { path : finalPath } );
// persist to DB
// persist to DB
newEntry.persist(err => {
if(err) {
self.client.log.error('Failed persisting upload to database', { path : finalPath, error : err.message } );
}
return nextEntry(null); // still try next file
return nextEntry(null); // still try next file
});
});
}, () => {
//
// Finally, we can remove any temp files that we may have created
// Finally, we can remove any temp files that we may have created
//
self.cleanupTempFiles();
});
@ -415,8 +415,8 @@ exports.getModule = class UploadModule extends MenuModule {
prepDetailsForUpload(scanResults, cb) {
async.eachSeries(scanResults.newEntries, (newEntry, nextEntry) => {
newEntry.meta.upload_by_username = this.client.user.username;
newEntry.meta.upload_by_user_id = this.client.user.userId;
newEntry.meta.upload_by_username = this.client.user.username;
newEntry.meta.upload_by_user_id = this.client.user.userId;
this.displayFileDetailsPageForUploadEntry(newEntry, (err, newValues) => {
if(err) {
@ -445,8 +445,8 @@ exports.getModule = class UploadModule extends MenuModule {
displayDupesPage(dupes, cb) {
//
// If we have custom art to show, use it - else just dump basic info.
// Pause at the end in either case.
// If we have custom art to show, use it - else just dump basic info.
// Pause at the end in either case.
//
const self = this;
@ -469,7 +469,7 @@ exports.getModule = class UploadModule extends MenuModule {
);
},
function prepDupeObjects(dupeListView, callback) {
// update dupe objects with additional info that can be used for formatString() and the like
// update dupe objects with additional info that can be used for formatString() and the like
async.each(dupes, (dupe, nextDupe) => {
FileEntry.loadBasicEntry(dupe.fileId, dupe, err => {
if(err) {
@ -478,8 +478,8 @@ exports.getModule = class UploadModule extends MenuModule {
const areaInfo = getFileAreaByTag(dupe.areaTag);
if(areaInfo) {
dupe.areaName = areaInfo.name;
dupe.areaDesc = areaInfo.desc;
dupe.areaName = areaInfo.name;
dupe.areaDesc = areaInfo.desc;
}
return nextDupe(null);
});
@ -513,7 +513,7 @@ exports.getModule = class UploadModule extends MenuModule {
processUploadedFiles() {
//
// For each file uploaded, we need to process & gather information
// For each file uploaded, we need to process & gather information
//
const self = this;
@ -525,8 +525,8 @@ exports.getModule = class UploadModule extends MenuModule {
}
//
// For non-blind uploads, batch is not supported, we expect a single file
// in |recvFilePaths|. If not, it's an error (we don't want to process the wrong thing)
// For non-blind uploads, batch is not supported, we expect a single file
// in |recvFilePaths|. If not, it's an error (we don't want to process the wrong thing)
//
if(self.recvFilePaths.length > 1) {
self.client.log.warn( { recvFilePaths : self.recvFilePaths }, 'Non-blind upload received 2:n files' );
@ -563,9 +563,9 @@ exports.getModule = class UploadModule extends MenuModule {
},
function startMovingAndPersistingToDatabase(scanResults, callback) {
//
// *Start* the process of moving files from their current |tempRecvDirectory|
// locations -> their final area destinations. Don't make the user wait
// here as I/O can take quite a bit of time. Log any failures.
// *Start* the process of moving files from their current |tempRecvDirectory|
// locations -> their final area destinations. Don't make the user wait
// here as I/O can take quite a bit of time. Log any failures.
//
self.moveAndPersistUploadsToDatabase(scanResults.newEntries);
return callback(null, scanResults.newEntries);
@ -574,8 +574,8 @@ exports.getModule = class UploadModule extends MenuModule {
Events.emit(
Events.getSystemEvents().UserUpload,
{
user : self.client.user,
files : uploadedEntries,
user : self.client.user,
files : uploadedEntries,
}
);
return callback(null);
@ -584,7 +584,7 @@ exports.getModule = class UploadModule extends MenuModule {
err => {
if(err) {
self.client.log.warn('File upload error encountered', { error : err.message } );
self.cleanupTempFiles(); // normally called after moveAndPersistUploadsToDatabase() is completed.
self.cleanupTempFiles(); // normally called after moveAndPersistUploadsToDatabase() is completed.
}
return self.prevMenu();
@ -609,8 +609,8 @@ exports.getModule = class UploadModule extends MenuModule {
const areaSelectView = self.viewControllers.options.getView(MciViewIds.options.area);
areaSelectView.setItems( self.availAreas.map(areaInfo => areaInfo.name ) );
const uploadTypeView = self.viewControllers.options.getView(MciViewIds.options.uploadType);
const fileNameView = self.viewControllers.options.getView(MciViewIds.options.fileName);
const uploadTypeView = self.viewControllers.options.getView(MciViewIds.options.uploadType);
const fileNameView = self.viewControllers.options.getView(MciViewIds.options.fileName);
const blindFileNameText = self.menuConfig.config.blindFileNameText || '(blind - filename ignored)';
@ -626,7 +626,7 @@ exports.getModule = class UploadModule extends MenuModule {
}
});
// sanatize filename for display when leaving the view
// sanatize filename for display when leaving the view
self.viewControllers.options.on('leave', prevView => {
if(prevView.id === MciViewIds.options.fileName) {
fileNameView.setText(sanatizeFilename(fileNameView.getData()));
@ -634,7 +634,7 @@ exports.getModule = class UploadModule extends MenuModule {
});
self.uploadType = 'blind';
uploadTypeView.setFocusItemIndex(0); // default to blind
uploadTypeView.setFocusItemIndex(0); // default to blind
fileNameView.setText(blindFileNameText);
areaSelectView.redraw();
@ -655,7 +655,7 @@ exports.getModule = class UploadModule extends MenuModule {
FormIds.processing,
{ clearScreen : true, trailingLF : false },
err => {
// note: this art is not required
// note: this art is not required
this.hasProcessingArt = !err;
return cb(null);
@ -689,7 +689,7 @@ exports.getModule = class UploadModule extends MenuModule {
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 || '');
if(isAnsi(fileEntry.desc)) {
@ -698,8 +698,8 @@ exports.getModule = class UploadModule extends MenuModule {
return descView.setAnsi(
fileEntry.desc,
{
prepped : false,
forceLineTerm : true,
prepped : false,
forceLineTerm : true,
},
() => {
return callback(null, descView, 'preview', MciViewIds.fileDetails.tags);
@ -709,29 +709,29 @@ exports.getModule = class UploadModule extends MenuModule {
const hasDesc = self.fileEntryHasDetectedDesc(fileEntry);
descView.setText(
hasDesc ? fileEntry.desc : getDescFromFileName(fileEntry.fileName),
{ scrollMode : 'top' } // override scroll mode; we want to be @ top
{ scrollMode : 'top' } // override scroll mode; we want to be @ top
);
return callback(null, descView, 'edit', hasDesc ? MciViewIds.fileDetails.tags : MciViewIds.fileDetails.desc);
}
},
function finalizeViews(descView, descViewMode, focusId, callback) {
descView.setPropertyValue('mode', descViewMode);
descView.acceptsFocus = 'preview' === descViewMode ? false : true;
descView.acceptsFocus = 'preview' === descViewMode ? false : true;
self.viewControllers.fileDetails.switchFocus(focusId);
return callback(null);
}
],
err => {
//
// we only call |cb| here if there is an error
// else, wait for the current from to be submit - then call -
// this way we'll move on to the next file entry when ready
// we only call |cb| here if there is an error
// else, wait for the current from to be submit - then call -
// this way we'll move on to the next file entry when ready
//
if(err) {
return cb(err);
}
self.fileDetailsCurrentEntrySubmitCallback = cb; // stash for moduleMethods.fileDetailsContinue
self.fileDetailsCurrentEntrySubmitCallback = cb; // stash for moduleMethods.fileDetailsContinue
}
);
}