Skip to content

Commit

Permalink
Merge pull request #939 from manuc66/feature/change-paperless-config
Browse files Browse the repository at this point in the history
fix the way paperless url is configured (more flexibility to support …
  • Loading branch information
manuc66 authored Jul 14, 2024
2 parents 62e77ce + 43d2dde commit f47338c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Please note that the `node-hp-scan-to` project is not endorsed by nor affiliated
- `-r` or `--resolution` Resolution in DPI of the scans (defaults is 200).
- `-w` or `--width` followed by an integer, the with in pixel of the scans (default: 2481)
- `-h` or `--height` followed by an integer, the height in pixel of the scans (default: 3507)
- `-s` or `--paperless-host` followed by the paperless host name
- `-s` or `--paperless-post-document-url` followed by the paperless post document url (example: https://domain.tld/api/documents/post_document/)
- `k` or `--paperless-token` followed by te paperless-ngx api token
- `-D, --debug"` enables debug logs.

Expand Down Expand Up @@ -113,7 +113,7 @@ Exhaustive list of supported environment variables and their meaning, or corresp
- `DIR`: command-line flag `-d`/`--directory`
- `TEMP_DIR`: command-line flag `-t`/`--temp-directory`
- `RESOLUTION`: command-line flag `-r`/`--resolution`
- `PAPERLESS_HOST`: the paperless api host (if provided with token, a pdf is uploaded to paperless-ngx)
- `PAPERLESS_POST_DOCUMENT_URL`: the paperless api host (if provided with token, a pdf is uploaded to paperless-ngx)
- `PAPERLESS_TOKEN`: the paperless api token
- `CMDLINE`: additional command-line flags that will be put at the end of the command.

Expand Down
4 changes: 2 additions & 2 deletions root/app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ if [ ! -z "$RESOLUTION" ]; then
ARGS="${ARGS} -r ${RESOLUTION}"
fi

if [ ! -z "$PAPERLESS_HOST" ]; then
ARGS="${ARGS} -s ${PAPERLESS_HOST}"
if [ ! -z "$PAPERLESS_POST_DOCUMENT_URL" ]; then
ARGS="${ARGS} -s ${PAPERLESS_POST_DOCUMENT_URL}"
fi

if [ ! -z "$PAPERLESS_TOKEN" ]; then
Expand Down
21 changes: 11 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,15 @@ function getConfig<T>(name: string): T | undefined {
function setupScanParameters(command: Command): Command {
command.option(
"-d, --directory <dir>",
"Directory where scans are saved (default: /tmp/scan-to-pc<random>)",
"Directory where scans are saved (default: /tmp/scan-to-pcRANDOM)",
);
command.option(
"-t, --temp-directory <dir>",
"Temp directory used for processing (default: /tmp/scan-to-pc<random>)",
"Temp directory used for processing (default: /tmp/scan-to-pcRANDOM)",
);
command.option(
"-p, --pattern <pattern>",
'Pattern for filename (i.e. "scan"_dd.mm.yyyy_hh:MM:ss, without this its scanPage<number>)',
'Pattern for filename (i.e. "scan"_dd.mm.yyyy_hh:MM:ss, without this its scanPageNUMBER)',
);
command.option(
"-r, --resolution <dpi>",
Expand All @@ -228,9 +228,10 @@ function setupScanParameters(command: Command): Command {
"Height in pixel of the scans (default: 3507)",
);
command.option(
"-s, --paperless-host <paperless_host>",
"The paperless host name",
"-s, --paperless-post-document-url <paperless_post_document_url>",
"The paperless post document url (example: https://domain.tld/api/documents/post_document/)",
);

command.option(
"-o, --paperless-token <paperless_token>",
"The paperless token",
Expand Down Expand Up @@ -284,19 +285,19 @@ function getIsDebug(options: OptionValues) {
function getPaperlessConfig(
parentOption: OptionValues,
): PaperlessConfig | undefined {
const configPaperlessHost =
parentOption.paperlessHost || getConfig("paperless_host");
const paperlessPostDocumentUrl =
parentOption.paperlessPostDocumentUrl || getConfig("paperless_post_document_url");
const configPaperlessToken =
parentOption.paperlessToken || getConfig("paperless_token");
const configPaperlessKeepFiles =
parentOption.paperlessKeepFiles || getConfig("paperless_keep_files") || false;

if (configPaperlessHost && configPaperlessToken) {
if (paperlessPostDocumentUrl && configPaperlessToken) {
console.log(
`Paperless configuration provided, host: ${configPaperlessHost}, the token length: ${configPaperlessToken.length}, keepFiles: ${configPaperlessKeepFiles}`,
`Paperless configuration provided, post document url: ${paperlessPostDocumentUrl}, the token length: ${configPaperlessToken.length}, keepFiles: ${configPaperlessKeepFiles}`,
);
return {
host: configPaperlessHost,
postDocumentUrl: paperlessPostDocumentUrl,
authToken: configPaperlessToken,
keepFiles: configPaperlessKeepFiles,
};
Expand Down
4 changes: 2 additions & 2 deletions src/scanProcessing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ export type DirectoryConfig = {
filePattern: string | undefined;
};
export type PaperlessConfig = {
host: string;
postDocumentUrl: string;
authToken: string;
keepFiles: boolean;
};
Expand All @@ -593,7 +593,7 @@ async function uploadToPaperless(
filePath: string,
paperlessConfig: PaperlessConfig,
): Promise<void> {
const url = `https://${paperlessConfig.host}/api/documents/post_document/`;
const url = paperlessConfig.postDocumentUrl;

const authToken = paperlessConfig.authToken;

Expand Down

0 comments on commit f47338c

Please sign in to comment.