this repo has no description

Metadata fetching

ari.express a29cdc09 1976f6ce

verified
Changed files
+137
+12
deno.json
··· 1 + { 2 + "tasks": { 3 + "dev": "deno run --watch main.ts" 4 + }, 5 + "imports": { 6 + "@atcute/bluesky": "npm:@atcute/bluesky@^2.0.2", 7 + "@atcute/client": "npm:@atcute/client@^3.0.1", 8 + "@skyware/jetstream": "npm:@skyware/jetstream@^0.2.2", 9 + "@std/assert": "jsr:@std/assert@1", 10 + "dotenv": "npm:dotenv@^16.5.0" 11 + } 12 + }
+67
deno.lock
··· 1 + { 2 + "version": "4", 3 + "specifiers": { 4 + "jsr:@std/assert@1": "1.0.12", 5 + "jsr:@std/internal@^1.0.6": "1.0.6", 6 + "npm:@atcute/bluesky@^2.0.2": "2.0.2_@atcute+client@3.0.1", 7 + "npm:@atcute/client@^3.0.1": "3.0.1", 8 + "npm:@skyware/jetstream@~0.2.2": "0.2.2_@atcute+client@3.0.1", 9 + "npm:dotenv@^16.5.0": "16.5.0" 10 + }, 11 + "jsr": { 12 + "@std/assert@1.0.12": { 13 + "integrity": "08009f0926dda9cbd8bef3a35d3b6a4b964b0ab5c3e140a4e0351fbf34af5b9a", 14 + "dependencies": [ 15 + "jsr:@std/internal" 16 + ] 17 + }, 18 + "@std/internal@1.0.6": { 19 + "integrity": "9533b128f230f73bd209408bb07a4b12f8d4255ab2a4d22a1fd6d87304aca9a4" 20 + } 21 + }, 22 + "npm": { 23 + "@atcute/bluesky@1.0.15_@atcute+client@3.0.1": { 24 + "integrity": "sha512-+EFiybmKQ97aBAgtaD+cKRJER5AMn3cZMkEwEg/pDdWyzxYJ9m1UgemmLdTgI8VrxPufKqdXS2nl7uO7TY6BPA==", 25 + "dependencies": [ 26 + "@atcute/client" 27 + ] 28 + }, 29 + "@atcute/bluesky@2.0.2_@atcute+client@3.0.1": { 30 + "integrity": "sha512-xU+9Rp8bzc9AOnWSc11M1urRppDt3BiWR7v2QrLt3Qoysa5jvL8j2p2w4iRT8vLByz8Q+Xgk5Kz4zWVx1zCiug==", 31 + "dependencies": [ 32 + "@atcute/client" 33 + ] 34 + }, 35 + "@atcute/client@3.0.1": { 36 + "integrity": "sha512-j51SuQYQj5jeKrx1DCXx+Q3fpVvO0JYGnKnJAdDSlesSLjPXjvnx1abC+hkuro58KRHHJvRA6P1MC0pmJsWfcg==" 37 + }, 38 + "@skyware/jetstream@0.2.2_@atcute+client@3.0.1": { 39 + "integrity": "sha512-d1MtWPTIFEciSzV8OClXZCJoz0DJ7aupt4EZSwpGAASYG0ZIPmZTt7RVJkoFzQyqRPHAMD7CvEwu0ut3MHX1og==", 40 + "dependencies": [ 41 + "@atcute/bluesky@1.0.15_@atcute+client@3.0.1", 42 + "partysocket" 43 + ] 44 + }, 45 + "dotenv@16.5.0": { 46 + "integrity": "sha512-m/C+AwOAr9/W1UOIZUo232ejMNnJAJtYQjUbHoNTBNTJSvqzzDh7vnrei3o3r3m9blf6ZoDkvcw0VmozNRFJxg==" 47 + }, 48 + "event-target-polyfill@0.0.4": { 49 + "integrity": "sha512-Gs6RLjzlLRdT8X9ZipJdIZI/Y6/HhRLyq9RdDlCsnpxr/+Nn6bU2EFGuC94GjxqhM+Nmij2Vcq98yoHrU8uNFQ==" 50 + }, 51 + "partysocket@1.1.3": { 52 + "integrity": "sha512-87Jd/nqPoWnVfzHE6Z12WLWTJ+TAgxs0b7i2S163HfQSrVDUK5tW/FC64T5N8L5ss+gqF+EV0BwjZMWggMY3UA==", 53 + "dependencies": [ 54 + "event-target-polyfill" 55 + ] 56 + } 57 + }, 58 + "workspace": { 59 + "dependencies": [ 60 + "jsr:@std/assert@1", 61 + "npm:@atcute/bluesky@^2.0.2", 62 + "npm:@atcute/client@^3.0.1", 63 + "npm:@skyware/jetstream@~0.2.2", 64 + "npm:dotenv@^16.5.0" 65 + ] 66 + } 67 + }
+58
main.ts
··· 1 + import { simpleFetchHandler, XRPC } from "@atcute/client"; 2 + import "@atcute/bluesky/lexicons"; 3 + 4 + interface AccountMetadata { 5 + did: string; 6 + displayName: string; 7 + avatarCid: string | null; 8 + } 9 + interface Post { 10 + text: string, 11 + timestamp: number, 12 + quoting: string | null, 13 + replying: string | null, 14 + imagesLinks: string[] | null, 15 + videosLinks: string[] | null, 16 + } 17 + 18 + const rpc = new XRPC({ 19 + handler: simpleFetchHandler({ 20 + service: Deno.env.get("PDS_URL") || "https://pds.witchcraft.systems", 21 + }), 22 + }); 23 + 24 + const getDidsFromPDS = async () => { 25 + const { data } = await rpc.get("com.atproto.sync.listRepos", { 26 + params: {}, 27 + }); 28 + return data.repos.map((repo: any) => (repo.did)); 29 + }; 30 + const getAccountMetadata = async (did: `did:${string}:${string}`) => { 31 + // gonna assume self exists in the app.bsky.actor.profile 32 + const { data: { value } } = await rpc.get("com.atproto.repo.getRecord", { 33 + params: { 34 + repo: did, 35 + collection: "app.bsky.actor.profile", 36 + rkey: "self", 37 + }, 38 + }); 39 + const account: AccountMetadata = { 40 + did: did, 41 + displayName: value.displayName, 42 + avatarCid: null, 43 + }; 44 + if (value.avatar) { 45 + account.avatarCid = value.avatar.ref["$link"]; 46 + } 47 + return account; 48 + }; 49 + 50 + const getAllMetadataFromPds = async () => { 51 + const dids = await getDidsFromPDS(); 52 + const metadata = await Promise.all( 53 + dids.map(async (repo: `did:${string}:${string}`) => { 54 + return await getAccountMetadata(repo); 55 + }), 56 + ); 57 + return metadata; 58 + };