(url: string, endpoint: string)
| 217 | |
| 218 | // HTTP 请求封装 |
| 219 | async function makeRequest(url: string, endpoint: string): Promise<any> { |
| 220 | try { |
| 221 | const response = await axios.get(`${url}${endpoint}`, { |
| 222 | timeout: 10000, |
| 223 | headers: { |
| 224 | Accept: "application/json", |
| 225 | "User-Agent": "TeleBox-Komari-Plugin/1.0", |
| 226 | }, |
| 227 | }); |
| 228 | |
| 229 | if (response.status !== 200) { |
| 230 | throw new Error(`HTTP ${response.status}: ${response.statusText}`); |
| 231 | } |
| 232 | |
| 233 | return response.data; |
| 234 | } catch (error: any) { |
| 235 | if (error.response) { |
| 236 | throw new Error(`API 请求失败: HTTP ${error.response.status}`); |
| 237 | } |
| 238 | throw new Error(`网络请求失败: ${error.message}`); |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | // 获取服务器基本信息 |
| 243 | async function getServerInfo(baseUrl: string): Promise<string> { |
no test coverage detected