Skip to content

Commit 1636aa7

Browse files
committed
fixup! Add stall detection to recover from frozen uploads
1 parent bfd0c8d commit 1636aa7

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

lib/options.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ export type SliceResult =
152152
export interface HttpStack {
153153
createRequest(method: string, url: string): HttpRequest
154154
getName(): string
155+
156+
// Indicates whether this HTTP stack implementation supports progress events
157+
// during upload. If false, stall detection will use overall transfer rate instead.
158+
supportsProgressEvents: () => boolean
155159
}
156160

157161
export type HttpProgressHandler = (bytesSent: number) => void
@@ -170,10 +174,6 @@ export interface HttpRequest {
170174

171175
// Return an environment specific object, e.g. the XMLHttpRequest object in browsers.
172176
getUnderlyingObject(): unknown
173-
174-
// Indicates whether this HTTP stack implementation supports progress events
175-
// during upload. If false, stall detection will use overall transfer rate instead.
176-
supportsProgressEvents: () => boolean
177177
}
178178

179179
export interface HttpResponse {

lib/upload.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Base64 } from 'js-base64'
2-
// @ts-ignore
2+
// TODO: Package url-parse is CommonJS. Can we replace this with a ESM package that
3+
// provides WHATWG URL? Then we can get rid of @rollup/plugin-commonjs.
34
import URL from 'url-parse'
45
import { DetailedError } from './DetailedError.js'
56
import { StallDetector } from './StallDetector.js'
@@ -11,15 +12,13 @@ import {
1112
PROTOCOL_IETF_DRAFT_03,
1213
PROTOCOL_IETF_DRAFT_05,
1314
PROTOCOL_TUS_V1,
14-
type Part,
1515
type PreviousUpload,
1616
type SliceType,
1717
type UploadInput,
1818
type UploadOptions,
1919
} from './options.js'
2020
import { uuid } from './uuid.js'
2121

22-
// Add this type definition after the imports
2322
interface ExtendedHttpRequest extends HttpRequest {
2423
_upload?: BaseUpload
2524
}
@@ -33,17 +32,17 @@ export const defaultOptions = {
3332
fingerprint: undefined,
3433
uploadSize: undefined,
3534

36-
onProgress: null,
37-
onChunkComplete: null,
38-
onSuccess: null,
39-
onError: null,
40-
onUploadUrlAvailable: null,
35+
onProgress: undefined,
36+
onChunkComplete: undefined,
37+
onSuccess: undefined,
38+
onError: undefined,
39+
onUploadUrlAvailable: undefined,
4140

4241
overridePatchMethod: false,
4342
headers: {},
4443
addRequestId: false,
45-
onBeforeRequest: null,
46-
onAfterResponse: null,
44+
onBeforeRequest: undefined,
45+
onAfterResponse: undefined,
4746
onShouldRetry: defaultOnShouldRetry,
4847

4948
chunkSize: Number.POSITIVE_INFINITY,
@@ -1245,6 +1244,8 @@ function resolveUrl(origin: string, link: string): string {
12451244
return new URL(link, origin).toString()
12461245
}
12471246

1247+
type Part = { start: number; end: number }
1248+
12481249
/**
12491250
* Calculate the start and end positions for the parts if an upload
12501251
* is split into multiple parallel requests.

0 commit comments

Comments
 (0)