Merge pull request #922 from erickythierry/master

converting stream to buffer when uploading files without apparent need
This commit is contained in:
Rajeh Taher
2024-07-27 17:56:17 +03:00
committed by GitHub

View File

@@ -607,28 +607,19 @@ export const getWAUploadToServer = (
let urls: { mediaUrl: string, directPath: string } | undefined
const hosts = [ ...customUploadHosts, ...uploadInfo.hosts ]
const chunks: Buffer[] = []
for await (const chunk of stream) {
chunks.push(chunk)
}
const reqBody = Buffer.concat(chunks)
fileEncSha256B64 = encodeBase64EncodedStringForUpload(fileEncSha256B64)
for(const { hostname, maxContentLengthBytes } of hosts) {
for(const { hostname } of hosts) {
logger.debug(`uploading to "${hostname}"`)
const auth = encodeURIComponent(uploadInfo.auth) // the auth token
const url = `https://${hostname}${MEDIA_PATH_MAP[mediaType]}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}`
let result: any
try {
if(maxContentLengthBytes && reqBody.length > maxContentLengthBytes) {
throw new Boom(`Body too large for "${hostname}"`, { statusCode: 413 })
}
const body = await axios.post(
url,
reqBody,
stream,
{
...options,
headers: {