Skip to content

Commit

Permalink
Merge pull request #29 from sbs20/development
Browse files Browse the repository at this point in the history
Linting and docs
  • Loading branch information
sbs20 authored May 2, 2020
2 parents b87b1d9 + 8510a23 commit 4bc9527
Show file tree
Hide file tree
Showing 14 changed files with 1,395 additions and 409 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ npm-debug.log*
pids
*.pid
*.seed
device.conf

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
Expand Down
26 changes: 13 additions & 13 deletions classes/Config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module.exports = {
Port: 8080,
IsTrace: true,
TraceLineEnding: '',
DeviceName: null,
Scanimage: '/usr/bin/scanimage',
Convert: '/usr/bin/convert',
IgnoreStdError: '2>/dev/null',
BypassSystemExecute: false,
OutputDirectory: './data/output/',
PreviewDirectory: './data/preview/',
MaximumScanWidthInMm: 215,
MaximumScanHeightInMm: 297,
PreviewResolution: 100
Port: 8080,
IsTrace: true,
TraceLineEnding: '',
DeviceName: null,
Scanimage: '/usr/bin/scanimage',
Convert: '/usr/bin/convert',
IgnoreStdError: '2>/dev/null',
BypassSystemExecute: false,
OutputDirectory: './data/output/',
PreviewDirectory: './data/preview/',
MaximumScanWidthInMm: 215,
MaximumScanHeightInMm: 297,
PreviewResolution: 100
};
2 changes: 0 additions & 2 deletions classes/Convert.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
var fs = require('fs');
var Q = require('kew');

var Config = require('./Config');
var System = require('./System');

Expand Down
4 changes: 2 additions & 2 deletions classes/Device.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ module.exports = function () {
/// Executes scanimageA and returns a promise of parsed results
var scanimageA = function () {
var cmd = Config.Scanimage;
if(Config.DeviceName){
cmd += ' -d "'+Config.DeviceName+'"';
if (Config.DeviceName) {
cmd += ' -d "' + Config.DeviceName + '"';
}
cmd += ' -A';

Expand Down
95 changes: 47 additions & 48 deletions classes/FileInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,51 @@ var path = require('path');

module.exports = function (fullpath) {

this.fullname = fullpath;

this.init = function () {
this.name = path.basename(this.fullname);
this.path = path.dirname(this.fullname);

if (this.exists()) {
var stat = fs.statSync(this.fullname);
this.extension = path.extname(this.fullname);
this.lastModified = stat.mtime;
this.size = stat.size;
}
};

this.delete = function () {
try {
fs.unlinkSync(this.fullname);
this.deleted = true;
}
catch (e) {
this.deleted = false;
}

return this;
};

this.exists = function () {
return fs.existsSync(this.fullname);
};

this.toBuffer = function () {
var bits = fs.readFileSync(this.fullname);
return new Buffer(bits);
};

this.toBase64 = function () {
return this.toBuffer().toString('base64');
};

this.toText = function () {
return this.toBuffer().toString();
};

this.save = function (data) {
fs.writeFileSync(this.fullname, data);
};

this.init();
this.fullname = fullpath;

this.init = function () {
this.name = path.basename(this.fullname);
this.path = path.dirname(this.fullname);

if (this.exists()) {
var stat = fs.statSync(this.fullname);
this.extension = path.extname(this.fullname);
this.lastModified = stat.mtime;
this.size = stat.size;
}
};

this.delete = function () {
try {
fs.unlinkSync(this.fullname);
this.deleted = true;
} catch (e) {
this.deleted = false;
}

return this;
};

this.exists = function () {
return fs.existsSync(this.fullname);
};

this.toBuffer = function () {
var bits = fs.readFileSync(this.fullname);
return new Buffer(bits);
};

this.toBase64 = function () {
return this.toBuffer().toString('base64');
};

this.toText = function () {
return this.toBuffer().toString();
};

this.save = function (data) {
fs.writeFileSync(this.fullname, data);
};

this.init();
};
105 changes: 52 additions & 53 deletions classes/ScanRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,75 +3,74 @@ var Config = require('./Config');
var System = require('./System');

var ScanRequest = function (def) {
var _this = this;

_this = this;
System.extend(_this, ScanRequest.default, def);
if (!_this.outputFilepath) {
var dateString = dateFormat(new Date(), 'yyyy-mm-dd HH.MM.ss');
_this.outputFilepath = Config.OutputDirectory + 'scan_' + dateString + '.' + _this.convertFormat;
}

System.extend(_this, ScanRequest.default, def);
if (!_this.outputFilepath) {
var dateString = dateFormat(new Date(), 'yyyy-mm-dd HH.MM.ss');
_this.outputFilepath = Config.OutputDirectory + 'scan_' + dateString + '.' + _this.convertFormat;
}
_this.validate = function () {
var errors = [];

_this.validate = function (device) {
var errors = [];
if (_this.mode === undefined) {
errors.push('Invalid mode: ' + _this.mode);
}

if (_this.mode === undefined) {
errors.push('Invalid mode: ' + _this.mode);
}
if (!Number.isInteger(_this.width)) {
errors.push('Invalid width: ' + _this.width);
}

if (!Number.isInteger(_this.width)) {
errors.push('Invalid width: ' + _this.width);
}
if (!Number.isInteger(_this.height)) {
errors.push('Invalid height: ' + _this.height);
}

if (!Number.isInteger(_this.height)) {
errors.push('Invalid height: ' + _this.height);
}
if (!Number.isInteger(_this.top)) {
errors.push('Invalid top: ' + _this.top);
}

if (!Number.isInteger(_this.top)) {
errors.push('Invalid top: ' + _this.top);
}
if (!Number.isInteger(_this.left)) {
errors.push('Invalid left: ' + _this.left);
}

if (!Number.isInteger(_this.left)) {
errors.push('Invalid left: ' + _this.left);
}
if (!Number.isInteger(_this.brightness)) {
errors.push('Invalid brightness: ' + _this.brightness);
}

if (!Number.isInteger(_this.brightness)) {
errors.push('Invalid brightness: ' + _this.brightness);
}
if (!Number.isInteger(_this.contrast)) {
errors.push('Invalid contrast: ' + _this.contrast);
}

if (!Number.isInteger(_this.contrast)) {
errors.push('Invalid contrast: ' + _this.contrast);
}
if ('depth' in _this && !Number.isInteger(_this.depth)) {
errors.push('Invalid depth: ' + _this.depth);
}

if ('depth' in _this && !Number.isInteger(_this.depth)) {
errors.push('Invalid depth: ' + _this.depth);
}
if (_this.top + _this.height > Config.MaximumScanHeightInMm) {
errors.push('Top + height exceed maximum dimensions');
}

if (_this.top + _this.height > Config.MaximumScanHeightInMm) {
errors.push('Top + height exceed maximum dimensions');
}
if (['tif', 'jpg', 'png'].indexOf(_this.convertFormat) === -1) {
errors.push('Invalid format type');
}

if (['tif', 'jpg', 'png'].indexOf(_this.convertFormat) === -1) {
errors.push('Invalid format type');
}

return errors;
};
return errors;
};
};

ScanRequest.default = {
top: 0,
left: 0,
width: Config.MaximumScanWidthInMm,
height: Config.MaximumScanHeightInMm,
mode: "Color",
resolution: 200,
format: "tiff",
outputFilepath: "",
brightness: 0,
contrast: 0,
convertFormat: 'tif',
dynamicLineart: true
top: 0,
left: 0,
width: Config.MaximumScanWidthInMm,
height: Config.MaximumScanHeightInMm,
mode: "Color",
resolution: 200,
format: "tiff",
outputFilepath: "",
brightness: 0,
contrast: 0,
convertFormat: 'tif',
dynamicLineart: true
};

module.exports = ScanRequest;
Loading

0 comments on commit 4bc9527

Please sign in to comment.