Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/http-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ export class MatrixHttpApi<O extends IHttpOpts> extends FetchHttpApi<O> {
uploadResolvers.reject(new Error("Timeout"));
};

// set an initial timeout of 30s; we'll advance it each time we get a progress notification
let timeoutTimer = callbacks.setTimeout(timeoutFn, 30000);
// set an initial timeout (default to 30s); extendable via opts.timeoutMs
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// set an initial timeout (default to 30s); extendable via opts.timeoutMs
// set an initial timeout (default to 30s); extendable via opts.timeoutMs
// we'll advance it each time we get a progress notification

const timeoutDuration = opts.timeoutMs ?? 30000;
let timeoutTimer = callbacks.setTimeout(timeoutFn, timeoutDuration);

xhr.onreadystatechange = function (): void {
switch (xhr.readyState) {
Expand Down Expand Up @@ -108,7 +109,7 @@ export class MatrixHttpApi<O extends IHttpOpts> extends FetchHttpApi<O> {
callbacks.clearTimeout(timeoutTimer);
upload.loaded = ev.loaded;
upload.total = ev.total;
timeoutTimer = callbacks.setTimeout(timeoutFn, 30000);
timeoutTimer = callbacks.setTimeout(timeoutFn, timeoutDuration);
opts.progressHandler?.({
loaded: ev.loaded,
total: ev.total,
Expand Down
5 changes: 5 additions & 0 deletions src/http-api/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ export interface UploadOpts {
*/
progressHandler?(progress: UploadProgress): void;
abortController?: AbortController;
/**
* Optional. Timeout in milliseconds before the upload is aborted.
* Defaults to 30000 (30 seconds) if not specified.
*/
timeoutMs?: number;
Comment on lines +210 to +214
Copy link
Contributor

@florianduros florianduros Oct 7, 2025

Choose a reason for hiding this comment

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

Suggested change
/**
* Optional. Timeout in milliseconds before the upload is aborted.
* Defaults to 30000 (30 seconds) if not specified.
*/
timeoutMs?: number;
/**
* Timeout in milliseconds before the upload is aborted.
* @default 30000 (30 seconds)
*/
timeoutMs?: number;

}

export interface Upload {
Expand Down
Loading