| 149 | }), |
| 150 | dcId, |
| 151 | ), |
| 152 | QUOTE_RPC_TIMEOUT_MS, |
| 153 | "rawDownloadFile", |
| 154 | ) as { bytes?: unknown }; |
| 155 | const buffer = result?.bytes; |
| 156 | return Buffer.isBuffer(buffer) && buffer.length > 0 ? buffer : undefined; |
| 157 | } catch (err: any) { |
| 158 | console.warn("yvlu rawDownloadFile failed", err?.message || err); |
| 159 | return undefined; |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | async function downloadMediaBuffer(client: any, target: any): Promise<Buffer | undefined> { |
| 164 | if (!client || !target) return undefined; |
| 165 | // For small media (thumbnails, static stickers, photos), try raw upload.GetFile first |
| 166 | // Fall back to downloadMedia if raw download fails or isn't applicable |
| 167 | try { |
| 168 | const media = target.media ?? target; |
| 169 | // Try to get document/photo info for raw download |
| 170 | let doc = media?.document ?? media?.photo; |
| 171 | if (doc && doc.id && doc.accessHash) { |
| 172 | // Small files: use raw download |