Skip to content

Commit

Permalink
Fix various v3 snagging issues
Browse files Browse the repository at this point in the history
Closes #686
Closes #692
Closes #693
Closes #694

This is mostly documentation. But it also defines the least awful way to resolve `require(...)` paths where a plugin (i.e. `config.local.js`) is in a symlinked directory.

Node uses the absolute path of a module to determine how `require` works. When the module is in a symlinked directory then things go bad.
  • Loading branch information
sbs20 committed Nov 14, 2023
1 parent c34886b commit f4b8bda
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
3 changes: 3 additions & 0 deletions app-server/config/config.default.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/* 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
Expand Down
21 changes: 17 additions & 4 deletions docs/01-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ and it's a one-off process. Further, you may be using some of the packages that
this script proposes removing.

```sh
# backup scans to home directory
sudo mv /var/www/scanservjs/data/output ~/scanservjs-scans
sudo chown $USER:$USER ~/scanservjs-scans

# Stop and remove service
sudo systemctl stop scanservjs > /dev/null
sudo rm -vf /etc/systemd/system/scanservjs.service
sudo systemctl daemon-reload

# backup scans to home directory
mkdir -p /tmp/scanservjs.bkp
sudo mv -v /var/www/scanservjs/data /tmp/scanservjs.bkp
sudo mv -v /var/www/scanservjs/config /tmp/scanservjs.bkp

# Remove all old application files
sudo rm -rvf /var/www/scanservjs

Expand All @@ -58,6 +59,18 @@ sudo apt-get remove -yq \
sudo apt-get autoremove
```

To restore backed up files after install:

```sh
sudo cp -v /tmp/scanservjs.bkp/data/output/* /usr/lib/scanservjs/data/output
sudo cp -v /tmp/scanservjs.bkp/config/*.local.js /usr/lib/scanservjs/config
sudo chown $USER:$USER /usr/lib/scanservjs/data/output/*
```

Note that if you have a `config.local.js` then you may need to amend it to work
in `v3.x`. Please refer to the updated `config.default.js` or documentation to
reference the recommended pattern for using node `require(...)`.

## Arch

If you're using Arch, then [@dadosch](https://github.com/dadosch) created a
Expand Down
3 changes: 2 additions & 1 deletion docs/10-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ action object must have a name and async execute method taking a `FileInfo`:
## Example file

```javascript
const Process = require('../server/classes/process');
const options = { paths: ['/usr/lib/scanservjs'] };
const Process = require(require.resolve('./server/classes/process', options));

module.exports = {
/**
Expand Down
9 changes: 6 additions & 3 deletions docs/12-recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ Then, add the following pipeline:
## Change the log level and default scan filename

```javascript
const dayjs = require('dayjs');
const options = { paths: ['/usr/lib/scanservjs'] };
const dayjs = require(require.resolve('dayjs', options));
module.exports = {
afterConfig(config) {
config.filename = () => {
Expand Down Expand Up @@ -258,7 +259,8 @@ integrating with `paperless-ng`. The example below defines a pipeline which
creates a PDF and then copies it to the home directory on completion.
```javascript
const Process = require('../src/classes/process');
const options = { paths: ['/usr/lib/scanservjs'] };
const Process = require(require.resolve('./server/classes/process', options));

module.exports = {
/**
Expand Down Expand Up @@ -354,7 +356,8 @@ pipeline then something like the following may help:
Now create the following pipeline in your `config/config.local.js`
```javascript
const Process = require('../server/classes/process');
const options = { paths: ['/usr/lib/scanservjs'] };
const Process = require(require.resolve('./server/classes/process', options));

module.exports = {
afterConfig(config) {
Expand Down

0 comments on commit f4b8bda

Please sign in to comment.