(doc: any)
| 915 | |
| 916 | async function downloadMediaToBuffer(client: any, target: any): Promise<Buffer | undefined> { |
| 917 | if (!client || !target) return undefined; |
| 918 | const mediaPath = path.join(os.tmpdir(), `telebox_quote_media_${Date.now()}_${Math.random().toString(16).slice(2)}`); |
| 919 | try { |
| 920 | const downloaded = await withTimeout(client.downloadMedia(target, { outputFile: mediaPath }), QUOTE_RPC_TIMEOUT_MS, "downloadMediaToBuffer.downloadMedia"); |
| 921 | let buffer: Buffer | undefined; |
| 922 | if (Buffer.isBuffer(downloaded)) buffer = downloaded; |
| 923 | else if (downloaded && typeof downloaded === "string" && fs.existsSync(downloaded)) buffer = await waitForStableFile(downloaded); |
| 924 | if (!buffer || buffer.length === 0) buffer = await waitForStableFile(mediaPath); |
| 925 | return buffer && buffer.length > 0 ? buffer : undefined; |
| 926 | } catch (err: any) { |
no outgoing calls
no test coverage detected