MCPcopy Create free account
hub / github.com/Script-Hub-Org/Script-Hub / http

Function http

Rewrite-Parser.js:2444–2471  ·  view source on GitHub ↗
(url, opts = {})

Source from the content-addressed store, hash-verified

2442}
2443// 请求
2444async function http(url, opts = {}) {
2445 const http_start = Date.now()
2446 let timeout = HTTP_TIMEOUT + 1 * 1000
2447 timeout = $.isSurge() ? timeout / 1000 : timeout
2448 const reqOpts = {
2449 timeout,
2450 url,
2451 ...opts,
2452 }
2453 try {
2454 const res = await Promise.race([
2455 $.http.get(reqOpts),
2456 new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), HTTP_TIMEOUT)),
2457 ])
2458 $.log(`⏱ 请求耗时:${Math.round(((Date.now() - http_start) / 1000) * 100) / 100} 秒\n └ ${reqOpts.url}`)
2459 return res
2460 } catch (e) {
2461 $.logErr(e)
2462 let msg = String($.lodash_get(e, 'message') || e)
2463 let info
2464 if (msg.includes('timeout')) {
2465 info = `请求超时(${Math.round((HTTP_TIMEOUT / 1000) * 100) / 100} 秒)`
2466 } else {
2467 throw new Error(e)
2468 }
2469 throw new Error(info)
2470 }
2471}
2472function parseJsonPath(_path) {
2473 const path = _path.trim()
2474 const output = []

Callers 3

Rewrite-Parser.jsFile · 0.70
getIconFunction · 0.70
isBinaryModeFunction · 0.70

Calls 5

isSurgeMethod · 0.45
getMethod · 0.45
logMethod · 0.45
logErrMethod · 0.45
lodash_getMethod · 0.45

Tested by

no test coverage detected