| 968 | } catch (error: any) { |
| 969 | if (error.code === 'ENOTFOUND') { |
| 970 | return { connected: false, message: "DNS解析失败,请检查DNS设置" }; |
| 971 | } else if (error.code === 'ECONNREFUSED') { |
| 972 | return { connected: false, message: "连接被拒绝,可能存在防火墙阻止" }; |
| 973 | } else if (error.code === 'ETIMEDOUT') { |
| 974 | return { connected: false, message: "连接超时,网络可能较慢或不稳定" }; |
| 975 | } else { |
| 976 | return { connected: false, message: `网络连接异常: ${error.message}` }; |
| 977 | } |
| 978 | } |
| 979 | } |
| 980 | |
| 981 | async function saveSpeedtestImage(url: string): Promise<string | null> { |
| 982 | try { |
| 983 | const imageUrl = url + ".png"; |
| 984 | const response = await axios.get(imageUrl, { responseType: "arraybuffer" }); |
| 985 | const imagePath = path.join(TEMP_DIR, "speedtest.png"); |
| 986 | const filledImagePath = path.join(TEMP_DIR, "speedtest_filled.png"); |
| 987 | fs.writeFileSync(imagePath, response.data); |
| 988 | |
| 989 | const bgColor = "#212338"; |