Skip to content

Commit

Permalink
Merge pull request #270 from sbs20/staging
Browse files Browse the repository at this point in the history
Proxy; Batch persistence; Locale names
  • Loading branch information
sbs20 authored May 20, 2021
2 parents aeebdb6 + d01e8b8 commit 7297e68
Show file tree
Hide file tree
Showing 25 changed files with 225 additions and 86 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ It supports any
* [Manual installation](docs/install.md)
* [Docker installation](docs/docker.md)
* [Scanner and SANE setup](docs/sane.md)
* [Proxy setup](docs/proxy.md)
* [Troubleshooting](docs/troubleshooting.md)
* [Development notes](docs/development.md)

## Configuration and device override
Expand Down
58 changes: 58 additions & 0 deletions docs/proxy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
## Reverse proxy

scanservjs supports reverse proxying and uses relative paths throughout so no
URL rewriting should be required.

### Apache

Example setup using a debian based distro.

```sh
sudo apt install apache2
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo nano /etc/apache2/sites-available/000-default.conf
```

Then add the following to a virtual host:

```
<Location /scanner/>
ProxyPass "http://127.0.0.1:8080/"
ProxyPassReverse "http://127.0.0.1:8080/"
</Location>
```

And restart

```sh
sudo systemctl restart apache2
```

## nginx

```sh
sudo apt install nginx
```

Edit your settings (e.g. `sudo nano /etc/nginx/sites-available/default`)

And add the following inside your chosen server block

```
# Increase timeouts since scan operations can take some time
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_send_timeout 300;
location /scanner/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://127.0.0.1:8080/;
}
```

Restart

```sh
sudo systemctl restart nginx
```
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.13.0",
"version": "2.14.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.13.0",
"version": "2.14.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
2 changes: 1 addition & 1 deletion packages/client/src/classes/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class Request {
},
filters: request.filters || [],
pipeline: request.pipeline || pipeline,
batch: request.batch || batchMode === undefined ? 'none' : batchMode,
batch: request.batch || (batchMode === undefined ? 'none' : batchMode),
index: 1
};

Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/components/Files.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default {
fileRemove(file) {
this.$emit('mask', 1);
Common.fetch('files/' + encodeURIComponent(file.fullname), {
Common.fetch(`files/${file.name}`, {
method: 'DELETE'
}).then(data => {
this.$emit('notify', { type: 'i', message: `${this.$t('files.message:deleted')} ${data.name}` });
Expand All @@ -62,7 +62,7 @@ export default {
},
open(file) {
window.location.href = 'files/' + encodeURIComponent(file.fullname);
window.location.href = `files/${file.name}`;
}
}
};
Expand Down
18 changes: 14 additions & 4 deletions packages/client/src/components/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
</template>
<template v-slot:action>
<div style="max-width: 10rem;">
<v-select :label="$t('settings.locale')" :items="locales" v-model="settings.locale" @change="reload"></v-select>
<v-select :label="$t('settings.locale')" :items="locales"
item-text="text" item-value="value"
v-model="settings.locale" @change="reload"></v-select>
</div>
</template>
</settings-item>
Expand Down Expand Up @@ -95,8 +97,7 @@ export default {
data() {
return {
settings: storage.settings,
locales: Constants.Locales
settings: storage.settings
};
},
Expand All @@ -110,6 +111,15 @@ export default {
});
},
locales() {
return Constants.Locales.map(l => {
return {
text: this.$t(`locales.${l}`),
value: l
};
});
},
themes() {
return Object.keys(Constants.Themes).map(t => {
return {
Expand All @@ -135,7 +145,7 @@ export default {
},
reload() {
location.href = `/?anticache=${Date.now()}${location.hash}`;
location.href = `?anticache=${Date.now()}${location.hash}`;
},
reset() {
Expand Down
12 changes: 6 additions & 6 deletions packages/client/src/locales/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"about": {
"main": "scanservjs je jednoduché webové uživatelské rozhraní pro váš skener. Umožňuje vám sdílet jeden nebo více skenerů (s využitím SANE) bez ovladačů nebo komplikované instalace. Umí ukládat do TIF, JPG, PNG, PDF a TXT (využívá Tesseract OCR) s různými nastaveními komprese, vše je možné konfigurovat. Podporuje vícestránkové skenování a všechna zařízení kompatibilní se SANE.",
"issue": "Ohlaste chybu nebo se podívejte na zdrojový kód:",
"system-info": "System information:"
"system-info": "Informace o systému:"
},

"colors": {
Expand Down Expand Up @@ -146,10 +146,10 @@
"theme:dark": "Tmavý",
"color": "Barva",
"color:description": "Barva. Toto nastavení změní barvu horního panelu.",
"devices": "Devices and storage",
"reset:description": "Clears stored scanner devices and forces a reload",
"devices": "Zařízení a úložiště",
"reset:description": "Odstraní uložená skenovací zařízení a vynutí opětovné načtení",
"reset": "Resetovat",
"clear-storage:description": "Clears local storage of any cached parameters",
"clear-storage": "Clear"
"clear-storage:description": "Uvolní veškerou mezipaměť vytvořenou v lokálním úložišti prohlížeče",
"clear-storage": "Uvolnit"
}
}
}
13 changes: 13 additions & 0 deletions packages/client/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,18 @@
"reset": "Reset",
"clear-storage:description": "Clears local storage of any cached parameters",
"clear-storage": "Clear"
},

"locales": {
"cs": "Czech",
"de": "Deutsche",
"en": "English",
"es": "Español",
"fr": "Français",
"it": "Italiano",
"pt-BR": "Portuguese (Brazilian)",
"ru": "Russian",
"zh": "Chinese",
"test": "Test"
}
}
2 changes: 2 additions & 0 deletions packages/client/vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const configure = require('../server/src/configure');
const path = require('path');

module.exports = {
publicPath: '',

css: {
loaderOptions: {
sass: {
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.13.0",
"version": "2.14.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
21 changes: 8 additions & 13 deletions packages/server/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Api {
*/
static async fileList() {
log.trace('fileList()');
const dir = new FileInfo(Config.outputDirectory);
const dir = FileInfo.create(Config.outputDirectory);
let files = await dir.list();
files = files
.filter(f => ['.tif', '.jpg', '.png', '.pdf', '.txt', '.zip'].includes(f.extension))
Expand All @@ -27,17 +27,12 @@ class Api {
}

/**
* @param {string} fullpath
* @param {string} name
* @returns {FileInfo}
*/
static fileDelete(fullpath) {
static fileDelete(name) {
log.trace('fileDelete()');
const file = new FileInfo(fullpath);
const parent = new FileInfo(file.path);
const data = new FileInfo(Config.outputDirectory);
if (!parent.equals(data)) {
throw new Error('Cannot delete outside of data directory');
}
const file = FileInfo.unsafe(Config.outputDirectory, name);
return file.delete();
}

Expand All @@ -59,7 +54,7 @@ class Api {
}
});

const cmd = `${Scanimage.scan(request)} > ${Config.previewDirectory}preview.tif`;
const cmd = `${Scanimage.scan(request)} > ${Config.previewDirectory}/preview.tif`;
log.trace('Executing cmd:', cmd);
await Process.spawn(cmd);
return {};
Expand All @@ -70,7 +65,7 @@ class Api {
*/
static deletePreview() {
log.trace('deletePreview()');
const file = new FileInfo(`${Config.previewDirectory}preview.tif`);
const file = FileInfo.create(`${Config.previewDirectory}/preview.tif`);
return file.delete();
}

Expand All @@ -82,7 +77,7 @@ class Api {
log.trace('readPreview()', filters);
// The UI relies on this image being the correct aspect ratio. If there is a
// preview image then just use it.
const source = new FileInfo(`${Config.previewDirectory}preview.tif`);
const source = FileInfo.create(`${Config.previewDirectory}/preview.tif`);
if (source.exists()) {
const buffer = source.toBuffer();
const cmds = [...Config.previewPipeline.commands];
Expand All @@ -95,7 +90,7 @@ class Api {
}

// If not then it's possible the default image is not quite the correct aspect ratio
const buffer = new FileInfo(`${Config.previewDirectory}default.jpg`).toBuffer();
const buffer = FileInfo.create(`${Config.previewDirectory}/default.jpg`).toBuffer();

try {
// We need to know the correct aspect ratio from the device
Expand Down
6 changes: 3 additions & 3 deletions packages/server/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class Config {

allowUnsafePaths: false,
devicesPath: './config/devices.json',
outputDirectory: './data/output/',
previewDirectory: './data/preview/',
tempDirectory: './data/temp/',
outputDirectory: 'data/output',
previewDirectory: 'data/preview',
tempDirectory: 'data/temp',

previewResolution: 100,
previewPipeline: {
Expand Down
5 changes: 4 additions & 1 deletion packages/server/src/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const fs = require('fs');
const rootLog = require('loglevel');
const prefix = require('loglevel-plugin-prefix');
const Config = require('./config');
const FileInfo = require('./file-info');

// We need to apply logging setting prior to anything else using a logger
prefix.reg(rootLog);
Expand Down Expand Up @@ -115,7 +116,9 @@ function configure(app, rootPath) {
app.get('/files/*', (req, res) => {
logRequest(req);
try {
res.download(req.params[0]);
const name = req.params[0];
const file = FileInfo.unsafe(Config.outputDirectory, name);
res.download(file.fullname);
} catch (error) {
sendError(res, 500, error);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Devices {
* @returns {Promise.<ScanDevice[]>}
*/
static async get() {
const file = new FileInfo(Config.devicesPath);
const file = FileInfo.create(Config.devicesPath);
let devices = null;

if (file.exists()) {
Expand Down Expand Up @@ -86,7 +86,7 @@ class Devices {
* @returns {void}
*/
static reset() {
const file = new FileInfo(Config.devicesPath);
const file = FileInfo.create(Config.devicesPath);
if (file.exists()) {
file.delete();
}
Expand Down
Loading

0 comments on commit 7297e68

Please sign in to comment.