( url: string, reqOpts?: RequestOptions, )
| 7 | * @param reqOpts |
| 8 | */ |
| 9 | export const request = async <T>( |
| 10 | url: string, |
| 11 | reqOpts?: RequestOptions, |
| 12 | ): Promise<HttpClientResponse<T>> => { |
| 13 | const opts: RequestOptions = { |
| 14 | contentType: 'json', |
| 15 | dataType: 'json', |
| 16 | headers: { |
| 17 | 'User-Agent': 'Elog', |
| 18 | ...reqOpts?.headers, |
| 19 | }, |
| 20 | gzip: true, |
| 21 | // 超时时间 60s |
| 22 | timeout: Number(process.env?.REQUEST_TIMEOUT || 60000) || 60000, |
| 23 | ...reqOpts, |
| 24 | } |
| 25 | out.debug(`API请求URL: ${url}`) |
| 26 | if (url.includes('api.github.com')) { |
| 27 | // Github Base64 输出太多,只输出headers |
| 28 | out.debug(`API请求Header参数: ${JSON.stringify(reqOpts?.headers || {})}`) |
| 29 | } else { |
| 30 | out.debug(`API请求参数: ${JSON.stringify(opts)}`) |
| 31 | } |
| 32 | return req(url, opts) |
| 33 | } |
| 34 | |
| 35 | export async function delay(ms = 500) { |
| 36 | await new Promise((resolve) => setTimeout(resolve, ms)) |
nothing calls this directly
no outgoing calls
no test coverage detected