feat: add deno-github-mod.ts, update deno-sshsig-mod.ts

This commit is contained in:
2025-01-19 14:42:36 +08:00
parent b057454890
commit c2e741ef16
2 changed files with 59 additions and 4 deletions

View File

@@ -0,0 +1,38 @@
import {
getFetchAutoProxyInit,
} from "https://hatter.ink/script/fetch/library/deno-fetch-auto-proxy-mod.ts?202501191421";
export class SshKey {
algorithm: string;
material: string;
description?: string;
constructor(
algorithm: string,
material: string,
description: string | undefined,
) {
this.algorithm = algorithm;
this.material = material;
this.description = description;
}
static parseSshKey(key: string): SshKey {
const keyParts = key.split(/\s+/);
if (keyParts.length < 2 || keyParts.length > 3) {
throw `Bad SSH key format ${key}`;
}
return new SshKey(
keyParts[0],
keyParts[1],
(keyParts.length > 2) ? keyParts[2] : undefined,
);
}
}
export async function fetchKeys(username: string): Promise<Array<SshKey>> {
const url = `https://github.com/${username}.keys`;
const response = await fetch(url, getFetchAutoProxyInit());
const responseText = await response.text();
return responseText.trim().split("\n").map((k) => SshKey.parseSshKey(k));
}