Skip to content

Instantly share code, notes, and snippets.

@tmcw

tmcw/user.ts Secret

Created December 8, 2022 16:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmcw/4ba9dfcf06c98c0d0da932b83519c662 to your computer and use it in GitHub Desktop.
Save tmcw/4ba9dfcf06c98c0d0da932b83519c662 to your computer and use it in GitHub Desktop.
import { Context } from "https://edge.netlify.com/";
const DOMAIN = "macwright.com";
const publicKey = `-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA7LBs3Qyuh93lRboTNXLN
hj4n92oK5Qg4oS8Cc81AXh04hD7nQSSKBhtarbHy2yPXeiKA+H3EGbcflsLvZCo2
B3OPNo2nGTCMyJM8HWDf/7JCOHHcy4tZC1ldjrItkb1YDABWwfoXxyBiGTyTVXjL
sBX5ArTGUPwctMSOdxlJp0ttFn5WDIHiPzxbSaEX/fzTy+HKr9RvYPu/hWWpXA/W
8QQRacZjslweupZFGCGPX1zJ+P0FSe81uV6N5cOPpy+vFkBQrvApwCSIyp/n7Rfq
UtU+zi/ru+wSxyvnoZPZa+zOXst8+pk7lIbmI6dyJ2+wijkykAxKt2DnDXWOSUGM
R+aNjc6tt8xp2MwmhAz91f1rIt2+jOhkPZ0m6aLV3B86J3iI0BIHXzQNydDtz5/P
EOj79vnnDwjCrWmbsfsIVCmECQDS7EW6Lzdc98GyiD/vyA4Epg3QgpeN4r7fELZj
8IfJJ7J8Z8nYewRoCVNnfvXpR26y+CLftMUi9LtPP1N78er1IdvZEer/8RIAc58r
S5VmDYBBfEduxPh/l3tn4A5Ri8smue26yG+wPkBj3CSqaOaNFxxZPgXcbI2OePrH
81goKk17g+5O0sZJGv+EAeFM1OQPXKqyu0DLY6PHJKGSho/B/BNWQ34vZnQhQF1r
++VZAcLEeqny/Cn6CHoeu5cCAwEAAQ==
-----END PUBLIC KEY-----`;
const ACTORS = new Map([
[
"/u/photos",
{
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1",
],
id: `https://${DOMAIN}/u/photos`,
type: "Person",
preferredUsername: `photos`,
summary: "Photos from macwright.com",
inbox: `https://${DOMAIN}/api/inbox`,
followers: `https://${DOMAIN}/u/photos/followers`,
icon: {
type: "Image",
mediaType: "image/jpeg",
url: "https://macwright.com/graphics/about.jpg",
},
publicKey: {
id: `https://${DOMAIN}/u/photos#main-key`,
owner: `https://${DOMAIN}/u/photos`,
publicKeyPem: publicKey,
},
},
],
]);
export default function handler(req: Request, context: Context) {
const u = new URL(req.url);
const resource = u.pathname;
if (resource && ACTORS.has(resource)) {
if (req.headers.get("accept")?.includes("text/html")) {
return context.rewrite("/photos");
}
return new Response(JSON.stringify(ACTORS.get(resource)), {
status: 200,
headers: { "Content-Type": "application/activity+json" },
});
}
return new Response("", {
status: 404,
headers: { "Content-Type": "text/html" },
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment