From 41aab5d415dad5ccf8718cfb7177d5209ba7196c Mon Sep 17 00:00:00 2001 From: Essem Date: Fri, 15 May 2026 17:25:57 -0500 Subject: [PATCH] feat: Add REST_TIMEOUT_MS environment variable Applies to all Oceanic requests as well as POST requests sent by the media server. --- .env.example | 4 +++- docs/config.md | 1 + src/api/index.ts | 9 ++++++--- src/app.ts | 1 + 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index 680ced1a..6ce18ac2 100644 --- a/.env.example +++ b/.env.example @@ -37,6 +37,8 @@ KLIPY= # Put a custom Discord REST API URL here (e.g. https://discord.com/api/v10) REST_PROXY= +# Amount of time to wait before a REST request is timed out, defaults to 15000 +REST_TIMEOUT_MS= # Put a Sentry DSN endpoint URL here (used for error monitoring and statistics) SENTRY_DSN= @@ -58,4 +60,4 @@ CLUSTER_PORT= API_TYPE=none # Put ID of server to limit owner-only commands to -ADMIN_SERVER= \ No newline at end of file +ADMIN_SERVER= diff --git a/docs/config.md b/docs/config.md index 765ab52e..58544e74 100644 --- a/docs/config.md +++ b/docs/config.md @@ -22,6 +22,7 @@ These variables that are not necessarily required for the bot to run, but can gr - `STAYVC`: Set this to true if you want the bot to stay in voice chat after playing music/a sound effect. You can make it leave by using the stop command. - `KLIPY`: An API token from [KLIPY](https://klipy.com/docs). This is required for parsing share links from KLIPY. - `REST_PROXY`: A Discord REST URL to use besides the default (`https://discord.com/api/v{version_number}`). Can be useful for proxying requests to Discord through an external server. +- `REST_TIMEOUT_MS`: An amount of time in milliseconds to wait until outgoing requests to Discord are timed out. Defaults to 15000 (15 seconds). - `SENTRY_DSN`: A DSN endpoint URL from [Sentry](https://sentry.io). This is a fully optional integration for error monitoring and statistics. - `OUTPUT`: A directory to output the help documentation in Markdown format to. It's recommended to set this to a directory being served by a web server. - `TEMPDIR`: A directory that will store generated media files larger than Discord's filesize limit. It's recommended to set this to a directory being served by a web server. diff --git a/src/api/index.ts b/src/api/index.ts index bfe46218..63808c85 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -391,9 +391,12 @@ async function finishJob(data: JobOutput, job: MiniJob, object: MediaParams, ws: `${jobObject.spoiler || object.spoiler ? "SPOILER_" : ""}${object.cmd}.${jobObject.ext}`, ); const controller = new AbortController(); - const timeout = setTimeout(() => { - controller.abort(); - }, 15000); + const timeout = setTimeout( + () => { + controller.abort(); + }, + Number(process.env.REST_TIMEOUT_MS) || 15000, + ); try { const res = await fetch(`${discordBaseURL}/webhooks/${clientID}/${object.token}`, { method: "POST", diff --git a/src/app.ts b/src/app.ts index 64a9287d..d459a155 100644 --- a/src/app.ts +++ b/src/app.ts @@ -142,6 +142,7 @@ const client = new Client({ }, rest: { baseURL: process.env.REST_PROXY && process.env.REST_PROXY !== "" ? process.env.REST_PROXY : undefined, + requestTimeout: Number(process.env.REST_TIMEOUT_MS) || 15000, }, collectionLimits: { messages: 50, -- 2.51.2