diff --git a/package-lock.json b/package-lock.json index 7fe13dae..86058638 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "scanservjs", - "version": "2.15.3", + "version": "2.16.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "scanservjs", - "version": "2.15.3", + "version": "2.16.0", "hasInstallScript": true, "license": "GPL-2.0" } diff --git a/package.json b/package.json index 1cee3c1a..cd114377 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/client/package-lock.json b/packages/client/package-lock.json index 6139af4e..f2b22c92 100644 --- a/packages/client/package-lock.json +++ b/packages/client/package-lock.json @@ -1,12 +1,12 @@ { "name": "scanservjs", - "version": "2.15.3", + "version": "2.16.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "scanservjs", - "version": "2.15.3", + "version": "2.16.0", "license": "GPL-2.0", "dependencies": { "@mdi/font": "^5.9.55", diff --git a/packages/client/package.json b/packages/client/package.json index c1025479..25fc07f1 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -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": { diff --git a/packages/client/src/classes/request.js b/packages/client/src/classes/request.js index 94b0f2ee..ea8a83fa 100644 --- a/packages/client/src/classes/request.js +++ b/packages/client/src/classes/request.js @@ -20,8 +20,7 @@ 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, @@ -29,6 +28,9 @@ export default class Request { 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; } diff --git a/packages/client/src/components/Scan.vue b/packages/client/src/components/Scan.vue index b823a7e1..62f17831 100644 --- a/packages/client/src/components/Scan.vue +++ b/packages/client/src/components/Scan.vue @@ -16,7 +16,7 @@ :label="$t('scan.resolution')" v-model="request.params.resolution" :items="device.features['--resolution']['options']"> - diff --git a/packages/server/package-lock.json b/packages/server/package-lock.json index 4121e0c3..9a2e1c0b 100644 --- a/packages/server/package-lock.json +++ b/packages/server/package-lock.json @@ -1,12 +1,12 @@ { "name": "scanservjs-server", - "version": "2.15.3", + "version": "2.16.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "scanservjs-server", - "version": "2.15.3", + "version": "2.16.0", "license": "GPL-2.0", "dependencies": { "adm-zip": "^0.5.5", diff --git a/packages/server/package.json b/packages/server/package.json index 6e60fe2e..22c6c8dc 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -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", diff --git a/packages/server/src/config.js b/packages/server/src/config.js index 1a9ec6c0..ad8407fd 100644 --- a/packages/server/src/config.js +++ b/packages/server/src/config.js @@ -15,6 +15,7 @@ class Config { Object.assign(this, { version: Package.version, port: 8080, + timeout: 120000, devices: [], ocrLanguage: 'eng', log: { diff --git a/packages/server/src/device.js b/packages/server/src/device.js index b7b18718..d8061eaa 100644 --- a/packages/server/src/device.js +++ b/packages/server/src/device.js @@ -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`; diff --git a/packages/server/src/request.js b/packages/server/src/request.js index ee8ef6a1..52c103bc 100644 --- a/packages/server/src/request.js +++ b/packages/server/src/request.js @@ -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 || [], @@ -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; } diff --git a/packages/server/src/scanimage.js b/packages/server/src/scanimage.js index 141dfb9e..994b1659 100644 --- a/packages/server/src/scanimage.js +++ b/packages/server/src/scanimage.js @@ -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) { diff --git a/packages/server/src/server.js b/packages/server/src/server.js index b34d8c12..5d23a696 100644 --- a/packages/server/src/server.js +++ b/packages/server/src/server.js @@ -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); diff --git a/packages/server/src/types.js b/packages/server/src/types.js index 31a16478..5bd1ca56 100644 --- a/packages/server/src/types.js +++ b/packages/server/src/types.js @@ -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 @@ -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] diff --git a/packages/server/test/device.test.js b/packages/server/test/device.test.js index 1162ae64..d96554e8 100644 --- a/packages/server/test/device.test.js +++ b/packages/server/test/device.test.js @@ -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); + }); }); \ No newline at end of file diff --git a/packages/server/test/request.test.js b/packages/server/test/request.test.js index 33da5d79..e1d3e9af 100644 --- a/packages/server/test/request.test.js +++ b/packages/server/test/request.test.js @@ -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); + }); + }); \ No newline at end of file diff --git a/packages/server/test/resource/scanimage-a8.txt b/packages/server/test/resource/scanimage-a8.txt new file mode 100644 index 00000000..f2d94741 --- /dev/null +++ b/packages/server/test/resource/scanimage-a8.txt @@ -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. \ No newline at end of file