docparse-scraper-add
Version:
Setup to process a scraper data add api request
36 lines (34 loc) • 1.03 kB
JavaScript
/**
* Parse an upload with ocr text and extract the relevant data. The parsing will
* be supplier-specific, so here we just perform the common setup steps and pass
* the upload to the appropriate supplier specific code
*/
var inspect = require('eyespect').inspector({maxLength:20000});
module.exports = function(supplierCode, cb) {
// get the supplier;
if (!cb) {
cb = supplierCode;
return cb('you must a supplierCode');
}
var moduleName = 'docparse-supplier-'+supplierCode.toLowerCase();
var lib = getLib(moduleName);
if (!lib) {
return cb('failed to get supplier module with name: ' + moduleName);
}
if (!lib.scraperProcessData) {
return cb('module ' + moduleName + ' does not export the scraperProcessData function as demanded');
}
cb(null, lib);
};
function getLib(moduleName) {
try {
var lib = require(moduleName);
if (!lib) {
return null;
}
return lib;
} catch(err) {
inspect(err, 'error loading supplier module for scraper add');
return null;
}
}