Skip to content

Add configurable mediaTimeout option for media upload polling#1341

Merged
neet merged 5 commits into
mainfrom
copilot/configure-media-timeout-option
Oct 25, 2025
Merged

Add configurable mediaTimeout option for media upload polling#1341
neet merged 5 commits into
mainfrom
copilot/configure-media-timeout-option

Conversation

Copilot AI commented Oct 25, 2025

Copy link
Copy Markdown
Contributor

Add configuration option for mediaTimeout to allow users to customize the media upload polling timeout.

Changes:

  • Create MediaConfigProps interface following the pattern of LogConfigProps
  • Add MediaConfigProps only to createRestAPIClient (REST API uses media uploads)
  • Remove mediaTimeout from MastoHttpConfigProps (not used by HttpConfigImpl)
  • OAuth client no longer receives mediaTimeout (doesn't use media uploads)
  • Add @experimental TSDoc tag to indicate behavior may change without announcement
  • All tests pass (including test for custom mediaTimeout)
  • Linting and build successful

Summary:

Users can now configure the mediaTimeout option when creating REST API clients. The implementation follows the existing pattern used by LogConfigProps - the property is defined in a separate interface that's only used in factory functions, not in the config implementation classes.

const client = createRestAPIClient({
  url: 'https://mastodon.social',
  accessToken: 'token',
  mediaTimeout: 120000, // 2 minutes
});

The mediaTimeout parameter is only available for createRestAPIClient since OAuth and Streaming APIs don't use media uploads. The parameter is marked as @experimental to indicate that its behavior may change without any announcement.

Original prompt

This section details on the original issue you should resolve

<issue_title>Option to change mediaTimeout</issue_title>
<issue_description>I saw that this mediaTimeout is hard-coded here:

private readonly mediaTimeout = 1000 * 60,

Is it possible to configure this?


For context, I've been bumping up the timeout property, once in a while, due to users mentioning their uploads timed out. E.g. cheeaun/phanpy@687db56

I've always thought timeout will help but after reading the code above, I realised there's another timeout setting?</issue_description>

<agent_instructions>To explain the context: The hard-coded parameter mediaTimeout is an integer that regard polling a timeout. In Mastodon API, a POST to /api/v2/media immediately returns a response, however it can't be attached to /api/v1/status until the media is successfully processed. Therefore, the Mastodon Hook class interprets the request for /api/v2/media and run a polling until url becomes present.
I would add an extra parameter to the HttpConfig, and use it in HttpActionDispatcherHookMastodon.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@github-actions

github-actions Bot commented Oct 25, 2025

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
rest 3.7 KB (+0.03% 🔺)
streaming 3.7 KB (0%)
oauth 3.69 KB (0%)

@pkg-pr-new

pkg-pr-new Bot commented Oct 25, 2025

Copy link
63c33ec_ " data-view-component="true" class="dropdown-item btn-link"> Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/neet/masto.js/masto@1341

commit: 63c33ec

Co-authored-by: neet <19276905+neet@users.noreply.github.com>
Copilot AI changed the title [WIP] Add option to change mediaTimeout configuration Add configurable mediaTimeout option for media upload polling Oct 25, 2025
Copilot AI requested a review from neet October 25, 2025 10:18
@neet

neet commented Oct 25, 2025

Copy link
Copy Markdown
Owner

@copilot mediaTimeout in HttpConfig is assigned but never used in the implementation class. It'd be more clean and solid if we have an object type that is only referred in the factory functions (just like LogConfigProps). Oauth and Streaming API will never use the polling so it's enough if we have it in REST as an intersection type.

Co-authored-by: neet <19276905+neet@users.noreply.github.com>

Copilot AI commented Oct 25, 2025

Copy link
Copy Markdown
Contributor Author

@copilot mediaTimeout in HttpConfig is assigned but never used in the implementation class. It'd be more clean and solid if we have an object type that is only referred in the factory functions (just ...

Refactored to use MediaConfigProps interface pattern (similar to LogConfigProps) in commit c264952. The mediaTimeout property is now only in the factory function parameter types, not in HttpConfigImpl, and is only available for createRestAPIClient since OAuth doesn't use media uploads.

@neet

neet commented Oct 25, 2025

Copy link
Copy Markdown
Owner

@copilot so much better now. Please also put @experimental TSDoc tag to tell the users that the behaviour of this option can be changed without any announcement.

Co-authored-by: neet <19276905+neet@users.noreply.github.com>

Copilot AI commented Oct 25, 2025

Copy link
Copy Markdown
Contributor Author

@copilot so much better now. Please also put @experimental TSDoc tag to tell the users that the behaviour of this option can be changed without any announcement.

Added @experimental TSDoc tag in commit 11c0e57.

@neet neet marked this pull request as ready for review October 25, 2025 10:47
Copilot AI review requested due to automatic review settings October 25, 2025 10:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a configurable mediaTimeout option to allow users to customize the polling timeout when uploading media. Previously, this timeout was hardcoded at 60 seconds, which could cause issues for users with slower connections or larger files.

Key changes:

  • Created MediaConfigProps interface to define the mediaTimeout configuration option
  • Made mediaTimeout available only in createRestAPIClient factory function (OAuth and Streaming APIs don't use media uploads)
  • Marked the option as @experimental to indicate potential future changes

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/adapters/clients.ts Added MediaConfigProps interface with mediaTimeout property and passed it to HttpActionDispatcherHookMastodon
src/adapters/action/dispatcher-http-hook-mastodon.spec.ts Added test case to verify custom mediaTimeout value is respected

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/adapters/clients.ts Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@neet neet enabled auto-merge (squash) October 25, 2025 11:00
@neet neet merged commit 7341c22 into main Oct 25, 2025
7 checks passed
@neet neet deleted the copilot/configure-media-timeout-option branch October 25, 2025 11:02
@neet neet mentioned this pull request Oct 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Option to change mediaTimeout

3 participants