Skip to content

Commit

Permalink
Merge pull request #248 from sbs20/development
Browse files Browse the repository at this point in the history
Improved browser support; translations; graceful upgrade
  • Loading branch information
sbs20 authored May 13, 2021
2 parents b4365b4 + a637dcd commit 0c02f2a
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ echo "docker: $(docker -v)"
cat /etc/*release | sed ':a;N;$!ba;s/\n/; /g'

# Logs if installed manually
sudo journalctl | grep server.js > scanservjs.log.installed.txt
sudo journalctl -u scanservjs | gzip > scanservjs.log.installed.txt.gz

# Logs if in docker
docker logs scanservjs-container > scanservjs.log.docker.txt
Expand Down
23 changes: 23 additions & 0 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Troubleshooting

## JSON.parse error

This happens when the browser received a string from the server which is not a
valid JSON string. Most likely you're running a proxy server (e.g. nginx) which
is timing out prior to the completion of the request. Scanservjs can sometimes
take a little while to fulfil its requests - usually because it's waiting for a
scanner, but sometimes because it's having to do a fair amount of image
processing and you're
[running on a low power CPU (e.g. RPi)](https://github.com/sbs20/scanservjs/issues/224).

The solution is to increase the proxy timeout. For nginx that might look like:

```
server{
...
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_send_timeout 300;
...
}
```
4 changes: 2 additions & 2 deletions 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 server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scanservjs-server",
"version": "2.12.2",
"version": "2.12.3",
"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. scanserv does not do image conversion or manipulation (beyond the bare minimum necessary for the purposes of browser preview) or OCR.",
"scripts": {
"serve": "nodemon --exec 'vue-cli-service serve'",
Expand Down
12 changes: 10 additions & 2 deletions server/src/device.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const extend = require('./util').extend;
const Config = require('./config');

/**
* @param {number} n
Expand Down Expand Up @@ -118,7 +117,6 @@ class Adapter {
/** @type {ScanDevice} */
let device = {
'id': '',
'version': Config.version,
'features': {}
};

Expand Down Expand Up @@ -156,6 +154,15 @@ class Device {
constructor() {
}

validate() {
const mandatory = ['--mode', '--resolution', '-l', '-t', '-x', '-y'];
for (const feature of mandatory) {
if (this.features[feature] === undefined) {
throw `${feature} is missing from device`;
}
}
}

/**
* @param {any|string} o
* @returns {ScanDevice}
Expand All @@ -165,6 +172,7 @@ class Device {
if (typeof o === 'object') {
const decorated = Adapter.decorate(o);
extend(device, decorated);
device.validate();
return device;
} else if (typeof o === 'string') {
const data = Adapter.parse(o);
Expand Down
22 changes: 11 additions & 11 deletions server/src/devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ class Devices {
*/
static from(o) {
if (typeof o === 'object') {
const devices = [];
if (Array.isArray(o)) {
for (let d of o) {
devices.push(Device.from(d));
try {
const devices = [];
if (Array.isArray(o)) {
for (let d of o) {
devices.push(Device.from(d));
}
}
return devices;
} catch (exception) {
log.warn(exception);
return [];
}
return devices;
} else {
throw new Error('Unexpected data for Devices');
}
Expand All @@ -46,12 +51,7 @@ class Devices {

if (file.exists()) {
devices = Devices.from(file.toJson());
if (devices.length > 0) {
if (devices[0].version !== Config.version) {
log.debug('devices.json version is old. Reloading');
devices = null;
}
} else {
if (devices.length === 0) {
log.debug('devices.json contains no devices. Reloading');
devices = null;
}
Expand Down
2 changes: 1 addition & 1 deletion webui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"vuetify-loader": "^1.7.2"
},
"browserslist": [
"> 1%",
"> 0.2%",
"last 2 versions",
"not dead"
],
Expand Down
60 changes: 34 additions & 26 deletions webui/src/classes/request.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,49 @@
import Constants from './constants';

export default {
create(request, device, pipeline) {
if (request === null) {
request = {
version: Constants.Version,
params: {
deviceId: device.id,
top: device.features['-t'].default,
left: device.features['-l'].default,
width: device.features['-x'].default,
height: device.features['-y'].default,
resolution: device.features['--resolution'].default,
mode: device.features['--mode'].default
},
filters: [],
pipeline: pipeline,
batch: 'none',
index: 1
};
}
export default class Request {
/**
* @param {Request} request
* @param {Device} device
* @param {string} pipeline
* @param {string} batchMode
* @returns
*/
static create(request, device, pipeline, batchMode) {
request = request || {};
request.params = request.params || {};

const obj = {
version: Constants.Version,
params: {
deviceId: device.id,
top: request.params.top || device.features['-t'].default,
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
},
filters: request.filters || [],
pipeline: request.pipeline || pipeline,
batch: request.batch || batchMode === undefined ? 'none' : batchMode,
index: 1
};

if ('--source' in device.features) {
request.params.source = request.params.source || device.features['--source'].default;
obj.params.source = request.params.source || device.features['--source'].default;
}
if ('--brightness' in device.features) {
request.params.brightness = request.params.brightness || device.features['--brightness'].default;
obj.params.brightness = request.params.brightness || device.features['--brightness'].default;
}
if ('--contrast' in device.features) {
request.params.contrast = request.params.contrast || device.features['--contrast'].default;
obj.params.contrast = request.params.contrast || device.features['--contrast'].default;
}
if ('--disable-dynamic-lineart' in device.features) {
request.params.dynamicLineart = request.params.dynamicLineart !== undefined
obj.params.dynamicLineart = request.params.dynamicLineart !== undefined
? request.params.dynamicLineart
: true;
}

return request;
return obj;
}
};
}
10 changes: 1 addition & 9 deletions webui/src/classes/storage.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import Constants from './constants';
import Settings from './settings';

let storage = null;

export default class Storage {

get request() {
let request = null;
if (localStorage.request) {
request = JSON.parse(localStorage.request);
if (request.version !== Constants.Version) {
request = null;
}
}
return request;
return localStorage.request ? JSON.parse(localStorage.request) : null;
}

set request(request) {
Expand Down
2 changes: 1 addition & 1 deletion webui/src/components/Scan.vue
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ export default {
buildRequest() {
let request = storage.request;
if (request !== null) {
if (request && request.params) {
this.device = this.context.devices.filter(d => d.id === request.params.deviceId)[0]
|| this.context.devices[0];
}
Expand Down
42 changes: 21 additions & 21 deletions webui/src/locales/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@
},

"colors": {
"accent-4": "Default",
"red": "Red",
"pink": "Pink",
"purple": "Purple",
"deep-purple": "Deep purple",
"accent-4": "Výchozí",
"red": "Červená",
"pink": "Růžová",
"purple": "Fialová",
"deep-purple": "Tmavě fialová",
"indigo": "Indigo",
"blue": "Blue",
"light-blue": "Light blue",
"cyan": "Cyan",
"teal": "Teal",
"green": "Green",
"light-green": "Light green",
"lime": "Lime",
"yellow": "Yellow",
"amber": "Amber",
"orange": "Orange",
"deep-orange": "Deep orange",
"brown": "Brown",
"blue-grey": "Blue grey",
"grey": "Grey"
"blue": "Modrá",
"light-blue": "Světle modrá",
"cyan": "Azurová",
"teal": "Šedozelená",
"green": "Zelená",
"light-green": "Světle zelená",
"lime": "Limetková",
"yellow": "Žlutá",
"amber": "Jantarová",
"orange": "Oranžová",
"deep-orange": "Tmavě oranžová",
"brown": "Hnědá",
"blue-grey": "Šedomodrá",
"grey": "Šedá"
},

"batch-dialog": {
Expand Down Expand Up @@ -144,7 +144,7 @@
"theme:system": "Podle systému",
"theme:light": "Světlý",
"theme:dark": "Tmavý",
"color": "Colour",
"color:description": "Colour. This will change the colour of the top app bar."
"color": "Barva",
"color:description": "Barva. Toto nastavení změní barvu horního panelu."
}
}
Loading

0 comments on commit 0c02f2a

Please sign in to comment.