feat: update deno-github-mod.ts, add timeout
This commit is contained in:
@@ -30,9 +30,20 @@ export class SshKey {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchKeys(username: string): Promise<Array<SshKey>> {
|
export async function fetchKeys(
|
||||||
|
username: string,
|
||||||
|
timeout?: number,
|
||||||
|
): Promise<Array<SshKey>> {
|
||||||
const url = `https://github.com/${username}.keys`;
|
const url = `https://github.com/${username}.keys`;
|
||||||
const response = await fetch(url, getFetchAutoProxyInit());
|
const fetchTimeout = timeout || 10000;
|
||||||
|
const abortController = new AbortController();
|
||||||
|
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();
|
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));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user