Skip to content

Commit

Permalink
Merge pull request #309 from sbs20/staging
Browse files Browse the repository at this point in the history
Optional --mode and configurable timeout
  • Loading branch information
sbs20 authored Jun 15, 2021
2 parents 8081f02 + 6626917 commit cf5f2f6
Show file tree
Hide file tree
Showing 17 changed files with 96 additions and 18 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scanservjs",
"version": "2.15.3",
"version": "2.16.0",
"description": "scanservjs is a simple web-based UI for SANE which allows you to share a scanner on a network without the need for drivers or complicated installation.",
"scripts": {
"clean": "rm -rf ./dist",
Expand Down
4 changes: 2 additions & 2 deletions packages/client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scanservjs",
"version": "2.15.3",
"version": "2.16.0",
"description": "scanservjs is a simple web-based UI for SANE which allows you to share a scanner on a network without the need for drivers or complicated installation.",
"author": "Sam Strachan",
"scripts": {
Expand Down
6 changes: 4 additions & 2 deletions packages/client/src/classes/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ export default class Request {
left: request.params.left || device.features['-l'].default,
width: request.params.width || device.features['-x'].default,
height: request.params.height || device.features['-y'].default,
resolution: request.params.resolution || device.features['--resolution'].default,
mode: request.params.mode || device.features['--mode'].default
resolution: request.params.resolution || device.features['--resolution'].default
},
filters: request.filters || [],
pipeline: request.pipeline || pipeline,
batch: request.batch || (batchMode === undefined ? 'none' : batchMode),
index: 1
};

if ('--mode' in device.features) {
obj.params.mode = request.params.mode || device.features['--mode'].default;
}
if ('--source' in device.features) {
obj.params.source = request.params.source || device.features['--source'].default;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/components/Scan.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
:label="$t('scan.resolution')" v-model="request.params.resolution"
:items="device.features['--resolution']['options']"></v-select>

<v-select
<v-select v-if="'--mode' in device.features"
:label="$t('scan.mode')" v-model="request.params.mode"
:items="modes" item-value="value" item-text="text"></v-select>

Expand Down
4 changes: 2 additions & 2 deletions packages/server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scanservjs-server",
"version": "2.15.3",
"version": "2.16.0",
"description": "scanservjs is a simple web-based UI for SANE which allows you to share a scanner on a network without the need for drivers or complicated installation.",
"scripts": {
"lint": "gulp lint",
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Config {
Object.assign(this, {
version: Package.version,
port: 8080,
timeout: 120000,
devices: [],
ocrLanguage: 'eng',
log: {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class Device {
}

validate() {
const mandatory = ['--mode', '--resolution', '-l', '-t', '-x', '-y'];
const mandatory = ['--resolution', '-l', '-t', '-x', '-y'];
for (const feature of mandatory) {
if (this.features[feature] === undefined) {
throw `${feature} is missing from device`;
Expand Down
4 changes: 3 additions & 1 deletion packages/server/src/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class Request {
width: bound(data.params.width, features['-x'].limits[0], features['-x'].limits[1], features['-x'].limits[1]),
height: bound(data.params.height, features['-y'].limits[0], features['-y'].limits[1], features['-y'].limits[1]),
resolution: data.params.resolution || features['--resolution'].default,
mode: data.params.mode || features['--mode'].default,
format: 'tiff'
},
filters: data.filters || [],
Expand All @@ -40,6 +39,9 @@ class Request {
index: data.index || 1
});

if ('--mode' in features) {
this.params.mode = data.params.mode || features['--mode'].default;
}
if ('--source' in features) {
this.params.source = data.params.source || features['--source'].default;
}
Expand Down
7 changes: 5 additions & 2 deletions packages/server/src/scanimage.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ class Scanimage {
log.debug(JSON.stringify(request));
const params = request.params;
const cmdBuilder = new CmdBuilder(Config.scanimage);
cmdBuilder.arg('-d', params.deviceId)
.arg('--mode', params.mode);
cmdBuilder.arg('-d', params.deviceId);

if ('mode' in params) {
cmdBuilder.arg('--mode', params.mode);
}

// Source needs to go before resolution
if ('source' in params) {
Expand Down
4 changes: 3 additions & 1 deletion packages/server/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ app.use(express.static('client'));

configure(app);

app.listen(Config.port, () => {
const server = app.listen(Config.port, () => {
log.info('Started');
});

server.setTimeout(Config.timeout);
3 changes: 2 additions & 1 deletion packages/server/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
* @typedef {Object} Configuration
* @property {string} version
* @property {number} port
* @property {number} timeout
* @property {string[]} devices
* @property {boolean} devicesFind
* @property {string} ocrLanguage
Expand Down Expand Up @@ -84,7 +85,7 @@
* @property {number} width
* @property {number} height
* @property {number} resolution
* @property {string} mode
* @property {string} [mode]
* @property {string} format
* @property {string} [source]
* @property {number} [brightness]
Expand Down
21 changes: 21 additions & 0 deletions packages/server/test/device.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,25 @@ describe('Device', () => {
assert.strictEqual(device.features['--brightness'], undefined);
assert.strictEqual(device.features['--contrast'], undefined);
});

it('scanimage-a8.txt', () => {
const file = FileInfo.create('test/resource/scanimage-a8.txt');
const device = Device.from(file.toText());

assert.strictEqual(device.id, 'umax1220u:libusb:001:004');
assert.deepStrictEqual(device.features['--resolution'].options, [75, 150, 300, 600]);
assert.strictEqual(device.features['--resolution'].default, 75);
assert.strictEqual(device.features['-l'].limits[0], 0);
assert.strictEqual(device.features['-l'].limits[1], 228.6);
assert.strictEqual(device.features['-l'].default, 0);
assert.strictEqual(device.features['-t'].limits[0], 0);
assert.strictEqual(device.features['-t'].limits[1], 298);
assert.strictEqual(device.features['-t'].default, 0);
assert.strictEqual(device.features['-x'].limits[0], 0);
assert.strictEqual(device.features['-x'].limits[1], 228.6);
assert.strictEqual(device.features['-x'].default, 228.6);
assert.strictEqual(device.features['-y'].limits[0], 0);
assert.strictEqual(device.features['-y'].limits[1], 298);
assert.strictEqual(device.features['-y'].default, 298);
});
});
33 changes: 33 additions & 0 deletions packages/server/test/request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,37 @@ describe('Request', () => {
assert.strictEqual(request.params.contrast, undefined);
assert.strictEqual(request.params.dynamicLineart, undefined);
});

it('scanimage-a8.txt', () => {
const file = FileInfo.create('test/resource/scanimage-a8.txt');
const device = Device.from(file.toText());
const context = new Context([device]);
const request = new Request(context).extend({
params: {
deviceId: 'umax1220u:libusb:001:004',
top: -1,
left: -20,
width: 400,
height: 400,
resolution: '150',
mode: 'Color',
brightness: 0,
contrast: 0,
dynamicLineart: true
},
pipeline: 'test-pipeline'
});

assert.strictEqual(request.params.deviceId, 'umax1220u:libusb:001:004');
assert.strictEqual(request.params.mode, undefined);
assert.strictEqual(request.params.resolution, '150');
assert.strictEqual(request.params.left, 0);
assert.strictEqual(request.params.top, 0);
assert.strictEqual(request.params.width, 228.6);
assert.strictEqual(request.params.height, 298);
assert.strictEqual(request.params.brightness, undefined);
assert.strictEqual(request.params.contrast, undefined);
assert.strictEqual(request.params.dynamicLineart, undefined);
});

});
13 changes: 13 additions & 0 deletions packages/server/test/resource/scanimage-a8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
All options specific to device `umax1220u:libusb:001:004':
--resolution auto||75|150|300|600dpi [75]
Sets the resolution of the scanned image.
--gray[=(yes|no)] [no]
Do a grayscale rather than color scan
-l 0..228.6mm [0]
Top-left x position of scan area.
-t 0..298.027mm [0]
Top-left y position of scan area.
-x 0..228.6mm [228.6]
Width of scan-area.
-y 0..298.027mm [298.027]
Height of scan-area.

0 comments on commit cf5f2f6

Please sign in to comment.