31 lines
803 B
TypeScript
31 lines
803 B
TypeScript
import { ensureDir } from "jsr:@std/fs@1";
|
|
|
|
import { ExportEntry } from "./directory-tailer.ts";
|
|
|
|
await ensureDir("./data/plc/live");
|
|
|
|
export async function writeLiveRecord(entry: ExportEntry, raw: string) {
|
|
const didplc = "did:plc:".length;
|
|
const prefix = entry.did.substring(didplc, didplc + 2);
|
|
const out = "./data/plc/live/" + prefix;
|
|
|
|
try {
|
|
await Deno.writeTextFile(
|
|
out,
|
|
[entry.did.substring(didplc), entry.createdAt, raw].join("\u001f") + "\n",
|
|
{
|
|
append: true,
|
|
}
|
|
);
|
|
} catch {
|
|
// directory probably does not exist, just try again
|
|
await ensureDir("./data/plc/live");
|
|
await Deno.writeTextFile(
|
|
out,
|
|
[entry.did.substring(didplc), entry.createdAt, raw].join("\u001f") + "\n",
|
|
{
|
|
append: true,
|
|
}
|
|
);
|
|
}
|
|
}
|