feat(OPTS): add opts command handler for utf8
master
This commit is contained in:
@@ -1,8 +1,31 @@
|
||||
const _ = require('lodash');
|
||||
|
||||
const OPTIONS = {
|
||||
UTF8: utf8,
|
||||
'UTF-8': utf8
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
directive: 'OPTS',
|
||||
handler: function () {
|
||||
return this.reply(501);
|
||||
handler: function ({command} = {}) {
|
||||
const [_option, ...args] = command.arg.split(' ');
|
||||
const option = _.toUpper(_option);
|
||||
|
||||
if (!OPTIONS.hasOwnProperty(option)) return this.reply(500);
|
||||
return OPTIONS[option].call(this, args);
|
||||
},
|
||||
syntax: '{{cmd}}',
|
||||
description: 'Select options for a feature'
|
||||
};
|
||||
|
||||
function utf8([setting] = []) {
|
||||
switch (_.toUpper(setting)) {
|
||||
case 'ON':
|
||||
this.encoding = 'utf8';
|
||||
return this.reply(200, 'UTF8 encoding on');
|
||||
case 'OFF':
|
||||
this.encoding = 'ascii';
|
||||
return this.reply(200, 'UTF8 encoding off');
|
||||
default: this.reply(501);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ class FtpConnection {
|
||||
this.log = options.log.child({id: this.id, ip: this.ip});
|
||||
this.commands = new Commands(this);
|
||||
this.transferType = 'binary';
|
||||
this.encoding = 'utf8';
|
||||
this.bufferSize = false;
|
||||
|
||||
this.connector = new BaseConnector(this);
|
||||
@@ -34,7 +35,7 @@ class FtpConnection {
|
||||
}
|
||||
|
||||
_handleData(data) {
|
||||
const messages = _.compact(data.toString('utf8').split('\r\n'));
|
||||
const messages = _.compact(data.toString(this.encoding).split('\r\n'));
|
||||
this.log.trace(messages);
|
||||
return sequence(messages.map(message => this.commands.handle.bind(this.commands, message)));
|
||||
}
|
||||
@@ -84,7 +85,7 @@ class FtpConnection {
|
||||
|
||||
if (!letter.socket) letter.socket = options.socket ? options.socket : this.commandSocket;
|
||||
if (!letter.message) letter.message = DEFAULT_MESSAGE[options.code] || 'No information';
|
||||
if (!letter.encoding) letter.encoding = 'utf8';
|
||||
if (!letter.encoding) letter.encoding = this.encoding;
|
||||
return when(letter.message) // allow passing in a promise as a message
|
||||
.then(message => {
|
||||
letter.message = message;
|
||||
|
||||
Reference in New Issue
Block a user