فهرست منبع

fix periodicPingUrls oops (#3490)

* fix periodicPingUrls oops

closes #3488

* Update packages/@uppy/companion/src/companion.js

Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>

* fix syntax

* Document periodic ping

Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
Mikael Finstad 3 سال پیش
والد
کامیت
8b8e6dfc7c
2فایلهای تغییر یافته به همراه23 افزوده شده و 2 حذف شده
  1. 6 2
      packages/@uppy/companion/src/companion.js
  2. 17 0
      website/src/docs/companion.md

+ 6 - 2
packages/@uppy/companion/src/companion.js

@@ -272,6 +272,10 @@ const validateConfig = (companionOptions) => {
     logger.warn('Running without uploadUrls specified is a security risk if running in production', 'startup.uploadUrls')
   }
 
-  const periodicPingUrlsValid = Array.isArray(periodicPingUrls) && periodicPingUrls.every((url2) => isURL(url2, { protocols: ['http', 'https'], require_protocol: true, require_tld: false }))
-  if (!periodicPingUrlsValid) throw new TypeError('Invalid periodicPingUrls')
+  if (periodicPingUrls != null && (
+    !Array.isArray(periodicPingUrls)
+    || periodicPingUrls.some((url2) => !isURL(url2, { protocols: ['http', 'https'], require_protocol: true, require_tld: false }))
+  )) {
+    throw new TypeError('Invalid periodicPingUrls')
+  }
 }

+ 17 - 0
website/src/docs/companion.md

@@ -251,6 +251,13 @@ export COMPANION_MAX_FILE_SIZE="100000000"
 
 # corresponds to the chunkSize option
 export COMPANION_CHUNK_SIZE="50000000"
+
+# corresponds to the periodicPingUrls option (CSV string converted to array)
+export COMPANION_PERIODIC_PING_URLS="https://example.com/ping1,https://example.com/ping2"
+# corresponds to the periodicPingInterval option
+export COMPANION_PERIODIC_PING_INTERVAL=60000
+# corresponds to the periodicPingStaticPayload option (JSON string)
+export COMPANION_PERIODIC_PING_STATIC_JSON_PAYLOAD="{\"static\":\"data\"}"
 ```
 
 See [env.example.sh](https://github.com/transloadit/uppy/blob/main/env.example.sh) for an example configuration script.
@@ -303,6 +310,9 @@ const options = {
   metrics: false,
   streamingUpload: true,
   maxFileSize: 100000000,
+  periodicPingUrls: [],
+  periodicPingInterval: 60000,
+  periodicPingStaticPayload: { static: 'payload' },
 }
 ```
 
@@ -343,6 +353,13 @@ const options = {
 
 15. **maxFileSize(optional)** - If this value is set, companion will limit the maximum file size to process. If unset, it will process files without any size limit (this is the default).
 
+16. **periodicPingUrls(optional)** - If this value is set, companion will periodically send POST requests to the specified URLs. Useful for keeping track of companion instances as a keep-alive.
+
+17. **periodicPingInterval(optional)** - Interval for periodic ping requests (in ms).
+
+18. **periodicPingStaticPayload(optional)** - A `JSON.stringify`-able JavaScript Object that will be sent as part of the JSON body in the period ping requests.
+
+
 ### Provider Redirect URIs
 
 When generating your provider API keys on their corresponding developer platforms (e.g [Google Developer Console](https://console.developers.google.com/)), you’d need to provide a `redirect URI` for the OAuth authorization process. In general the redirect URI for each provider takes the format: