(buffer: Buffer)
| 895 | if (size > 0 && size === lastSize) { |
| 896 | stable += 1; |
| 897 | if (stable >= 2) return fs.readFileSync(filePath); |
| 898 | } else { |
| 899 | stable = 0; |
| 900 | lastSize = size; |
| 901 | } |
| 902 | } |
| 903 | } catch (err) { |
| 904 | console.debug("[quote] waitForStableFile loop error:", err?.message || err); |
| 905 | } |
| 906 | await sleepMs(120); |
| 907 | } |
| 908 | try { |
| 909 | if (fs.existsSync(filePath) && fs.statSync(filePath).size > 0) return fs.readFileSync(filePath); |
| 910 | } catch (err) { |
| 911 | console.debug("[quote] waitForStableFile loop error:", err?.message || err); |
| 912 | } |
| 913 | return undefined; |
| 914 | } |
| 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)}`); |
no test coverage detected