tangled
alpha
login
or
join now
essem.space
/
pds-feedgen
2
fork
atom
A couple of Bluesky feeds focused around PDSes
2
fork
atom
overview
issues
pulls
pipelines
Add endpoint to ingest/backfill specific user
essem.space
1 month ago
5a7b4617
8c67d41f
+29
-9
1 changed file
expand all
collapse all
unified
split
ingest.ts
+29
-9
ingest.ts
···
4
PlcDidDocumentResolver,
5
WebDidDocumentResolver,
6
} from "@atcute/identity-resolver";
7
-
import type { ResourceUri } from "@atcute/lexicons/syntax";
8
import { Jetstream, CommitType } from "@skyware/jetstream";
9
10
import type {} from "@atcute/atproto";
···
127
}
128
});
129
130
-
jetstream.on("identity", async (e) => {
131
-
const cached = getAuthor.get<Author>(e.did);
132
-
const pds = await getPDS(e.did as DID, true);
133
-
if (!pds || cached?.pds === pds) return;
134
const handler = simpleFetchHandler({ service: pds });
135
const rpc = new Client({ handler });
136
try {
137
const { records } = await ok(
138
rpc.get("com.atproto.repo.listRecords", {
139
params: {
140
-
repo: e.did,
141
collection: "app.bsky.feed.post",
142
},
143
-
})
144
);
145
worker.postMessage({
146
op: 2,
147
records,
148
-
did: e.did,
149
pds,
150
});
151
} catch (e) {
152
console.error(`Failed to backfill posts: ${e}`);
153
}
0
0
0
0
0
154
});
155
156
jetstream.start();
157
158
export default {
159
-
fetch() {
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
160
return new Response("Pong!");
161
},
162
} satisfies Deno.ServeDefaultExport;
···
4
PlcDidDocumentResolver,
5
WebDidDocumentResolver,
6
} from "@atcute/identity-resolver";
7
+
import type { ActorIdentifier, ResourceUri } from "@atcute/lexicons/syntax";
8
import { Jetstream, CommitType } from "@skyware/jetstream";
9
10
import type {} from "@atcute/atproto";
···
127
}
128
});
129
130
+
async function backfillUser(did: ActorIdentifier) {
131
+
const cached = getAuthor.get<Author>(did);
132
+
const pds = await getPDS(did as DID, true);
133
+
if (!pds || cached?.pds === pds) return false;
134
const handler = simpleFetchHandler({ service: pds });
135
const rpc = new Client({ handler });
136
try {
137
const { records } = await ok(
138
rpc.get("com.atproto.repo.listRecords", {
139
params: {
140
+
repo: did,
141
collection: "app.bsky.feed.post",
142
},
143
+
}),
144
);
145
worker.postMessage({
146
op: 2,
147
records,
148
+
did: did,
149
pds,
150
});
151
} catch (e) {
152
console.error(`Failed to backfill posts: ${e}`);
153
}
154
+
return true;
155
+
}
156
+
157
+
jetstream.on("identity", async (e) => {
158
+
await backfillUser(e.did);
159
});
160
161
jetstream.start();
162
163
export default {
164
+
async fetch(request) {
165
+
const url = new URL(request.url);
166
+
if (url.pathname === "/refresh") {
167
+
const did = url.searchParams.get("id");
168
+
if (!did) {
169
+
return new Response("No DID/handle provided", {
170
+
status: 400,
171
+
});
172
+
}
173
+
if (!(await backfillUser(did as ActorIdentifier))) {
174
+
return new Response(`Failed to refresh ${did}`, {
175
+
status: 500,
176
+
});
177
+
}
178
+
return new Response(`Refreshed ${did}`);
179
+
}
180
return new Response("Pong!");
181
},
182
} satisfies Deno.ServeDefaultExport;