mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
chore: lint
This commit is contained in:
@@ -346,34 +346,34 @@ export const encryptedStream = async(
|
|||||||
const mediaKey = Crypto.randomBytes(32)
|
const mediaKey = Crypto.randomBytes(32)
|
||||||
const { cipherKey, iv, macKey } = await getMediaKeys(mediaKey, mediaType)
|
const { cipherKey, iv, macKey } = await getMediaKeys(mediaKey, mediaType)
|
||||||
|
|
||||||
const encFilePath = join(
|
const encFilePath = join(
|
||||||
getTmpFilesDirectory(),
|
getTmpFilesDirectory(),
|
||||||
mediaType + generateMessageIDV2() + "-enc"
|
mediaType + generateMessageIDV2() + '-enc'
|
||||||
);
|
)
|
||||||
const encFileWriteStream = createWriteStream(encFilePath);
|
const encFileWriteStream = createWriteStream(encFilePath)
|
||||||
|
|
||||||
let originalFileStream: WriteStream | undefined;
|
let originalFileStream: WriteStream | undefined
|
||||||
let originalFilePath: string | undefined;
|
let originalFilePath: string | undefined
|
||||||
|
|
||||||
if (saveOriginalFileIfRequired) {
|
if(saveOriginalFileIfRequired) {
|
||||||
originalFilePath = join(
|
originalFilePath = join(
|
||||||
getTmpFilesDirectory(),
|
getTmpFilesDirectory(),
|
||||||
mediaType + generateMessageIDV2() + "-original"
|
mediaType + generateMessageIDV2() + '-original'
|
||||||
);
|
)
|
||||||
originalFileStream = createWriteStream(originalFilePath);
|
originalFileStream = createWriteStream(originalFilePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
let fileLength = 0
|
let fileLength = 0
|
||||||
const aes = Crypto.createCipheriv('aes-256-cbc', cipherKey, iv)
|
const aes = Crypto.createCipheriv('aes-256-cbc', cipherKey, iv)
|
||||||
const hmac = Crypto.createHmac('sha256', macKey!).update(iv)
|
const hmac = Crypto.createHmac('sha256', macKey!).update(iv)
|
||||||
const sha256Plain = Crypto.createHash('sha256')
|
const sha256Plain = Crypto.createHash('sha256')
|
||||||
const sha256Enc = Crypto.createHash('sha256')
|
const sha256Enc = Crypto.createHash('sha256')
|
||||||
|
|
||||||
const onChunk = (buff: Buffer) => {
|
const onChunk = (buff: Buffer) => {
|
||||||
sha256Enc.update(buff);
|
sha256Enc.update(buff)
|
||||||
hmac.update(buff);
|
hmac.update(buff)
|
||||||
encFileWriteStream.write(buff);
|
encFileWriteStream.write(buff)
|
||||||
};
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for await (const data of stream) {
|
for await (const data of stream) {
|
||||||
@@ -390,13 +390,13 @@ export const encryptedStream = async(
|
|||||||
data: { media, type }
|
data: { media, type }
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (originalFileStream) {
|
if(originalFileStream) {
|
||||||
if (!originalFileStream.write(data)) {
|
if(!originalFileStream.write(data)) {
|
||||||
await once(originalFileStream, "drain");
|
await once(originalFileStream, 'drain')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sha256Plain.update(data)
|
sha256Plain.update(data)
|
||||||
onChunk(aes.update(data))
|
onChunk(aes.update(data))
|
||||||
@@ -410,18 +410,18 @@ export const encryptedStream = async(
|
|||||||
const fileSha256 = sha256Plain.digest()
|
const fileSha256 = sha256Plain.digest()
|
||||||
const fileEncSha256 = sha256Enc.digest()
|
const fileEncSha256 = sha256Enc.digest()
|
||||||
|
|
||||||
encFileWriteStream.write(mac);
|
encFileWriteStream.write(mac)
|
||||||
|
|
||||||
encFileWriteStream.end();
|
encFileWriteStream.end()
|
||||||
originalFileStream?.end?.();
|
originalFileStream?.end?.()
|
||||||
stream.destroy();
|
stream.destroy()
|
||||||
|
|
||||||
logger?.debug('encrypted data successfully')
|
logger?.debug('encrypted data successfully')
|
||||||
|
|
||||||
return {
|
return {
|
||||||
mediaKey,
|
mediaKey,
|
||||||
originalFilePath,
|
originalFilePath,
|
||||||
encFilePath,
|
encFilePath,
|
||||||
mac,
|
mac,
|
||||||
fileEncSha256,
|
fileEncSha256,
|
||||||
fileSha256,
|
fileSha256,
|
||||||
@@ -438,12 +438,15 @@ export const encryptedStream = async(
|
|||||||
stream.destroy()
|
stream.destroy()
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fs.unlink(encFilePath)
|
await fs.unlink(encFilePath)
|
||||||
if (originalFilePath) await fs.unlink(originalFilePath)
|
if(originalFilePath) {
|
||||||
} catch(err) {
|
await fs.unlink(originalFilePath)
|
||||||
logger?.error({ err }, 'failed deleting tmp files')
|
}
|
||||||
}
|
} catch(err) {
|
||||||
|
logger?.error({ err }, 'failed deleting tmp files')
|
||||||
|
}
|
||||||
|
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -625,8 +628,8 @@ export const getWAUploadToServer = (
|
|||||||
url,
|
url,
|
||||||
stream,
|
stream,
|
||||||
{
|
{
|
||||||
...options,
|
...options,
|
||||||
maxRedirects: 0,
|
maxRedirects: 0,
|
||||||
headers: {
|
headers: {
|
||||||
...options.headers || { },
|
...options.headers || { },
|
||||||
'Content-Type': 'application/octet-stream',
|
'Content-Type': 'application/octet-stream',
|
||||||
|
|||||||
Reference in New Issue
Block a user