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

Method get

env/env.js:241–300  ·  view source on GitHub ↗
(t, e = () => {})

Source from the content-addressed store, hash-verified

239 void 0 === t.headers.Cookie && void 0 === t.cookieJar && (t.cookieJar = this.ckjar))
240 }
241 get(t, e = () => {}) {
242 switch (
243 (t.headers &&
244 (delete t.headers['Content-Type'],
245 delete t.headers['Content-Length'],
246 delete t.headers['content-type'],
247 delete t.headers['content-length']),
248 t.params && (t.url += '?' + this.queryStr(t.params)),
249 this.getEnv())
250 ) {
251 case 'Surge':
252 case 'Loon':
253 case 'Stash':
254 case 'Shadowrocket':
255 default:
256 this.isSurge() &&
257 this.isNeedRewrite &&
258 ((t.headers = t.headers || {}), Object.assign(t.headers, { 'X-Surge-Skip-Scripting': !1 })),
259 $httpClient.get(t, (t, s, a) => {
260 !t && s && ((s.body = a), (s.statusCode = s.status ? s.status : s.statusCode), (s.status = s.statusCode)),
261 e(t, s, a)
262 })
263 break
264 case 'Quantumult X':
265 this.isNeedRewrite && ((t.opts = t.opts || {}), Object.assign(t.opts, { hints: !1 })),
266 $task.fetch(t).then(
267 t => {
268 const { statusCode: s, statusCode: a, headers: r, body: i, bodyBytes: o } = t
269 e(null, { status: s, statusCode: a, headers: r, body: i, bodyBytes: o }, i, o)
270 },
271 t => e((t && t.error) || 'UndefinedError')
272 )
273 break
274 case 'Node.js':
275 let s = require('iconv-lite')
276 this.initGotEnv(t),
277 this.got(t)
278 .on('redirect', (t, e) => {
279 try {
280 if (t.headers['set-cookie']) {
281 const s = t.headers['set-cookie'].map(this.cktough.Cookie.parse).toString()
282 s && this.ckjar.setCookieSync(s, null), (e.cookieJar = this.ckjar)
283 }
284 } catch (t) {
285 this.logErr(t)
286 }
287 })
288 .then(
289 t => {
290 const { statusCode: a, statusCode: r, headers: i, rawBody: o } = t,
291 n = s.decode(o, this.encoding)
292 e(null, { status: a, statusCode: r, headers: i, rawBody: o, body: n }, n)
293 },
294 t => {
295 const { message: a, response: r } = t
296 e(a, r, r && s.decode(r.rawBody, this.encoding))
297 }
298 )

Callers 2

fetchContentFunction · 0.45
getScriptMethod · 0.45

Calls 5

queryStrMethod · 0.45
getEnvMethod · 0.45
isSurgeMethod · 0.45
initGotEnvMethod · 0.45
logErrMethod · 0.45

Tested by

no test coverage detected