Metadata fetching

This commit is contained in:
Ariadna 2025-04-18 01:10:56 -04:00
parent 1976f6ce71
commit a29cdc090e
Signed by: ari
SSH key fingerprint: SHA256:j4xpQafvRcIH4rwZqM5aREIogWsCjyYohia7vH0+uZY
3 changed files with 137 additions and 0 deletions

58
main.ts Normal file
View file

@ -0,0 +1,58 @@
import { simpleFetchHandler, XRPC } from "@atcute/client";
import "@atcute/bluesky/lexicons";
interface AccountMetadata {
did: string;
displayName: string;
avatarCid: string | null;
}
interface Post {
text: string,
timestamp: number,
quoting: string | null,
replying: string | null,
imagesLinks: string[] | null,
videosLinks: string[] | null,
}
const rpc = new XRPC({
handler: simpleFetchHandler({
service: Deno.env.get("PDS_URL") || "https://pds.witchcraft.systems",
}),
});
const getDidsFromPDS = async () => {
const { data } = await rpc.get("com.atproto.sync.listRepos", {
params: {},
});
return data.repos.map((repo: any) => (repo.did));
};
const getAccountMetadata = async (did: `did:${string}:${string}`) => {
// gonna assume self exists in the app.bsky.actor.profile
const { data: { value } } = await rpc.get("com.atproto.repo.getRecord", {
params: {
repo: did,
collection: "app.bsky.actor.profile",
rkey: "self",
},
});
const account: AccountMetadata = {
did: did,
displayName: value.displayName,
avatarCid: null,
};
if (value.avatar) {
account.avatarCid = value.avatar.ref["$link"];
}
return account;
};
const getAllMetadataFromPds = async () => {
const dids = await getDidsFromPDS();
const metadata = await Promise.all(
dids.map(async (repo: `did:${string}:${string}`) => {
return await getAccountMetadata(repo);
}),
);
return metadata;
};