-
Notifications
You must be signed in to change notification settings - Fork 145
/
config.default.js
142 lines (130 loc) · 5.22 KB
/
config.default.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* eslint-disable no-unused-vars */
const options = { paths: ['/usr/lib/scanservjs'] };
const Process = require(require.resolve('./server/classes/process', options));
const dayjs = require(require.resolve('dayjs', options));
/**
* This file is ignored. If you want to apply overrides, make a copy in this
* location and name it `config.local.js`. Then make the necessary changes.
*/
module.exports = {
/**
* @param {Configuration} config
*/
afterConfig(config) {
/**
* Override any of the following values
*/
// config.host = '127.0.0.1';
// config.port = 8080;
// config.devices = [];
// config.ocrLanguage = 'eng';
// config.log.level = 'DEBUG';
// config.scanimage = '/usr/bin/scanimage';
// config.convert = '/usr/bin/convert';
// config.tesseract = '/usr/bin/tesseract';
// config.previewResolution = 100;
/* When all scans are complete, the filenames are all piped into stdin of the
first pipeline command. It would be nicer to pipe the binary output of scanimage
but that doesn't work with multipage scans so we have no choice but to write to
the filesystem.
The stdout of each pipeline feeds into the stdin of the next. Although clumsy in
some respects (especially where we have to write temporary files and then list
them) it at least provides a means of user configuration with "just" shell
scripting.
The overall output of the pipelines (i.e. the last pipeline output) must be a
list of the files you want kept. The convention is to output files of the form
`scan-0000.ext` but it's convention only. You can output whatever you want. If
multiple files are output then the results will be zipped into a single file.
Each command is executed with the CWD set to the temporary location so no
directory traversal is required. Pipeline commands are always read from this
file (and never from the browser request, even though it is sent). It would be
possible to subvert these commands for malicious use, but it doesn't give any
further privilege than the user account running scanservjs and still requires
access to this file. You obviously should not be running as root.
Some useful pointers:
- `convert` can read a list of files from a file with the @ argument. The `-`
file is stdin. So `convert @- -argument output` performs the conversion on
each file piped into stdin
- `tesseract` has a similar feature using `-c stream_filelist=true`
- `convert` can also output multiple files if you use an output filename with
`%d` in it. C string style formatting is available so you can do things like
output to `scan-%04d.jpg`. Formats which do not support multiple pages must
use this option. Multi-page formats including PDF and TIF do not use this
option.
- if you just wanted to take a filename from stdin and have its content read out
you could `xargs cat` provided there were no spaces or commas in the filename
(which there won't be)
*/
/**
* Create a custom pipeline
*/
// const myPipelines = [
// {
// extension: 'jpg',
// description: 'JPG | Super quality',
// commands: [
// 'convert @- -quality 96 scan-%04d.jpg',
// 'ls scan-*.*'
// ]
// }
// ];
/**
* Replace all existing pipelines
*/
// config.pipelines = myPipelines;
/**
* Append to existing pipelines
*/
// config.pipelines.push(myPipelines[0]);
},
/**
* This method is called after devices have been read (from the scanner or
* disk) but before being returned to anything else. You can use this to
* override default settings from the scanner, or resolution options or
* anything else for that matter.
*
* Note that the devices parameter is an array. Most systems will likely just
* have one scanner, but that's not always true. Therefore you will need to
* identify the scanner by id or index. It's also possible that the list will
* be empty if there's an upstream error.
* @param {ScanDevice[]} devices
*/
afterDevices(devices) {
/**
* Example code below
*/
// const device = devices.filter(d => d.id.startsWith('plustek'))[0];
// if (device) {
// device.features['--mode'].default = 'Gray';
// device.features['--resolution'].default = 150;
// device.features['--resolution'].options = [150, 300, 600];
// device.features['--brightness'].default = 10;
// device.features['--contrast'].default = 20;
// device.features['-x'].default = 215;
// device.features['-y'].default = 297;
// }
},
/**
* This method is called after every scan has completed with the resultant
* FileInfo.
* @param {FileInfo} fileInfo
* @returns {Promise.<any>}
*/
async afterScan(fileInfo) {
// Copy the file to the home directory
// return await Process.spawn(`cp '${fileInfo.fullname}' ~/`);
},
/**
* Returns a list of actions that can be run either through the UI or at the
* end of a specific pipeline
* @type {Action[]}
*/
actions: [
// {
// name: 'Echo',
// async execute(fileInfo) {
// return await Process.spawn(`echo '${fileInfo.fullname}'`);
// }
// }
]
};