MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / fetchScriptBody

Function fetchScriptBody

src/pkg/utils/script.ts:49–64  ·  view source on GitHub ↗
(url: string, signal?: AbortSignal)

Source from the content-addressed store, hash-verified

47
48// 从网址取得脚本代码
49export async function fetchScriptBody(url: string, signal?: AbortSignal): Promise<string> {
50 const resp = await fetch(url, {
51 signal,
52 headers: {
53 "Cache-Control": "no-cache",
54 },
55 });
56 if (resp.status !== 200) {
57 throw new Error("fetch script info failed");
58 }
59 if (resp.headers.get("content-type")?.includes("text/html")) {
60 throw new Error("url is html");
61 }
62 const body = await readRawContent(resp, resp.headers.get("content-type"));
63 return body;
64}
65
66// 通过代码解析出脚本基本信息 (不含数据库查询)
67export function parseScriptFromCode(code: string, origin: string, uuid?: string): Script {

Callers 6

_checkUpdateAvailableMethod · 0.90
installByUrlMethod · 0.90
_checkUpdateAvailableMethod · 0.90
_checkScriptUpdateMethod · 0.90
prepareScriptByCodeFunction · 0.70

Calls 2

readRawContentFunction · 0.90
getMethod · 0.65

Tested by

no test coverage detected