Various bug fixes
This commit is contained in:
parent
e2a9d35bb1
commit
9bb8277583
|
@ -16,9 +16,7 @@ const stringFormat = require('./string_format');
|
|||
const fs = require('graceful-fs');
|
||||
const _ = require('lodash');
|
||||
const moment = require('moment');
|
||||
const iconv = require('iconv-lite');
|
||||
const { mkdirs } = require('fs-extra');
|
||||
const { stripMciColorCodes } = require('./color_codes.js');
|
||||
|
||||
const parseFullName = require('parse-full-name').parseFullName;
|
||||
|
||||
|
@ -43,6 +41,7 @@ module.exports = class DropFile {
|
|||
|
||||
this.dropFileFormatDirectory = paths.join(
|
||||
__dirname,
|
||||
'..',
|
||||
'dropfile_formats'
|
||||
);
|
||||
}
|
||||
|
@ -86,7 +85,7 @@ module.exports = class DropFile {
|
|||
// TODO: Replace with a switch statement once we have binary handlers as well
|
||||
|
||||
// Read the directory containing the dropfile formats, and return undefined if we don't have the format
|
||||
const fileName = this.fileName();
|
||||
const fileName = this.fileName;
|
||||
if (!fileName) {
|
||||
Log.info({fileType: this.fileType}, 'Dropfile format not supported.');
|
||||
return undefined;
|
||||
|
@ -105,28 +104,39 @@ module.exports = class DropFile {
|
|||
|
||||
getContents() {
|
||||
const handler = this.getHandler().bind(this);
|
||||
return handler();
|
||||
const contents = handler();
|
||||
return contents;
|
||||
}
|
||||
|
||||
getDropfile() {
|
||||
// Get the filename to read
|
||||
const fileName = paths.join(this.dropFileFormatDirectory, this.fileName());
|
||||
const fileName = paths.join(this.dropFileFormatDirectory, this.fileName);
|
||||
|
||||
let text = fs.readFileSync(fileName);
|
||||
|
||||
// Read file, or return empty string if it doesn't exist
|
||||
fs.readFile(fileName, (err, data) => {
|
||||
if (err) {
|
||||
Log.warn({filename: fileName}, 'Error reading dropfile format file.');
|
||||
return '';
|
||||
}
|
||||
let text = data;
|
||||
// Format the data with string_format and predefined_mci
|
||||
const formatObj = getPredefinedMCIFormatObject(this.client, data);
|
||||
let formatObj = getPredefinedMCIFormatObject(this.client, text);
|
||||
|
||||
const additionalFormatObj = {
|
||||
'getSysopFirstName': this.getSysopFirstName(),
|
||||
'getSysopLastName': this.getSysopLastName(),
|
||||
'getUserFirstName': this.getUserFirstName(),
|
||||
'getUserLastName': this.getUserLastName(),
|
||||
'getUserTotalDownloadK': this.getUserTotalDownloadK(),
|
||||
'getUserTotalUploadK': this.getUserTotalUploadK(),
|
||||
'getCurrentDateMMDDYY': this.getCurrentDateMMDDYY(),
|
||||
'getSystemDailyDownloadK': this.getSystemDailyDownloadK(),
|
||||
'getUserBirthDateMMDDYY': this.getUserBirthDateMMDDYY(),
|
||||
};
|
||||
|
||||
// Add additional format objects to the format object
|
||||
formatObj = _.merge(formatObj, additionalFormatObj);
|
||||
|
||||
if (formatObj) {
|
||||
// Expand the text
|
||||
text = stringFormat(text, formatObj, true);
|
||||
}
|
||||
return text;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
@ -166,6 +176,24 @@ module.exports = class DropFile {
|
|||
return StatLog.getUserStatNum(this.client.user, UserProps.FileDlTotalBytes) / 1024;
|
||||
}
|
||||
|
||||
getSystemDailyDownloadK() {
|
||||
return StatLog.getSystemStatNum(SysProps.getSystemDailyDownloadK) / 1024;
|
||||
}
|
||||
|
||||
getUserTotalUploadK() {
|
||||
return StatLog.getUserStatNum(this.client.user, UserProps.FileUlTotalBytes) / 1024;
|
||||
}
|
||||
|
||||
getCurrentDateMMDDYY() {
|
||||
// Return current date in MM/DD/YY format
|
||||
return moment().format('MM/DD/YY');
|
||||
}
|
||||
|
||||
getUserBirthDateMMDDYY() {
|
||||
// Return user's birthdate in MM/DD/YY format
|
||||
return moment(this.client.user.properties[UserProps.Birthdate]).format('MM/DD/YY');
|
||||
}
|
||||
|
||||
getDoorInfoFileName() {
|
||||
let x;
|
||||
const node = this.client.node;
|
||||
|
@ -179,13 +207,14 @@ module.exports = class DropFile {
|
|||
return 'DORINFO' + x + '.DEF';
|
||||
}
|
||||
|
||||
|
||||
createFile(cb) {
|
||||
mkdirs(paths.dirname(this.fullPath), err => {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
return fs.writeFile(this.fullPath, this.getContents(), cb);
|
||||
const fullPath = this.fullPath;
|
||||
const contents = this.getContents();
|
||||
return fs.writeFile(fullPath, contents, cb);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -127,9 +127,6 @@ const PREDEFINED_MCI_GENERATORS = {
|
|||
UZ: function sanitizedUserName(client) {
|
||||
return client.user.getSanitizedName();
|
||||
},
|
||||
UM: function userComment(client) {
|
||||
return userStatAsString(client, UserProps.UserComment, '');
|
||||
},
|
||||
LL: function legacyUserLevel(client) {
|
||||
return client.user.getLegacySecurityLevel().toString();
|
||||
},
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
{UA}
|
||||
M
|
||||
{AP}
|
||||
{DT}
|
||||
{getCurrentDateMMDDYY}
|
||||
{SW}
|
||||
{SH}
|
||||
{LL}
|
||||
|
@ -24,8 +24,8 @@ C:\DATA\BBS.LOG
|
|||
{SR}
|
||||
1
|
||||
0
|
||||
0
|
||||
{getUserTotalUploadK}
|
||||
{UP}
|
||||
0
|
||||
{getUserTotalDownloadK}
|
||||
{DN}
|
||||
8N1
|
|
@ -14,7 +14,7 @@ N
|
|||
NOT PROVIDED
|
||||
{LL}
|
||||
{UC}
|
||||
{DT}
|
||||
{getCurrentDateMMDDYY}
|
||||
9999
|
||||
999
|
||||
GR
|
||||
|
@ -27,9 +27,9 @@ N
|
|||
Y
|
||||
{UP}
|
||||
{DN}
|
||||
0
|
||||
{getSystemDailyDownloadK}
|
||||
9999999
|
||||
{BD}
|
||||
{getUserBirthDateMMDDYY}
|
||||
C:\DATA
|
||||
C:\DATA
|
||||
{SR}
|
||||
|
@ -40,13 +40,13 @@ Y
|
|||
Y
|
||||
7
|
||||
32767
|
||||
{DT}
|
||||
{getCurrentDateMMDDYY}
|
||||
{CT}
|
||||
{CT}
|
||||
9999
|
||||
{DD}
|
||||
0
|
||||
0
|
||||
{UM}
|
||||
{getUserTotalUploadK}
|
||||
{getUserTotalDownloadK}
|
||||
|
||||
{DR}
|
||||
32767
|
|
@ -1,11 +1,11 @@
|
|||
{BN}
|
||||
UNKNOWN
|
||||
UNKNOWN
|
||||
{getSysopFirstName}
|
||||
{getSysopLastName}
|
||||
COM1
|
||||
19200 BAUD,N,8,1
|
||||
0
|
||||
UNKNOWN
|
||||
UNKNOWN
|
||||
{getUserFirstName}
|
||||
{getUserLastName}
|
||||
{LO}
|
||||
1
|
||||
{LL}
|
||||
|
|
|
@ -7,7 +7,7 @@ Y
|
|||
999
|
||||
555-555-1212
|
||||
{LO}
|
||||
{BD}
|
||||
{getUserBirthDateMMDDYY}
|
||||
{ND}
|
||||
1
|
||||
19200
|
||||
|
|
Loading…
Reference in New Issue