(url: string, signal?: AbortSignal)
| 47 | |
| 48 | // 从网址取得脚本代码 |
| 49 | export 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 | // 通过代码解析出脚本基本信息 (不含数据库查询) |
| 67 | export function parseScriptFromCode(code: string, origin: string, uuid?: string): Script { |
no test coverage detected