Better handling of TIC import descriptions

* Add descPriority config option (default='diz')
* Really prefer diz/ldesc over *generated* descriptions e.g. from filename or info extractors
This commit is contained in:
Bryan Ashby 2017-10-01 11:07:49 -06:00
parent 1ad7ce848a
commit af52ed6153
3 changed files with 30 additions and 9 deletions

View File

@ -639,6 +639,7 @@ function getDefaultConfig() {
secureInOnly : true, // only bring in from secure inbound (|secInbound| path, password protected)
uploadBy : 'ENiGMA TIC', // default upload by username (override @ network)
allowReplace : false, // use "Replaces" TIC field
descPriority : 'diz', // May be diz=.DIZ/etc., or tic=from TIC Ldesc
}
}
},

View File

@ -356,7 +356,8 @@ function extractAndProcessDescFiles(fileEntry, filePath, archiveEntries, cb) {
// Assume FILE_ID.DIZ, NFO files, etc. are CP437.
//
// :TODO: This isn't really always the case - how to handle this? We could do a quick detection...
fileEntry[descType] = iconv.decode(sliceAtSauceMarker(data, 0x1a), 'cp437');
fileEntry[descType] = iconv.decode(sliceAtSauceMarker(data, 0x1a), 'cp437');
fileEntry[`${descType}Src`] = 'descFile';
return next(null);
});
});
@ -404,7 +405,8 @@ function extractAndProcessSingleArchiveEntry(fileEntry, filePath, archiveEntries
function processSingleExtractedFile(extractedFile, callback) {
populateFileEntryInfoFromFile(fileEntry, extractedFile, err => {
if(!fileEntry.desc) {
fileEntry.desc = getDescFromFileName(filePath);
fileEntry.desc = getDescFromFileName(filePath);
fileEntry.descSrc = 'fileName';
}
return callback(err);
});
@ -529,7 +531,8 @@ function populateFileEntryInfoFromFile(fileEntry, filePath, cb) {
stdout = (wordWrapText( stdout, { width : 45 } ).wrapped || []).join('\n');
}
fileEntry[key] = stdout;
fileEntry[key] = stdout;
fileEntry[`${key}Src`] = 'infoTool';
}
}
@ -551,7 +554,8 @@ function populateFileEntryNonArchive(fileEntry, filePath, stepInfo, iterator, cb
function getDescriptions(callback) {
populateFileEntryInfoFromFile(fileEntry, filePath, err => {
if(!fileEntry.desc) {
fileEntry.desc = getDescFromFileName(filePath);
fileEntry.desc = getDescFromFileName(filePath);
fileEntry.descSrc = 'fileName';
}
return callback(err);
});

View File

@ -1321,7 +1321,7 @@ function FTNMessageScanTossModule() {
// Lastly, we will only replace if the item is in the same/specified area
// and that come from the same origin as a previous entry.
//
const allowReplace = _.get(Config.scannerTossers.ftn_bso.nodes, [ localInfo.node, 'tic', 'allowReplace' ] ) || Config.scannerTossers.ftn_bso.tic.allowReplace;
const allowReplace = _.get(Config.scannerTossers.ftn_bso.nodes, [ localInfo.node, 'tic', 'allowReplace' ], Config.scannerTossers.ftn_bso.tic.allowReplace);
const replaces = ticFileInfo.getAsString('Replaces');
if(!allowReplace || !replaces) {
@ -1377,7 +1377,7 @@ function FTNMessageScanTossModule() {
short_file_name : ticFileInfo.getAsString('File').toUpperCase(), // upper to ensure no case issues later; this should be a DOS 8.3 name
tic_origin : ticFileInfo.getAsString('Origin'),
tic_desc : ticFileInfo.getAsString('Desc'),
upload_by_username : _.get(Config.scannerTossers.ftn_bso.nodes, [ localInfo.node, 'tic', 'uploadBy' ]) || Config.scannerTossers.ftn_bso.tic.uploadBy,
upload_by_username : _.get(Config.scannerTossers.ftn_bso.nodes, [ localInfo.node, 'tic', 'uploadBy' ], Config.scannerTossers.ftn_bso.tic.uploadBy),
}
};
@ -1432,9 +1432,25 @@ function FTNMessageScanTossModule() {
localInfo.fileEntry.areaTag = localInfo.areaTag;
localInfo.fileEntry.fileName = ticFileInfo.longFileName;
// we default to .DIZ/etc. desc, but use from TIC if needed
if(!localInfo.fileEntry.desc || 0 === localInfo.fileEntry.desc.length) {
localInfo.fileEntry.desc = ticFileInfo.getAsString('Ldesc') || ticFileInfo.getAsString('Desc') || getDescFromFileName(ticFileInfo.filePath);
//
// We may now have two descriptions: from .DIZ/etc. or the TIC itself.
// Determine which one to use using |descPriority| and availability.
//
// We will still fallback as needed from <priority1> -> <priority2> -> <fromFileName>
//
const descPriority = _.get(
Config.scannerTossers.ftn_bso.nodes, [ localInfo.node, 'tic', 'descPriority' ],
Config.scannerTossers.ftn_bso.tic.descPriority
);
if('tic' === descPriority) {
const origDesc = localInfo.fileEntry.desc;
localInfo.fileEntry.desc = ticFileInfo.getAsString('Ldesc') || origDesc || getDescFromFileName(ticFileInfo.filePath);
} else {
// see if we got desc from .DIZ/etc.
const fromDescFile = 'descFile' === localInfo.fileEntry.descSrc;
localInfo.fileEntry.desc = fromDescFile ? localInfo.fileEntry.desc : ticFileInfo.getAsString('Ldesc');
localInfo.fileEntry.desc = localInfo.fileEntry.desc || getDescFromFileName(ticFileInfo.filePath);
}
const areaStorageDir = getAreaStorageDirectoryByTag(storageTag);