2016-12-31 21:50:29 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// enigma-bbs
|
2022-06-05 20:04:25 +00:00
|
|
|
const MenuModule = require('./menu_module.js').MenuModule;
|
|
|
|
const Config = require('./config.js').get;
|
|
|
|
const ViewController = require('./view_controller.js').ViewController;
|
2016-12-31 21:50:29 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// deps
|
2022-06-05 20:04:25 +00:00
|
|
|
const async = require('async');
|
|
|
|
const _ = require('lodash');
|
2016-12-31 21:50:29 +00:00
|
|
|
|
|
|
|
exports.moduleInfo = {
|
2022-06-05 20:04:25 +00:00
|
|
|
name: 'File transfer protocol selection',
|
|
|
|
desc: 'Select protocol / method for file transfer',
|
|
|
|
author: 'NuSkooler',
|
2016-12-31 21:50:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const MciViewIds = {
|
2022-06-05 20:04:25 +00:00
|
|
|
protList: 1,
|
2016-12-31 21:50:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.getModule = class FileTransferProtocolSelectModule extends MenuModule {
|
2018-06-22 05:15:04 +00:00
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
|
|
|
|
|
|
|
this.config = this.menuConfig.config || {};
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (options.extraArgs) {
|
|
|
|
if (options.extraArgs.direction) {
|
2018-06-22 05:15:04 +00:00
|
|
|
this.config.direction = options.extraArgs.direction;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.config.direction = this.config.direction || 'send';
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
this.extraArgs = options.extraArgs;
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (_.has(options, 'lastMenuResult.sentFileIds')) {
|
2018-06-22 05:15:04 +00:00
|
|
|
this.sentFileIds = options.lastMenuResult.sentFileIds;
|
|
|
|
}
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (_.has(options, 'lastMenuResult.recvFilePaths')) {
|
2018-06-22 05:15:04 +00:00
|
|
|
this.recvFilePaths = options.lastMenuResult.recvFilePaths;
|
|
|
|
}
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
this.fallbackOnly = options.lastMenuResult ? true : false;
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
this.loadAvailProtocols();
|
|
|
|
|
|
|
|
this.menuMethods = {
|
2022-06-05 20:04:25 +00:00
|
|
|
selectProtocol: (formData, extraArgs, cb) => {
|
|
|
|
const protocol = this.protocols[formData.value.protocol];
|
2018-06-22 05:15:04 +00:00
|
|
|
const finalExtraArgs = this.extraArgs || {};
|
2022-06-05 20:04:25 +00:00
|
|
|
Object.assign(
|
|
|
|
finalExtraArgs,
|
|
|
|
{ protocol: protocol.protocol, direction: this.config.direction },
|
|
|
|
extraArgs
|
|
|
|
);
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
const modOpts = {
|
2022-06-05 20:04:25 +00:00
|
|
|
extraArgs: finalExtraArgs,
|
2018-06-22 05:15:04 +00:00
|
|
|
};
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if ('send' === this.config.direction) {
|
|
|
|
return this.gotoMenu(
|
|
|
|
this.config.downloadFilesMenu || 'sendFilesToUser',
|
|
|
|
modOpts,
|
|
|
|
cb
|
|
|
|
);
|
2018-06-22 05:15:04 +00:00
|
|
|
} else {
|
2022-06-05 20:04:25 +00:00
|
|
|
return this.gotoMenu(
|
|
|
|
this.config.uploadFilesMenu || 'recvFilesFromUser',
|
|
|
|
modOpts,
|
|
|
|
cb
|
|
|
|
);
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
getMenuResult() {
|
2022-06-05 20:04:25 +00:00
|
|
|
if (this.sentFileIds) {
|
|
|
|
return { sentFileIds: this.sentFileIds };
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (this.recvFilePaths) {
|
|
|
|
return { recvFilePaths: this.recvFilePaths };
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
initSequence() {
|
2022-06-05 20:04:25 +00:00
|
|
|
if (this.sentFileIds || this.recvFilePaths) {
|
2018-06-23 03:26:46 +00:00
|
|
|
// nothing to do here; move along (we're just falling through)
|
2018-06-22 05:15:04 +00:00
|
|
|
this.prevMenu();
|
|
|
|
} else {
|
|
|
|
super.initSequence();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mciReady(mciData, cb) {
|
|
|
|
super.mciReady(mciData, err => {
|
2022-06-05 20:04:25 +00:00
|
|
|
if (err) {
|
2018-06-22 05:15:04 +00:00
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
const self = this;
|
|
|
|
const vc = (self.viewControllers.allViews = new ViewController({
|
|
|
|
client: self.client,
|
|
|
|
}));
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function loadFromConfig(callback) {
|
|
|
|
const loadOpts = {
|
2022-06-05 20:04:25 +00:00
|
|
|
callingMenu: self,
|
|
|
|
mciMap: mciData.menu,
|
2018-06-22 05:15:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return vc.loadFromMenuConfig(loadOpts, callback);
|
|
|
|
},
|
|
|
|
function populateList(callback) {
|
|
|
|
const protListView = vc.getView(MciViewIds.protList);
|
|
|
|
|
2018-11-06 04:54:04 +00:00
|
|
|
protListView.setItems(self.protocols);
|
2018-06-22 05:15:04 +00:00
|
|
|
protListView.redraw();
|
|
|
|
|
|
|
|
return callback(null);
|
2022-06-05 20:04:25 +00:00
|
|
|
},
|
2018-06-22 05:15:04 +00:00
|
|
|
],
|
|
|
|
err => {
|
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
loadAvailProtocols() {
|
|
|
|
this.protocols = _.map(Config().fileTransferProtocols, (protInfo, protocol) => {
|
|
|
|
return {
|
2022-06-05 20:04:25 +00:00
|
|
|
text: protInfo.name, // standard
|
|
|
|
protocol: protocol,
|
|
|
|
name: protInfo.name,
|
|
|
|
hasBatch: _.has(protInfo, 'external.recvArgs'),
|
|
|
|
hasNonBatch: _.has(protInfo, 'external.recvArgsNonBatch'),
|
|
|
|
sort: protInfo.sort,
|
2018-06-22 05:15:04 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// Filter out batch vs non-batch only protocols
|
2022-06-05 20:04:25 +00:00
|
|
|
if (this.extraArgs.recvFileName) {
|
|
|
|
// non-batch aka non-blind
|
|
|
|
this.protocols = this.protocols.filter(prot => prot.hasNonBatch);
|
2018-06-22 05:15:04 +00:00
|
|
|
} else {
|
2022-06-05 20:04:25 +00:00
|
|
|
this.protocols = this.protocols.filter(prot => prot.hasBatch);
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// natural sort taking explicit orders into consideration
|
2022-06-05 20:04:25 +00:00
|
|
|
this.protocols.sort((a, b) => {
|
|
|
|
if (_.isNumber(a.sort) && _.isNumber(b.sort)) {
|
2018-06-22 05:15:04 +00:00
|
|
|
return a.sort - b.sort;
|
|
|
|
} else {
|
2022-06-05 20:04:25 +00:00
|
|
|
return a.name.localeCompare(b.name, {
|
|
|
|
sensitivity: false,
|
|
|
|
numeric: true,
|
|
|
|
});
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-12-31 21:50:29 +00:00
|
|
|
};
|