Cleanup and Maintenance part 1 (#1)
All checks were successful
Deploy / Deploy (push) Successful in 30s

Co-authored-by: ari <ariadna@omg.lol>
Reviewed-on: #1
This commit is contained in:
Astra 2025-04-21 06:30:49 +00:00
parent 7d850f0ab5
commit b01b6b7f65
8 changed files with 67 additions and 51 deletions

View file

@ -48,7 +48,7 @@ class Post {
account: AccountMetadata,
) {
this.postCid = record.cid;
this.recordName = record.uri.split("/").slice(-1)[0];
this.recordName = processAtUri(record.uri).rkey;
this.authorDid = account.did;
this.authorAvatarCid = account.avatarCid;
this.authorHandle = account.handle;
@ -111,13 +111,13 @@ const rpc = new XRPC({
}),
});
const getDidsFromPDS = async () => {
const getDidsFromPDS = async () : Promise<At.Did[]> => {
const { data } = await rpc.get("com.atproto.sync.listRepos", {
params: {},
});
return data.repos.map((repo: any) => (repo.did));
return data.repos.map((repo: any) => (repo.did)) as At.Did[];
};
const getAccountMetadata = async (did: `did:${string}:${string}`) => {
const getAccountMetadata = async (did: `did:${string}:${string}`) : Promise<AccountMetadata> => {
// gonna assume self exists in the app.bsky.actor.profile
try {
const { data } = await rpc.get("com.atproto.repo.getRecord", {
@ -146,11 +146,12 @@ const getAccountMetadata = async (did: `did:${string}:${string}`) => {
did: "error",
displayName: "",
avatarCid: null,
handle: "error",
};
}
};
const getAllMetadataFromPds = async () => {
const getAllMetadataFromPds = async () : Promise<AccountMetadata[]> => {
const dids = await getDidsFromPDS();
const metadata = await Promise.all(
dids.map(async (repo: `did:${string}:${string}`) => {
@ -166,7 +167,7 @@ const fetchPosts = async (did: string) => {
params: {
repo: did as At.Identifier,
collection: "app.bsky.feed.post",
limit: Config.MAX_POSTS_PER_USER,
limit: Config.MAX_POSTS,
},
});
return {
@ -237,14 +238,7 @@ const fetchAllPosts = async () => {
})
);
posts.sort((a, b) => b.timestamp - a.timestamp);
return posts;
};
const testApiCall = async () => {
const { data } = await rpc.get("com.atproto.sync.listRepos", {
params: {},
});
console.log(data);
return posts.slice(0, Config.MAX_POSTS);
};
export { fetchAllPosts, getAllMetadataFromPds, Post };
export type { AccountMetadata };