blob: ab235427f31910dc9368fde805c305e8eb6213bf (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
const nodeFetch = require("node-fetch");
const fetch = (url, opts) =>
nodeFetch(url, {
...opts,
headers: {
Accept: "application/activity+json",
...(opts?.headers || {}),
},
}).then((x) => x.json());
const webfinger = async (domain, user) => {
const query = `https://${domain}/.well-known/webfinger?resource=@${user}@${domain}`;
const json = await fetch(query);
return json.links.find((x) => x.rel == "self").href;
};
(async () => {
const userLocation = await webfinger(
"chat.understars.dev",
"1140599542186631381",
);
console.log(userLocation);
const user = await fetch(userLocation);
const outbox = await fetch(user.outbox);
const firstPage = await fetch(outbox.first);
const mostRecent = firstPage.orderedItems[0];
console.log(mostRecent);
})();
|