Add Base32 encoding support and enhance caching logic

This commit is contained in:
2026-04-06 10:20:50 +08:00
parent 9e18169744
commit 2df31a718e
2 changed files with 71 additions and 7 deletions

45
single-scripts/get-rfc.ts Executable file
View File

@@ -0,0 +1,45 @@
#!/usr/bin/env -S deno run -A
import { parseArgs } from "jsr:@std/cli/parse-args";
import {
args,
exit,
fetchFileWithCache,
readFileToString,
} from "https://global.hatter.ink/script/get/@62/deno-commons-mod.ts";
const flags = parseArgs(args(), {
boolean: ["help"],
string: ["id"],
});
function printHelp() {
console.log("get-rfc.ts --id <RFC ID>");
}
if (flags.help) {
printHelp();
exit(0);
}
if (flags.id) {
const rfcId = parseInt(flags.id, 10);
if (isNaN(rfcId)) {
console.error("Invalid RFC id");
exit(1);
}
await getAndPrintRfc(rfcId);
} else {
printHelp();
exit(1);
}
async function getAndPrintRfc(rfcId: number): Promise<void> {
const url = `https://play.hatter.me/ietf/rfc${rfcId}.txt`;
const fileMeta = await fetchFileWithCache(url, {
base32Filename: true,
hierarchicalCacheDir: true,
});
const content = await readFileToString(fileMeta.cache_full_path);
console.log(content);
}