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

Function http

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

Source from the content-addressed store, hash-verified

2854}
2855// 请求
2856async function http(url, opts = {}) {
2857 const http_start = Date.now()
2858 let timeout = HTTP_TIMEOUT + 1 * 1000
2859 timeout = $.isSurge() ? timeout / 1000 : timeout
2860 const reqOpts = {
2861 timeout,
2862 url,
2863 ...opts,
2864 }
2865 try {
2866 const res = await Promise.race([
2867 $.http.get(reqOpts),
2868 new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), HTTP_TIMEOUT)),
2869 ])
2870 $.log(`⏱ 请求耗时:${Math.round(((Date.now() - http_start) / 1000) * 100) / 100} 秒\n └ ${reqOpts.url}`)
2871 return res
2872 } catch (e) {
2873 $.logErr(e)
2874 let msg = String($.lodash_get(e, 'message') || e)
2875 let info
2876 if (msg.includes('timeout')) {
2877 info = `请求超时(${Math.round((HTTP_TIMEOUT / 1000) * 100) / 100} 秒)`
2878 } else {
2879 throw new Error(e)
2880 }
2881 throw new Error(info)
2882 }
2883}
2884function parseJsonPath(_path) {
2885 const path = _path.trim()
2886 const output = []

Callers 3

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