feat: update deno-github-mode.ts

This commit is contained in:
2025-01-19 18:19:22 +08:00
parent 35b310bd3f
commit 15dd204154

View File

@@ -1,6 +1,6 @@
import { import {
getFetchAutoProxyInit, fetchWithTimoutAndAutoProxy,
} from "https://hatter.ink/script/fetch/library/deno-fetch-auto-proxy-mod.ts?202501191421"; } from "https://hatter.ink/script/fetch/library/deno-fetch-auto-proxy-mod.ts?202501191815";
export class SshKey { export class SshKey {
algorithm: string; algorithm: string;
@@ -35,15 +35,7 @@ export async function fetchKeys(
timeout?: number, timeout?: number,
): Promise<Array<SshKey>> { ): Promise<Array<SshKey>> {
const url = `https://github.com/${username}.keys`; const url = `https://github.com/${username}.keys`;
const fetchTimeout = timeout || 10000; const response = await fetchWithTimoutAndAutoProxy(url, timeout);
const abortController = new AbortController(); const responseText: string = await response.text();
const timoutHandler = setTimeout(() => {
abortController.abort(`Timout ${fetchTimeout} ms`);
}, fetchTimeout);
const init = getFetchAutoProxyInit() || {};
init.signal = abortController.signal;
const response = await fetch(url, init);
const responseText = await response.text();
clearTimeout(timoutHandler);
return responseText.trim().split("\n").map((k) => SshKey.parseSshKey(k)); return responseText.trim().split("\n").map((k) => SshKey.parseSshKey(k));
} }