From d13b5933d03168b0f0b9b0221f50684d2eae7b5e Mon Sep 17 00:00:00 2001 From: bus Date: Sun, 18 Apr 2021 01:41:41 +0200 Subject: [PATCH 1/5] function to read from env --- api.js | 3 ++- env.js | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 env.js diff --git a/api.js b/api.js index 7caf844..17df1ac 100644 --- a/api.js +++ b/api.js @@ -1,9 +1,10 @@ const got = require('got'); +const { getEnvVar } = require('./env.js'); const fetchEvents = () => got('http://localhost:8384/rest/events', { headers: { - 'X-API-Key': process.env.API_KEY, + 'X-API-Key': getEnvVar('API_KEY','invalid') }, }).json(); diff --git a/env.js b/env.js new file mode 100644 index 0000000..8999dd4 --- /dev/null +++ b/env.js @@ -0,0 +1,9 @@ +module.exports = { + getEnvVar: function (varname, defaultvalue){ + var result = process.env[varname]; + if(result!=undefined) + return result; + else + return defaultvalue; + } +}; From b60f0b759a58af065e9521fc014d33d969965e49 Mon Sep 17 00:00:00 2001 From: bus Date: Sun, 18 Apr 2021 01:42:48 +0200 Subject: [PATCH 2/5] URL from env --- api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api.js b/api.js index 17df1ac..5219d25 100644 --- a/api.js +++ b/api.js @@ -2,7 +2,7 @@ const got = require('got'); const { getEnvVar } = require('./env.js'); const fetchEvents = () => - got('http://localhost:8384/rest/events', { + got(getEnvVar('ST_URL','http://localhost:8384/rest/events'), { headers: { 'X-API-Key': getEnvVar('API_KEY','invalid') }, From 36ff52ae5b77f44a6e77de1bffe54995bd1fec70 Mon Sep 17 00:00:00 2001 From: bus Date: Fri, 30 Apr 2021 00:39:34 +0200 Subject: [PATCH 3/5] hook root from env --- hooks.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hooks.js b/hooks.js index 512d6c2..085f74f 100644 --- a/hooks.js +++ b/hooks.js @@ -3,8 +3,9 @@ const ms = require('ms'); const os = require('os'); const path = require('path'); const { spawn } = require('child_process'); +const { getEnvVar } = require('./env.js'); -const getHooksRoot = () => path.join(os.homedir(), '/.syncthing-hooks'); +const getHooksRoot = () => getEnvVar('ST_HOOK_DIR', path.join(os.homedir(), '/.syncthing-hooks')) const readHooksRoot = async root => { try { From a32ca79e022eb717a1393ce9b60a1b8722588cf6 Mon Sep 17 00:00:00 2001 From: bus Date: Fri, 30 Apr 2021 00:57:38 +0200 Subject: [PATCH 4/5] renamed env var --- hooks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks.js b/hooks.js index 085f74f..bd5fb42 100644 --- a/hooks.js +++ b/hooks.js @@ -5,7 +5,7 @@ const path = require('path'); const { spawn } = require('child_process'); const { getEnvVar } = require('./env.js'); -const getHooksRoot = () => getEnvVar('ST_HOOK_DIR', path.join(os.homedir(), '/.syncthing-hooks')) +const getHooksRoot = () => getEnvVar('ST_HOOK_ROOT', path.join(os.homedir(), '/.syncthing-hooks')) const readHooksRoot = async root => { try { From f96da3e2b4521ac054cdd7784ce7070b1d745713 Mon Sep 17 00:00:00 2001 From: bus Date: Fri, 30 Apr 2021 00:58:21 +0200 Subject: [PATCH 5/5] explanation for new env vars --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5c49d4f..a2a289e 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,13 @@ API_KEY=mykey syncthing-hooks Don't forget to substitute `mykey` with your syncthing API key, which can be found in the settings in the GUI. +If Syncthing runs on another host or listens to a non-default port, you can specify an URL by using `ST_URL`. +Note that this URL has to include the protocol, hostname, port and path, e.g.: + +``` +ST_URL=http://:8384/rest/events +``` + It won't install itself as a daemon by default, however. In order to run it as a service, it is recommended to install [pm2](https://pm2.keymetrics.io/): ```sh @@ -44,7 +51,9 @@ pm2 logs ## Hooks -Create a folder in your home directory called `.syncthing-hooks`. Each hook is a file with the following naming scheme: +Create a folder in your home directory called `.syncthing-hooks`. +A different directory can be set using `ST_HOOK_ROOT`. +Each hook is a file with the following naming scheme: `folder-name-delay`