mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
refactor: use abstraction for tmpdir
This commit is contained in:
@@ -15,6 +15,8 @@ import { generateMessageID } from './generics'
|
|||||||
import { hkdf } from './crypto'
|
import { hkdf } from './crypto'
|
||||||
import { DEFAULT_ORIGIN } from '../Defaults'
|
import { DEFAULT_ORIGIN } from '../Defaults'
|
||||||
|
|
||||||
|
const getTmpFilesDirectory = () => tmpdir()
|
||||||
|
|
||||||
export const hkdfInfoKey = (type: MediaType) => {
|
export const hkdfInfoKey = (type: MediaType) => {
|
||||||
let str: string = type
|
let str: string = type
|
||||||
if(type === 'sticker') str = 'image'
|
if(type === 'sticker') str = 'image'
|
||||||
@@ -135,7 +137,7 @@ export async function generateThumbnail(
|
|||||||
const buff = await compressImage(file)
|
const buff = await compressImage(file)
|
||||||
thumbnail = buff.toString('base64')
|
thumbnail = buff.toString('base64')
|
||||||
} else if(mediaType === 'video') {
|
} else if(mediaType === 'video') {
|
||||||
const imgFilename = join(tmpdir(), generateMessageID() + '.jpg')
|
const imgFilename = join(getTmpFilesDirectory(), generateMessageID() + '.jpg')
|
||||||
try {
|
try {
|
||||||
await extractVideoThumb(file, imgFilename, '00:00:00', { width: 32, height: 32 })
|
await extractVideoThumb(file, imgFilename, '00:00:00', { width: 32, height: 32 })
|
||||||
const buff = await fs.readFile(imgFilename)
|
const buff = await fs.readFile(imgFilename)
|
||||||
@@ -173,7 +175,7 @@ export const encryptedStream = async(media: WAMediaUpload, mediaType: MediaType,
|
|||||||
const mediaKey = Crypto.randomBytes(32)
|
const mediaKey = Crypto.randomBytes(32)
|
||||||
const {cipherKey, iv, macKey} = getMediaKeys(mediaKey, mediaType)
|
const {cipherKey, iv, macKey} = getMediaKeys(mediaKey, mediaType)
|
||||||
// random name
|
// random name
|
||||||
const encBodyPath = join(tmpdir(), mediaType + generateMessageID() + '.enc')
|
const encBodyPath = join(getTmpFilesDirectory(), mediaType + generateMessageID() + '.enc')
|
||||||
const encWriteStream = createWriteStream(encBodyPath)
|
const encWriteStream = createWriteStream(encBodyPath)
|
||||||
let bodyPath: string
|
let bodyPath: string
|
||||||
let writeStream: WriteStream
|
let writeStream: WriteStream
|
||||||
@@ -181,7 +183,7 @@ export const encryptedStream = async(media: WAMediaUpload, mediaType: MediaType,
|
|||||||
if(type === 'file') {
|
if(type === 'file') {
|
||||||
bodyPath = (media as any).url
|
bodyPath = (media as any).url
|
||||||
} else if(saveOriginalFileIfRequired) {
|
} else if(saveOriginalFileIfRequired) {
|
||||||
bodyPath = join(tmpdir(), mediaType + generateMessageID())
|
bodyPath = join(getTmpFilesDirectory(), mediaType + generateMessageID())
|
||||||
writeStream = createWriteStream(bodyPath)
|
writeStream = createWriteStream(bodyPath)
|
||||||
didSaveToTmpPath = true
|
didSaveToTmpPath = true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user