mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-17 16:50:22 +00:00
@uppy/companion: remove redundant HEAD request for file size (#5648)
* Always get size from stream response headers because i don't really think we need a separate request for it * Remove explicit size request Remove `size` method from providers that don't have a backup method for getting size (that is better than GET download response header) assumption: GET response content-length is as good as (or better than) HEAD response content-length, meaning it is not necessary to call getURLMeta when we already tried the original GET response content-length this reduces the chance of hitting the race condition where the size of a URL changes between the GET and HEAD requests are sent
This commit is contained in:
parent
4f04568681
commit
834b01300a
14 changed files with 35 additions and 113 deletions
|
|
@ -61,26 +61,14 @@ class MyCustomProvider {
|
|||
},
|
||||
})
|
||||
|
||||
if (!resp.ok) {
|
||||
throw new Error(`Errornous HTTP response (${resp.status} ${resp.statusText})`)
|
||||
}
|
||||
return { stream: Readable.fromWeb(resp.body) }
|
||||
}
|
||||
|
||||
// eslint-disable-next-line class-methods-use-this
|
||||
async size ({ id, token }) {
|
||||
const resp = await fetch(`${BASE_URL}/photos/${id}`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
})
|
||||
const contentLengthStr = resp.headers['content-length']
|
||||
const contentLength = parseInt(contentLengthStr, 10);
|
||||
const size = !Number.isNaN(contentLength) && contentLength >= 0 ? contentLength : undefined;
|
||||
|
||||
if (!resp.ok) {
|
||||
throw new Error(`Errornous HTTP response (${resp.status} ${resp.statusText})`)
|
||||
}
|
||||
|
||||
const { size } = await resp.json()
|
||||
return size
|
||||
return { stream: Readable.fromWeb(resp.body), size }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue