mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Merge pull request #922 from erickythierry/master
converting stream to buffer when uploading files without apparent need
This commit is contained in:
@@ -607,28 +607,19 @@ export const getWAUploadToServer = (
|
|||||||
let urls: { mediaUrl: string, directPath: string } | undefined
|
let urls: { mediaUrl: string, directPath: string } | undefined
|
||||||
const hosts = [ ...customUploadHosts, ...uploadInfo.hosts ]
|
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)
|
fileEncSha256B64 = encodeBase64EncodedStringForUpload(fileEncSha256B64)
|
||||||
|
|
||||||
for(const { hostname, maxContentLengthBytes } of hosts) {
|
for(const { hostname } of hosts) {
|
||||||
logger.debug(`uploading to "${hostname}"`)
|
logger.debug(`uploading to "${hostname}"`)
|
||||||
|
|
||||||
const auth = encodeURIComponent(uploadInfo.auth) // the auth token
|
const auth = encodeURIComponent(uploadInfo.auth) // the auth token
|
||||||
const url = `https://${hostname}${MEDIA_PATH_MAP[mediaType]}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}`
|
const url = `https://${hostname}${MEDIA_PATH_MAP[mediaType]}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}`
|
||||||
let result: any
|
let result: any
|
||||||
try {
|
try {
|
||||||
if(maxContentLengthBytes && reqBody.length > maxContentLengthBytes) {
|
|
||||||
throw new Boom(`Body too large for "${hostname}"`, { statusCode: 413 })
|
|
||||||
}
|
|
||||||
|
|
||||||
const body = await axios.post(
|
const body = await axios.post(
|
||||||
url,
|
url,
|
||||||
reqBody,
|
stream,
|
||||||
{
|
{
|
||||||
...options,
|
...options,
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
Reference in New Issue
Block a user