2019-02-20 22:12:29 +00:00
|
|
|
import express, { Router } from "express";
|
|
|
|
import { promises as fs } from "fs";
|
|
|
|
|
|
|
|
const domain = process.env.DOMAIN;
|
2022-03-20 18:28:38 +00:00
|
|
|
const pubKeyPemPath = process.env.PUB_KEY_PEM;
|
2019-02-20 22:12:29 +00:00
|
|
|
|
2019-02-20 23:07:29 +00:00
|
|
|
export default async function actor(router: Router) {
|
2022-03-20 18:28:38 +00:00
|
|
|
if (!pubKeyPemPath) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const pubKeyPem = (await fs.readFile(pubKeyPemPath)).toString();
|
2019-02-20 22:12:29 +00:00
|
|
|
const actorObj = {
|
|
|
|
"@context": [
|
|
|
|
"https://www.w3.org/ns/activitystreams",
|
|
|
|
"https://w3id.org/security/v1"
|
|
|
|
],
|
|
|
|
"type": "Person",
|
|
|
|
"id": `https://${domain}/ap/actor`,
|
2019-02-24 15:21:14 +00:00
|
|
|
"preferredUsername": "blog",
|
2019-02-20 22:12:29 +00:00
|
|
|
"name": "shadowfacts' blog",
|
|
|
|
"icon": {
|
|
|
|
"type": "Image",
|
|
|
|
"mediaType": "image/png",
|
|
|
|
"url": `https://${domain}/shadowfacts.png`
|
|
|
|
},
|
|
|
|
"inbox": `https://${domain}/ap/inbox`,
|
|
|
|
"followers": `https://${domain}/ap/actor/followers`,
|
|
|
|
"publicKey": {
|
|
|
|
"id": `https://${domain}/ap/actor#main-key`,
|
|
|
|
"owner": `https://${domain}/ap/actor`,
|
|
|
|
"publicKeyPem": pubKeyPem
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
router.get("/ap/actor", (req, res) => {
|
2019-10-10 16:31:49 +00:00
|
|
|
if (req.accepts("text/html")) {
|
|
|
|
res.redirect("/");
|
|
|
|
} else {
|
2019-02-20 22:12:29 +00:00
|
|
|
res.type("application/activity+json");
|
|
|
|
res.json(actorObj);
|
|
|
|
res.end();
|
|
|
|
}
|
|
|
|
});
|
2019-10-10 16:31:49 +00:00
|
|
|
}
|