2016-09-29 03:54:25 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// ENiGMA½
|
2017-11-24 23:23:15 +00:00
|
|
|
const MenuModule = require('./menu_module.js').MenuModule;
|
|
|
|
const ViewController = require('./view_controller.js').ViewController;
|
|
|
|
const ansi = require('./ansi_term.js');
|
|
|
|
const theme = require('./theme.js');
|
|
|
|
const FileEntry = require('./file_entry.js');
|
|
|
|
const stringFormat = require('./string_format.js');
|
|
|
|
const FileArea = require('./file_base_area.js');
|
|
|
|
const Errors = require('./enig_error.js').Errors;
|
|
|
|
const ErrNotEnabled = require('./enig_error.js').ErrorReasons.NotEnabled;
|
|
|
|
const ArchiveUtil = require('./archive_util.js');
|
|
|
|
const Config = require('./config.js').config;
|
|
|
|
const DownloadQueue = require('./download_queue.js');
|
|
|
|
const FileAreaWeb = require('./file_area_web.js');
|
|
|
|
const FileBaseFilters = require('./file_base_filter.js');
|
|
|
|
const resolveMimeType = require('./mime_util.js').resolveMimeType;
|
|
|
|
const isAnsi = require('./string_util.js').isAnsi;
|
|
|
|
const controlCodesToAnsi = require('./color_codes.js').controlCodesToAnsi;
|
2016-12-07 01:58:56 +00:00
|
|
|
|
2016-09-29 03:54:25 +00:00
|
|
|
// deps
|
|
|
|
const async = require('async');
|
|
|
|
const _ = require('lodash');
|
|
|
|
const moment = require('moment');
|
|
|
|
|
|
|
|
exports.moduleInfo = {
|
|
|
|
name : 'File Area List',
|
|
|
|
desc : 'Lists contents of file an file area',
|
|
|
|
author : 'NuSkooler',
|
|
|
|
};
|
|
|
|
|
|
|
|
const FormIds = {
|
2016-10-13 04:07:22 +00:00
|
|
|
browse : 0,
|
|
|
|
details : 1,
|
|
|
|
detailsGeneral : 2,
|
|
|
|
detailsNfo : 3,
|
|
|
|
detailsFileList : 4,
|
2016-09-29 03:54:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const MciViewIds = {
|
|
|
|
browse : {
|
2017-01-22 05:09:29 +00:00
|
|
|
desc : 1,
|
|
|
|
navMenu : 2,
|
|
|
|
|
|
|
|
customRangeStart : 10, // 10+ = customs
|
2016-10-13 04:07:22 +00:00
|
|
|
},
|
|
|
|
details : {
|
2017-01-22 05:09:29 +00:00
|
|
|
navMenu : 1,
|
|
|
|
infoXyTop : 2, // %XY starting position for info area
|
|
|
|
infoXyBottom : 3,
|
|
|
|
|
|
|
|
customRangeStart : 10, // 10+ = customs
|
2016-10-13 04:07:22 +00:00
|
|
|
},
|
|
|
|
detailsGeneral : {
|
2017-01-22 05:09:29 +00:00
|
|
|
customRangeStart : 10, // 10+ = customs
|
2016-10-13 04:07:22 +00:00
|
|
|
},
|
|
|
|
detailsNfo : {
|
|
|
|
nfo : 1,
|
2017-01-22 05:09:29 +00:00
|
|
|
|
|
|
|
customRangeStart : 10, // 10+ = customs
|
2016-10-13 04:07:22 +00:00
|
|
|
},
|
|
|
|
detailsFileList : {
|
|
|
|
fileList : 1,
|
2017-01-22 05:09:29 +00:00
|
|
|
|
|
|
|
customRangeStart : 10, // 10+ = customs
|
2016-09-29 03:54:25 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.getModule = class FileAreaList extends MenuModule {
|
|
|
|
|
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
|
|
|
|
2017-09-02 22:24:52 +00:00
|
|
|
this.filterCriteria = _.get(options, 'extraArgs.filterCriteria');
|
|
|
|
this.fileList = _.get(options, 'extraArgs.fileList');
|
2016-09-29 03:54:25 +00:00
|
|
|
|
2017-09-04 02:44:39 +00:00
|
|
|
if(this.fileList) {
|
|
|
|
// we'll need to adjust position as well!
|
|
|
|
this.fileListPosition = 0;
|
|
|
|
}
|
|
|
|
|
2016-10-25 03:49:45 +00:00
|
|
|
this.dlQueue = new DownloadQueue(this.client);
|
2016-10-15 03:57:02 +00:00
|
|
|
|
2017-02-08 03:20:10 +00:00
|
|
|
if(!this.filterCriteria) {
|
|
|
|
this.filterCriteria = FileBaseFilters.getActiveFilter(this.client);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(_.isString(this.filterCriteria)) {
|
|
|
|
this.filterCriteria = JSON.parse(this.filterCriteria);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(_.has(options, 'lastMenuResult.value')) {
|
|
|
|
this.lastMenuResultValue = options.lastMenuResult.value;
|
|
|
|
}
|
2016-10-03 03:40:37 +00:00
|
|
|
|
2016-10-13 04:07:22 +00:00
|
|
|
this.menuMethods = {
|
|
|
|
nextFile : (formData, extraArgs, cb) => {
|
|
|
|
if(this.fileListPosition + 1 < this.fileList.length) {
|
|
|
|
this.fileListPosition += 1;
|
|
|
|
|
|
|
|
return this.displayBrowsePage(true, cb); // true=clerarScreen
|
|
|
|
}
|
|
|
|
|
|
|
|
return cb(null);
|
|
|
|
},
|
|
|
|
prevFile : (formData, extraArgs, cb) => {
|
|
|
|
if(this.fileListPosition > 0) {
|
|
|
|
--this.fileListPosition;
|
|
|
|
|
|
|
|
return this.displayBrowsePage(true, cb); // true=clearScreen
|
|
|
|
}
|
|
|
|
|
|
|
|
return cb(null);
|
|
|
|
},
|
|
|
|
viewDetails : (formData, extraArgs, cb) => {
|
|
|
|
this.viewControllers.browse.setFocus(false);
|
|
|
|
return this.displayDetailsPage(cb);
|
|
|
|
},
|
|
|
|
detailsQuit : (formData, extraArgs, cb) => {
|
2017-09-02 21:56:47 +00:00
|
|
|
[ 'detailsNfo', 'detailsFileList', 'details' ].forEach(n => {
|
|
|
|
const vc = this.viewControllers[n];
|
|
|
|
if(vc) {
|
|
|
|
vc.detachClientEvents();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-10-13 04:07:22 +00:00
|
|
|
return this.displayBrowsePage(true, cb); // true=clearScreen
|
|
|
|
},
|
2016-10-15 03:57:02 +00:00
|
|
|
toggleQueue : (formData, extraArgs, cb) => {
|
|
|
|
this.dlQueue.toggle(this.currentFileEntry);
|
|
|
|
this.updateQueueIndicator();
|
|
|
|
return cb(null);
|
|
|
|
},
|
2016-10-25 03:49:45 +00:00
|
|
|
showWebDownloadLink : (formData, extraArgs, cb) => {
|
|
|
|
return this.fetchAndDisplayWebDownloadLink(cb);
|
2017-02-08 05:15:34 +00:00
|
|
|
},
|
|
|
|
displayHelp : (formData, extraArgs, cb) => {
|
|
|
|
return this.displayHelpPage(cb);
|
2017-02-08 03:20:10 +00:00
|
|
|
}
|
2016-10-13 04:07:22 +00:00
|
|
|
};
|
2016-09-29 03:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enter() {
|
|
|
|
super.enter();
|
|
|
|
}
|
|
|
|
|
|
|
|
leave() {
|
|
|
|
super.leave();
|
|
|
|
}
|
|
|
|
|
2017-02-08 03:20:10 +00:00
|
|
|
getSaveState() {
|
|
|
|
return {
|
|
|
|
fileList : this.fileList,
|
|
|
|
fileListPosition : this.fileListPosition,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
restoreSavedState(savedState) {
|
|
|
|
if(savedState) {
|
|
|
|
this.fileList = savedState.fileList;
|
|
|
|
this.fileListPosition = savedState.fileListPosition;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
updateFileEntryWithMenuResult(cb) {
|
|
|
|
if(!this.lastMenuResultValue) {
|
|
|
|
return cb(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(_.isNumber(this.lastMenuResultValue.rating)) {
|
|
|
|
const fileId = this.fileList[this.fileListPosition];
|
|
|
|
FileEntry.persistUserRating(fileId, this.client.user.userId, this.lastMenuResultValue.rating, err => {
|
|
|
|
if(err) {
|
|
|
|
this.client.log.warn( { error : err.message, fileId : fileId }, 'Failed to persist file rating' );
|
|
|
|
}
|
|
|
|
return cb(null);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return cb(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-29 03:54:25 +00:00
|
|
|
initSequence() {
|
|
|
|
const self = this;
|
|
|
|
|
|
|
|
async.series(
|
|
|
|
[
|
2017-02-08 03:20:10 +00:00
|
|
|
function preInit(callback) {
|
|
|
|
return self.updateFileEntryWithMenuResult(callback);
|
|
|
|
},
|
2016-09-29 03:54:25 +00:00
|
|
|
function beforeArt(callback) {
|
|
|
|
return self.beforeArt(callback);
|
|
|
|
},
|
|
|
|
function display(callback) {
|
2017-02-08 05:15:34 +00:00
|
|
|
return self.displayBrowsePage(false, err => {
|
|
|
|
if(err && 'NORESULTS' === err.reasonCode) {
|
|
|
|
self.gotoMenu(self.menuConfig.config.noResultsMenu || 'fileBaseListEntriesNoResults');
|
|
|
|
}
|
|
|
|
return callback(err);
|
|
|
|
});
|
2016-09-29 03:54:25 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
() => {
|
|
|
|
self.finishedLoading();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-10-25 03:49:45 +00:00
|
|
|
populateCurrentEntryInfo(cb) {
|
2016-10-13 04:07:22 +00:00
|
|
|
const config = this.menuConfig.config;
|
|
|
|
const currEntry = this.currentFileEntry;
|
|
|
|
|
|
|
|
const uploadTimestampFormat = config.browseUploadTimestampFormat || config.uploadTimestampFormat || 'YYYY-MMM-DD';
|
|
|
|
const area = FileArea.getFileAreaByTag(currEntry.areaTag);
|
|
|
|
const hashTagsSep = config.hashTagsSep || ', ';
|
2016-10-15 03:57:02 +00:00
|
|
|
const isQueuedIndicator = config.isQueuedIndicator || 'Y';
|
|
|
|
const isNotQueuedIndicator = config.isNotQueuedIndicator || 'N';
|
2016-10-13 04:07:22 +00:00
|
|
|
|
2017-02-12 07:25:25 +00:00
|
|
|
const entryInfo = currEntry.entryInfo = {
|
2016-10-13 04:07:22 +00:00
|
|
|
fileId : currEntry.fileId,
|
|
|
|
areaTag : currEntry.areaTag,
|
2017-07-10 02:00:36 +00:00
|
|
|
areaName : _.get(area, 'name') || 'N/A',
|
|
|
|
areaDesc : _.get(area, 'desc') || 'N/A',
|
2017-01-22 05:09:29 +00:00
|
|
|
fileSha256 : currEntry.fileSha256,
|
2016-10-13 04:07:22 +00:00
|
|
|
fileName : currEntry.fileName,
|
|
|
|
desc : currEntry.desc || '',
|
|
|
|
descLong : currEntry.descLong || '',
|
2017-02-08 03:20:10 +00:00
|
|
|
userRating : currEntry.userRating,
|
2016-10-13 04:07:22 +00:00
|
|
|
uploadTimestamp : moment(currEntry.uploadTimestamp).format(uploadTimestampFormat),
|
|
|
|
hashTags : Array.from(currEntry.hashTags).join(hashTagsSep),
|
2017-02-12 07:25:25 +00:00
|
|
|
isQueued : this.dlQueue.isQueued(currEntry) ? isQueuedIndicator : isNotQueuedIndicator,
|
2016-10-25 03:49:45 +00:00
|
|
|
webDlLink : '', // :TODO: fetch web any existing web d/l link
|
2017-02-08 03:20:10 +00:00
|
|
|
webDlExpire : '', // :TODO: fetch web d/l link expire time
|
2016-10-13 04:07:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// We need the entry object to contain meta keys even if they are empty as
|
|
|
|
// consumers may very likely attempt to use them
|
|
|
|
//
|
2017-02-25 06:39:31 +00:00
|
|
|
const metaValues = FileEntry.WellKnownMetaValues;
|
2016-10-13 04:07:22 +00:00
|
|
|
metaValues.forEach(name => {
|
2016-10-14 02:53:38 +00:00
|
|
|
const value = !_.isUndefined(currEntry.meta[name]) ? currEntry.meta[name] : 'N/A';
|
2016-10-13 04:07:22 +00:00
|
|
|
entryInfo[_.camelCase(name)] = value;
|
|
|
|
});
|
|
|
|
|
|
|
|
if(entryInfo.archiveType) {
|
2017-05-11 03:21:07 +00:00
|
|
|
const mimeType = resolveMimeType(entryInfo.archiveType);
|
|
|
|
entryInfo.archiveTypeDesc = mimeType ? _.get(Config, [ 'fileTypes', mimeType, 'desc' ] ) || mimeType : entryInfo.archiveType;
|
2016-10-13 04:07:22 +00:00
|
|
|
} else {
|
|
|
|
entryInfo.archiveTypeDesc = 'N/A';
|
|
|
|
}
|
|
|
|
|
2016-10-14 02:53:38 +00:00
|
|
|
entryInfo.uploadByUsername = entryInfo.uploadByUsername || 'N/A'; // may be imported
|
|
|
|
entryInfo.hashTags = entryInfo.hashTags || '(none)';
|
2016-10-13 04:07:22 +00:00
|
|
|
|
|
|
|
// create a rating string, e.g. "**---"
|
|
|
|
const userRatingTicked = config.userRatingTicked || '*';
|
|
|
|
const userRatingUnticked = config.userRatingUnticked || '';
|
2017-02-08 03:20:10 +00:00
|
|
|
entryInfo.userRating = ~~Math.round(entryInfo.userRating) || 0; // be safe!
|
2017-09-02 15:59:22 +00:00
|
|
|
entryInfo.userRatingString = userRatingTicked.repeat(entryInfo.userRating);
|
2016-10-13 04:07:22 +00:00
|
|
|
if(entryInfo.userRating < 5) {
|
2017-09-02 15:59:22 +00:00
|
|
|
entryInfo.userRatingString += userRatingUnticked.repeat( (5 - entryInfo.userRating) );
|
2016-10-13 04:07:22 +00:00
|
|
|
}
|
2016-10-25 03:49:45 +00:00
|
|
|
|
|
|
|
FileAreaWeb.getExistingTempDownloadServeItem(this.client, this.currentFileEntry, (err, serveItem) => {
|
|
|
|
if(err) {
|
|
|
|
entryInfo.webDlExpire = '';
|
2017-02-18 16:56:23 +00:00
|
|
|
if(ErrNotEnabled === err.reasonCode) {
|
|
|
|
entryInfo.webDlExpire = config.webDlLinkNoWebserver || 'Web server is not enabled';
|
|
|
|
} else {
|
|
|
|
entryInfo.webDlLink = config.webDlLinkNeedsGenerated || 'Not yet generated';
|
|
|
|
}
|
2016-10-25 03:49:45 +00:00
|
|
|
} else {
|
|
|
|
const webDlExpireTimeFormat = config.webDlExpireTimeFormat || 'YYYY-MMM-DD @ h:mm';
|
|
|
|
|
2017-09-24 05:17:16 +00:00
|
|
|
entryInfo.webDlLink = ansi.vtxHyperlink(this.client, serveItem.url) + serveItem.url;
|
2016-10-25 03:49:45 +00:00
|
|
|
entryInfo.webDlExpire = moment(serveItem.expireTimestamp).format(webDlExpireTimeFormat);
|
|
|
|
}
|
|
|
|
|
|
|
|
return cb(null);
|
|
|
|
});
|
2016-10-13 04:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
populateCustomLabels(category, startId) {
|
2017-01-22 05:09:29 +00:00
|
|
|
return this.updateCustomViewTextsWithFilter(category, startId, this.currentFileEntry.entryInfo);
|
2016-10-25 03:49:45 +00:00
|
|
|
}
|
|
|
|
|
2016-10-13 04:07:22 +00:00
|
|
|
displayArtAndPrepViewController(name, options, cb) {
|
2016-09-29 03:54:25 +00:00
|
|
|
const self = this;
|
|
|
|
const config = this.menuConfig.config;
|
|
|
|
|
|
|
|
async.waterfall(
|
|
|
|
[
|
2016-10-13 04:07:22 +00:00
|
|
|
function readyAndDisplayArt(callback) {
|
|
|
|
if(options.clearScreen) {
|
2017-02-12 07:25:25 +00:00
|
|
|
self.client.term.rawWrite(ansi.resetScreen());
|
2016-09-29 03:54:25 +00:00
|
|
|
}
|
2016-10-13 04:07:22 +00:00
|
|
|
|
2016-09-29 03:54:25 +00:00
|
|
|
theme.displayThemedAsset(
|
2016-10-13 04:07:22 +00:00
|
|
|
config.art[name],
|
2016-09-29 03:54:25 +00:00
|
|
|
self.client,
|
|
|
|
{ font : self.menuConfig.font, trailingLF : false },
|
|
|
|
(err, artData) => {
|
|
|
|
return callback(err, artData);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function prepeareViewController(artData, callback) {
|
2016-10-13 04:07:22 +00:00
|
|
|
if(_.isUndefined(self.viewControllers[name])) {
|
|
|
|
const vcOpts = {
|
|
|
|
client : self.client,
|
|
|
|
formId : FormIds[name],
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!_.isUndefined(options.noInput)) {
|
|
|
|
vcOpts.noInput = options.noInput;
|
|
|
|
}
|
|
|
|
|
|
|
|
const vc = self.addViewController(name, new ViewController(vcOpts));
|
|
|
|
|
|
|
|
if('details' === name) {
|
|
|
|
try {
|
|
|
|
self.detailsInfoArea = {
|
|
|
|
top : artData.mciMap.XY2.position,
|
|
|
|
bottom : artData.mciMap.XY3.position,
|
|
|
|
};
|
|
|
|
} catch(e) {
|
|
|
|
return callback(Errors.DoesNotExist('Missing XY2 and XY3 position indicators!'));
|
|
|
|
}
|
|
|
|
}
|
2016-09-29 03:54:25 +00:00
|
|
|
|
|
|
|
const loadOpts = {
|
|
|
|
callingMenu : self,
|
|
|
|
mciMap : artData.mciMap,
|
2016-10-13 04:07:22 +00:00
|
|
|
formId : FormIds[name],
|
2016-09-29 03:54:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return vc.loadFromMenuConfig(loadOpts, callback);
|
|
|
|
}
|
2016-10-13 04:07:22 +00:00
|
|
|
|
|
|
|
self.viewControllers[name].setFocus(true);
|
|
|
|
return callback(null);
|
|
|
|
|
|
|
|
},
|
|
|
|
],
|
|
|
|
err => {
|
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2016-09-29 03:54:25 +00:00
|
|
|
|
2016-10-13 04:07:22 +00:00
|
|
|
displayBrowsePage(clearScreen, cb) {
|
|
|
|
const self = this;
|
2016-09-29 03:54:25 +00:00
|
|
|
|
2016-10-13 04:07:22 +00:00
|
|
|
async.series(
|
|
|
|
[
|
2016-09-29 03:54:25 +00:00
|
|
|
function fetchEntryData(callback) {
|
2017-09-04 02:44:39 +00:00
|
|
|
if(self.fileList) {
|
2016-10-13 04:07:22 +00:00
|
|
|
return callback(null);
|
|
|
|
}
|
2017-02-08 03:20:10 +00:00
|
|
|
return self.loadFileIds(false, callback); // false=do not force
|
2016-09-29 03:54:25 +00:00
|
|
|
},
|
2017-02-08 05:15:34 +00:00
|
|
|
function checkEmptyResults(callback) {
|
|
|
|
if(0 === self.fileList.length) {
|
|
|
|
return callback(Errors.General('No results for criteria', 'NORESULTS'));
|
|
|
|
}
|
|
|
|
return callback(null);
|
|
|
|
},
|
|
|
|
function prepArtAndViewController(callback) {
|
|
|
|
return self.displayArtAndPrepViewController('browse', { clearScreen : clearScreen }, callback);
|
|
|
|
},
|
|
|
|
function loadCurrentFileInfo(callback) {
|
2016-10-14 02:53:38 +00:00
|
|
|
self.currentFileEntry = new FileEntry();
|
|
|
|
|
2016-09-29 03:54:25 +00:00
|
|
|
self.currentFileEntry.load( self.fileList[ self.fileListPosition ], err => {
|
2016-10-25 03:49:45 +00:00
|
|
|
if(err) {
|
|
|
|
return callback(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
return self.populateCurrentEntryInfo(callback);
|
2016-09-29 03:54:25 +00:00
|
|
|
});
|
|
|
|
},
|
2017-08-30 02:10:34 +00:00
|
|
|
function populateDesc(callback) {
|
2016-09-29 03:54:25 +00:00
|
|
|
if(_.isString(self.currentFileEntry.desc)) {
|
|
|
|
const descView = self.viewControllers.browse.getView(MciViewIds.browse.desc);
|
2017-08-06 17:31:21 +00:00
|
|
|
if(descView) {
|
2017-11-13 01:55:57 +00:00
|
|
|
//
|
|
|
|
// For descriptions we want to support as many color code systems
|
|
|
|
// as we can for coverage of what is found in the while (e.g. Renegade
|
|
|
|
// pipes, PCB @X##, etc.)
|
|
|
|
//
|
|
|
|
// MLTEV doesn't support all of this, so convert. If we produced ANSI
|
|
|
|
// esc sequences, we'll proceed with specialization, else just treat
|
|
|
|
// it as text.
|
|
|
|
//
|
|
|
|
const desc = controlCodesToAnsi(self.currentFileEntry.desc);
|
|
|
|
if(desc.length != self.currentFileEntry.desc.length || isAnsi(desc)) {
|
2017-08-30 01:55:20 +00:00
|
|
|
descView.setAnsi(
|
2017-11-13 01:55:57 +00:00
|
|
|
desc,
|
2017-08-30 01:55:20 +00:00
|
|
|
{
|
|
|
|
prepped : false,
|
|
|
|
forceLineTerm : true
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
return callback(null);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
descView.setText(self.currentFileEntry.desc);
|
|
|
|
return callback(null);
|
|
|
|
}
|
2016-12-07 01:58:56 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return callback(null);
|
|
|
|
}
|
2017-08-30 02:10:34 +00:00
|
|
|
},
|
|
|
|
function populateAdditionalViews(callback) {
|
|
|
|
self.updateQueueIndicator();
|
|
|
|
self.populateCustomLabels('browse', MciViewIds.browse.customRangeStart);
|
|
|
|
return callback(null);
|
2016-10-13 04:07:22 +00:00
|
|
|
}
|
|
|
|
],
|
2017-02-08 05:15:34 +00:00
|
|
|
err => {
|
2016-10-13 04:07:22 +00:00
|
|
|
if(cb) {
|
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
displayDetailsPage(cb) {
|
|
|
|
const self = this;
|
|
|
|
|
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function prepArtAndViewController(callback) {
|
|
|
|
return self.displayArtAndPrepViewController('details', { clearScreen : true }, callback);
|
|
|
|
},
|
|
|
|
function populateViews(callback) {
|
2017-01-22 05:09:29 +00:00
|
|
|
self.populateCustomLabels('details', MciViewIds.details.customRangeStart);
|
2016-10-13 04:07:22 +00:00
|
|
|
return callback(null);
|
|
|
|
},
|
|
|
|
function prepSection(callback) {
|
|
|
|
return self.displayDetailsSection('general', false, callback);
|
|
|
|
},
|
|
|
|
function listenNavChanges(callback) {
|
|
|
|
const navMenu = self.viewControllers.details.getView(MciViewIds.details.navMenu);
|
|
|
|
navMenu.setFocusItemIndex(0);
|
2016-09-29 03:54:25 +00:00
|
|
|
|
2016-10-13 04:07:22 +00:00
|
|
|
navMenu.on('index update', index => {
|
|
|
|
const sectionName = {
|
|
|
|
0 : 'general',
|
|
|
|
1 : 'nfo',
|
|
|
|
2 : 'fileList',
|
|
|
|
}[index];
|
|
|
|
|
|
|
|
if(sectionName) {
|
|
|
|
self.displayDetailsSection(sectionName, true);
|
|
|
|
}
|
2016-09-29 03:54:25 +00:00
|
|
|
});
|
|
|
|
|
2016-10-13 04:07:22 +00:00
|
|
|
return callback(null);
|
|
|
|
}
|
|
|
|
],
|
|
|
|
err => {
|
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2017-02-08 05:15:34 +00:00
|
|
|
|
|
|
|
displayHelpPage(cb) {
|
|
|
|
this.displayAsset(
|
|
|
|
this.menuConfig.config.art.help,
|
|
|
|
{ clearScreen : true },
|
|
|
|
() => {
|
|
|
|
this.client.waitForKeyPress( () => {
|
|
|
|
return this.displayBrowsePage(true, cb);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2016-10-25 03:49:45 +00:00
|
|
|
|
|
|
|
fetchAndDisplayWebDownloadLink(cb) {
|
|
|
|
const self = this;
|
|
|
|
|
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function generateLinkIfNeeded(callback) {
|
|
|
|
|
|
|
|
if(self.currentFileEntry.webDlExpireTime < moment()) {
|
|
|
|
return callback(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
const expireTime = moment().add(Config.fileBase.web.expireMinutes, 'minutes');
|
|
|
|
|
|
|
|
FileAreaWeb.createAndServeTempDownload(
|
|
|
|
self.client,
|
|
|
|
self.currentFileEntry,
|
|
|
|
{ expireTime : expireTime },
|
|
|
|
(err, url) => {
|
|
|
|
if(err) {
|
|
|
|
return callback(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
self.currentFileEntry.webDlExpireTime = expireTime;
|
|
|
|
|
|
|
|
const webDlExpireTimeFormat = self.menuConfig.config.webDlExpireTimeFormat || 'YYYY-MMM-DD @ h:mm';
|
|
|
|
|
2017-09-24 05:17:16 +00:00
|
|
|
self.currentFileEntry.entryInfo.webDlLink = ansi.vtxHyperlink(self.client, url) + url;
|
2016-10-25 03:49:45 +00:00
|
|
|
self.currentFileEntry.entryInfo.webDlExpire = expireTime.format(webDlExpireTimeFormat);
|
|
|
|
|
|
|
|
return callback(null);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
function updateActiveViews(callback) {
|
2017-01-22 05:09:29 +00:00
|
|
|
self.updateCustomViewTextsWithFilter(
|
|
|
|
'browse',
|
|
|
|
MciViewIds.browse.customRangeStart, self.currentFileEntry.entryInfo,
|
2017-01-23 04:30:49 +00:00
|
|
|
{ filter : [ '{webDlLink}', '{webDlExpire}' ] }
|
2017-01-22 05:09:29 +00:00
|
|
|
);
|
2016-10-25 03:49:45 +00:00
|
|
|
return callback(null);
|
|
|
|
}
|
|
|
|
],
|
|
|
|
err => {
|
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2016-10-13 04:07:22 +00:00
|
|
|
|
2016-10-15 03:57:02 +00:00
|
|
|
updateQueueIndicator() {
|
2016-10-25 03:49:45 +00:00
|
|
|
const isQueuedIndicator = this.menuConfig.config.isQueuedIndicator || 'Y';
|
|
|
|
const isNotQueuedIndicator = this.menuConfig.config.isNotQueuedIndicator || 'N';
|
|
|
|
|
|
|
|
this.currentFileEntry.entryInfo.isQueued = stringFormat(
|
|
|
|
this.dlQueue.isQueued(this.currentFileEntry) ?
|
|
|
|
isQueuedIndicator :
|
|
|
|
isNotQueuedIndicator
|
|
|
|
);
|
|
|
|
|
2017-01-22 05:09:29 +00:00
|
|
|
this.updateCustomViewTextsWithFilter(
|
|
|
|
'browse',
|
|
|
|
MciViewIds.browse.customRangeStart,
|
|
|
|
this.currentFileEntry.entryInfo,
|
2017-01-23 04:30:49 +00:00
|
|
|
{ filter : [ '{isQueued}' ] }
|
2017-01-22 05:09:29 +00:00
|
|
|
);
|
2016-10-15 03:57:02 +00:00
|
|
|
}
|
|
|
|
|
2016-10-13 04:07:22 +00:00
|
|
|
cacheArchiveEntries(cb) {
|
|
|
|
// check cache
|
|
|
|
if(this.currentFileEntry.archiveEntries) {
|
|
|
|
return cb(null, 'cache');
|
|
|
|
}
|
|
|
|
|
|
|
|
const areaInfo = FileArea.getFileAreaByTag(this.currentFileEntry.areaTag);
|
|
|
|
if(!areaInfo) {
|
|
|
|
return cb(Errors.Invalid('Invalid area tag'));
|
|
|
|
}
|
|
|
|
|
2016-12-07 01:58:56 +00:00
|
|
|
const filePath = this.currentFileEntry.filePath;
|
2016-10-13 04:07:22 +00:00
|
|
|
const archiveUtil = ArchiveUtil.getInstance();
|
|
|
|
|
|
|
|
archiveUtil.listEntries(filePath, this.currentFileEntry.entryInfo.archiveType, (err, entries) => {
|
|
|
|
if(err) {
|
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.currentFileEntry.archiveEntries = entries;
|
|
|
|
return cb(null, 're-cached');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
populateFileListing() {
|
|
|
|
const fileListView = this.viewControllers.detailsFileList.getView(MciViewIds.detailsFileList.fileList);
|
|
|
|
|
|
|
|
if(this.currentFileEntry.entryInfo.archiveType) {
|
|
|
|
this.cacheArchiveEntries( (err, cacheStatus) => {
|
|
|
|
if(err) {
|
|
|
|
// :TODO: Handle me!!!
|
|
|
|
fileListView.setItems( [ 'Failed getting file listing' ] ); // :TODO: make this not suck
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if('re-cached' === cacheStatus) {
|
2016-12-31 21:50:29 +00:00
|
|
|
const fileListEntryFormat = this.menuConfig.config.fileListEntryFormat || '{fileName} {fileSize}'; // :TODO: use byteSize here?
|
2016-10-13 04:07:22 +00:00
|
|
|
const focusFileListEntryFormat = this.menuConfig.config.focusFileListEntryFormat || fileListEntryFormat;
|
|
|
|
|
|
|
|
fileListView.setItems( this.currentFileEntry.archiveEntries.map( entry => stringFormat(fileListEntryFormat, entry) ) );
|
|
|
|
fileListView.setFocusItems( this.currentFileEntry.archiveEntries.map( entry => stringFormat(focusFileListEntryFormat, entry) ) );
|
|
|
|
|
|
|
|
fileListView.redraw();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
fileListView.setItems( [ stringFormat(this.menuConfig.config.notAnArchiveFormat || 'Not an archive', { fileName : this.currentFileEntry.fileName } ) ] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
displayDetailsSection(sectionName, clearArea, cb) {
|
|
|
|
const self = this;
|
2017-01-28 19:33:06 +00:00
|
|
|
const name = `details${_.upperFirst(sectionName)}`;
|
2016-10-13 04:07:22 +00:00
|
|
|
|
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function detachPrevious(callback) {
|
|
|
|
if(self.lastDetailsViewController) {
|
|
|
|
self.lastDetailsViewController.detachClientEvents();
|
|
|
|
}
|
|
|
|
return callback(null);
|
|
|
|
},
|
|
|
|
function prepArtAndViewController(callback) {
|
|
|
|
|
|
|
|
function gotoTopPos() {
|
|
|
|
self.client.term.rawWrite(ansi.goto(self.detailsInfoArea.top[0], 1));
|
2016-10-01 19:25:32 +00:00
|
|
|
}
|
|
|
|
|
2016-10-13 04:07:22 +00:00
|
|
|
gotoTopPos();
|
2016-09-29 03:54:25 +00:00
|
|
|
|
2016-10-13 04:07:22 +00:00
|
|
|
if(clearArea) {
|
|
|
|
self.client.term.rawWrite(ansi.reset());
|
2016-09-29 03:54:25 +00:00
|
|
|
|
2016-10-13 04:07:22 +00:00
|
|
|
let pos = self.detailsInfoArea.top[0];
|
|
|
|
const bottom = self.detailsInfoArea.bottom[0];
|
|
|
|
|
|
|
|
while(pos++ <= bottom) {
|
|
|
|
self.client.term.rawWrite(ansi.eraseLine() + ansi.down());
|
2016-09-29 03:54:25 +00:00
|
|
|
}
|
|
|
|
|
2016-10-13 04:07:22 +00:00
|
|
|
gotoTopPos();
|
|
|
|
}
|
|
|
|
|
|
|
|
return self.displayArtAndPrepViewController(name, { clearScreen : false, noInput : true }, callback);
|
|
|
|
},
|
|
|
|
function populateViews(callback) {
|
|
|
|
self.lastDetailsViewController = self.viewControllers[name];
|
|
|
|
|
|
|
|
switch(sectionName) {
|
|
|
|
case 'nfo' :
|
|
|
|
{
|
|
|
|
const nfoView = self.viewControllers.detailsNfo.getView(MciViewIds.detailsNfo.nfo);
|
2017-08-19 21:21:02 +00:00
|
|
|
if(!nfoView) {
|
|
|
|
return callback(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isAnsi(self.currentFileEntry.entryInfo.descLong)) {
|
|
|
|
nfoView.setAnsi(
|
|
|
|
self.currentFileEntry.entryInfo.descLong,
|
|
|
|
{
|
|
|
|
prepped : false,
|
|
|
|
forceLineTerm : true,
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
return callback(null);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
2016-10-13 04:07:22 +00:00
|
|
|
nfoView.setText(self.currentFileEntry.entryInfo.descLong);
|
2017-08-19 21:21:02 +00:00
|
|
|
return callback(null);
|
2016-10-13 04:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'fileList' :
|
|
|
|
self.populateFileListing();
|
2017-08-19 21:21:02 +00:00
|
|
|
return callback(null);
|
2016-10-01 19:25:32 +00:00
|
|
|
|
2017-08-19 21:21:02 +00:00
|
|
|
default :
|
|
|
|
return callback(null);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
function setLabels(callback) {
|
2017-01-22 05:09:29 +00:00
|
|
|
self.populateCustomLabels(name, MciViewIds[name].customRangeStart);
|
2016-10-01 19:25:32 +00:00
|
|
|
return callback(null);
|
2016-09-29 03:54:25 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
err => {
|
|
|
|
if(cb) {
|
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-02-08 03:20:10 +00:00
|
|
|
loadFileIds(force, cb) {
|
|
|
|
if(force || (_.isUndefined(this.fileList) || _.isUndefined(this.fileListPosition))) {
|
|
|
|
this.fileListPosition = 0;
|
2017-09-26 16:42:53 +00:00
|
|
|
|
|
|
|
const filterCriteria = Object.assign({}, this.filterCriteria);
|
|
|
|
if(!filterCriteria.areaTag) {
|
|
|
|
filterCriteria.areaTag = FileArea.getAvailableFileAreaTags(this.client);
|
|
|
|
}
|
|
|
|
|
|
|
|
FileEntry.findFiles(filterCriteria, (err, fileIds) => {
|
2017-02-08 03:20:10 +00:00
|
|
|
this.fileList = fileIds;
|
|
|
|
return cb(err);
|
|
|
|
});
|
|
|
|
}
|
2016-09-29 03:54:25 +00:00
|
|
|
}
|
|
|
|
};
|