lint: 0 warnings left

This commit is contained in:
Rajeh Taher
2024-10-14 05:15:10 +03:00
parent 61a0ff3178
commit 18ac07df8e
32 changed files with 652 additions and 1006 deletions

View File

@@ -12,7 +12,7 @@ import { Readable, Transform } from 'stream'
import { URL } from 'url'
import { proto } from '../../WAProto'
import { DEFAULT_ORIGIN, MEDIA_HKDF_KEY_MAPPING, MEDIA_PATH_MAP } from '../Defaults'
import { BaileysEventMap, DownloadableMessage, MediaConnInfo, MediaDecryptionKeyInfo, MediaType, MessageType, SocketConfig, WAGenericMediaMessage, WAMediaUpload, WAMediaUploadFunction, WAMessageContent } from '../Types'
import { BaileysEventMap, DownloadableMessage, MediaConnInfo, MediaDecryptionKeyInfo, MediaType, MessageType, SocketConfig, WAGenericMediaMessage, WAMediaPayloadURL, WAMediaUpload, WAMediaUploadFunction, WAMessageContent } from '../Types'
import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildBuffer, jidNormalizedUser } from '../WABinary'
import { aesDecryptGCM, aesEncryptGCM, hkdf } from './crypto'
import { generateMessageID } from './generics'
@@ -79,7 +79,7 @@ const extractVideoThumb = async(
destPath: string,
time: string,
size: { width: number, height: number },
) => new Promise((resolve, reject) => {
) => new Promise<void>((resolve, reject) => {
const cmd = `ffmpeg -ss ${time} -i ${path} -y -vf scale=${size.width}:-1 -vframes 1 -f image2 ${destPath}`
exec(cmd, (err) => {
if(err) {
@@ -88,7 +88,7 @@ const extractVideoThumb = async(
resolve()
}
})
}) as Promise<void>
})
export const extractImageThumb = async(bufferOrFilePath: Readable | Buffer | string, width = 32) => {
if(bufferOrFilePath instanceof Readable) {
@@ -97,7 +97,7 @@ export const extractImageThumb = async(bufferOrFilePath: Readable | Buffer | str
const lib = await getImageProcessingLibrary()
if('sharp' in lib && typeof lib.sharp?.default === 'function') {
const img = lib.sharp!.default(bufferOrFilePath)
const img = lib.sharp.default(bufferOrFilePath)
const dimensions = await img.metadata()
const buffer = await img
@@ -114,7 +114,7 @@ export const extractImageThumb = async(bufferOrFilePath: Readable | Buffer | str
} else if('jimp' in lib && typeof lib.jimp?.read === 'function') {
const { read, MIME_JPEG, RESIZE_BILINEAR, AUTO } = lib.jimp
const jimp = await read(bufferOrFilePath as any)
const jimp = await read(bufferOrFilePath as string)
const dimensions = {
width: jimp.getWidth(),
height: jimp.getHeight()
@@ -154,7 +154,7 @@ export const generateProfilePicture = async(mediaUpload: WAMediaUpload) => {
const lib = await getImageProcessingLibrary()
let img: Promise<Buffer>
if('sharp' in lib && typeof lib.sharp?.default === 'function') {
img = lib.sharp!.default(bufferOrFilePath)
img = lib.sharp.default(bufferOrFilePath)
.resize(640, 640)
.jpeg({
quality: 50,
@@ -162,7 +162,7 @@ export const generateProfilePicture = async(mediaUpload: WAMediaUpload) => {
.toBuffer()
} else if('jimp' in lib && typeof lib.jimp?.read === 'function') {
const { read, MIME_JPEG, RESIZE_BILINEAR } = lib.jimp
const jimp = await read(bufferOrFilePath as any)
const jimp = await read(bufferOrFilePath as string)
const min = Math.min(jimp.getWidth(), jimp.getHeight())
const cropped = jimp.crop(0, 0, min, min)
@@ -351,7 +351,7 @@ export const encryptedStream = async(
let writeStream: WriteStream | undefined
let didSaveToTmpPath = false
if(type === 'file') {
bodyPath = (media as any).url
bodyPath = (media as WAMediaPayloadURL).url.toString()
} else if(saveOriginalFileIfRequired) {
bodyPath = join(getTmpFilesDirectory(), mediaType + generateMessageID())
writeStream = createWriteStream(bodyPath)
@@ -382,10 +382,8 @@ export const encryptedStream = async(
}
sha256Plain = sha256Plain.update(data)
if(writeStream) {
if(!writeStream.write(data)) {
await once(writeStream, 'drain')
}
if(writeStream && !writeStream.write(data)) {
await once(writeStream, 'drain')
}
onChunk(aes.update(data))
@@ -455,7 +453,7 @@ const toSmallestChunkSize = (num: number) => {
export type MediaDownloadOptions = {
startByte?: number
endByte?: number
options?: AxiosRequestConfig<any>
options?: AxiosRequestConfig<{}>
}
export const getUrlFromDirectPath = (directPath: string) => `https://${DEF_HOST}${directPath}`
@@ -501,9 +499,9 @@ export const downloadEncryptedContent = async(
Origin: DEFAULT_ORIGIN,
}
if(startChunk || endChunk) {
headers!.Range = `bytes=${startChunk}-`
headers.Range = `bytes=${startChunk}-`
if(endChunk) {
headers!.Range += endChunk
headers.Range += endChunk
}
}
@@ -614,6 +612,7 @@ export const getWAUploadToServer = (
const auth = encodeURIComponent(uploadInfo.auth) // the auth token
const url = `https://${hostname}${MEDIA_PATH_MAP[mediaType]}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}`
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let result: any
try {
@@ -770,9 +769,4 @@ const MEDIA_RETRY_STATUS_MAP = {
[proto.MediaRetryNotification.ResultType.DECRYPTION_ERROR]: 412,
[proto.MediaRetryNotification.ResultType.NOT_FOUND]: 404,
[proto.MediaRetryNotification.ResultType.GENERAL_ERROR]: 418,
} as const
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function __importStar(arg0: any): any {
throw new Error('Function not implemented.')
}
} as const