changes to how authorized fetch works

This commit is contained in:
Ashley 2024-08-24 10:49:58 +00:00
parent a7910e5f78
commit e0d21c04e2
3 changed files with 36 additions and 47 deletions

4
auth-fetch-notice.txt Normal file
View file

@ -0,0 +1,4 @@
Don't worry, we're not scraping your data.
You can view the source code of the bot on any of these sites:
https://git.lgbt/root/possumbot
https://git.anomalous.news/nyxaris/possumbot

View file

@ -1,59 +1,61 @@
import express from "express"; import express from 'express';
import fs from "fs"; import fs from 'fs';
import env from "dotenv"; import env from 'dotenv';
env.config(); env.config();
const domain = process.env.AP_FETCH_DOMAIN; const domain = process.env.AP_FETCH_DOMAIN;
const pubkey = fs.readFileSync("data/publickey.crt", 'utf8'); const pubkey = fs.readFileSync('data/publickey.crt', 'utf8');
const app = express(); const app = express();
const notice = `Don't worry, this doesn't scrape your data.`; const notice = fs.readFileSync('auth-fetch-notice.txt', 'utf8');
const actor = { const actor = {
"@context": [ '@context': [
"https://www.w3.org/ns/activitystreams", 'https://www.w3.org/ns/activitystreams',
"https://w3id.org/security/v1" 'https://w3id.org/security/v1'
], ],
"id": "https://" + domain + "/actor", 'id': 'https://' + domain + '/actor',
"type": "Person", 'type': 'Person',
"preferredUsername": "possumbot", 'preferredUsername': 'possumbot',
"inbox": "https://" + domain + "/inbox", 'inbox': 'https://' + domain + '/inbox',
"publicKey": { 'publicKey': {
"id": "https://" + domain + "/actor#main-key", 'id': 'https://' + domain + '/actor#main-key',
"owner": "https://" + domain + "/actor", 'owner': 'https://' + domain + '/actor',
"publicKeyPem": pubkey 'publicKeyPem': pubkey
} }
} }
const webfinger = { const webfinger = {
"subject": "acct:possumbot@" + domain + "", 'subject': 'acct:possumbot@' + domain + '',
"links": [ 'links': [
{ {
"rel": "self", 'rel': 'self',
"type": "application/activity+json", 'type': 'application/activity+json',
"href": "https://" + domain + "/actor" 'href': 'https://' + domain + '/actor'
} }
] ]
} }
app.get("/", (req, res) => { app.get('/', (req, res) => {
res.setHeader('content-type', 'text/plain'); res.setHeader('content-type', 'text/plain');
res.send(notice); res.write(notice);
}); });
app.get("/actor", (req, res) => { app.get('/actor', (req, res) => {
res.setHeader('content-type', 'application/activity+json'); res.writeHead(200, { 'Content-Type': 'application/activity+json' });
res.send(JSON.stringify(actor)); res.write(JSON.stringify(actor));
res.end();
}); });
app.get("/.well-known/webfinger", (req, res) => { app.get('/.well-known/webfinger', (req, res) => {
res.setHeader('content-type', 'application/activity+json'); res.writeHead(200, { 'Content-Type': 'application/json' });
res.send(JSON.stringify(webfinger)); res.write(JSON.stringify(webfinger));
res.end();
}); });
app.listen(process.env.AP_FETCH_PORT); app.listen(process.env.AP_FETCH_PORT);

View file

@ -18,20 +18,6 @@ const PATH_REGEX = {
cohost: /^\/[A-Za-z0-9]+\/post\/\d+-[A-Za-z0-9-]+\/?/, cohost: /^\/[A-Za-z0-9]+\/post\/\d+-[A-Za-z0-9-]+\/?/,
}; };
const PLATFORM_COLORS = {
mastodon: 0x2791da,
pleroma: 0xfba457,
akkoma: 0x593196,
misskey: 0x99c203,
calckey: 0x31748f,
firefish: 0xf07a5b, // YCbCr interpolated from the two logo colors
gotosocial: 0xff853e,
lemmy: 0x14854f,
birdsitelive: 0x1da1f2,
iceshrimp: 0x8e82f9, // YCbCr interpolated as the accent color is a gradient
cohost: 0x83254f,
};
const domainCache = new Map(); const domainCache = new Map();
domainCache.set("cohost.org", "cohost"); // no nodeinfo domainCache.set("cohost.org", "cohost"); // no nodeinfo
@ -124,7 +110,6 @@ async function processUrl(url) {
} }
let platform = (await resolvePlatform(url)) ?? "<no nodeinfo>"; let platform = (await resolvePlatform(url)) ?? "<no nodeinfo>";
let color = PLATFORM_COLORS[platform];
let platformName = platform let platformName = platform
.replace("gotosocial", "GoToSocial") .replace("gotosocial", "GoToSocial")
.replace("birdsitelive", '"Twitter" (BirdsiteLive)') .replace("birdsitelive", '"Twitter" (BirdsiteLive)')
@ -359,7 +344,6 @@ async function processUrl(url) {
const realUrlObj = new URL(postData.id); const realUrlObj = new URL(postData.id);
if(realUrlObj.origin != urlObj.origin) { if(realUrlObj.origin != urlObj.origin) {
platform = await resolvePlatform(postData.id); platform = await resolvePlatform(postData.id);
color = PLATFORM_COLORS[platform];
platformName = platform.replace("gotosocial", "GoToSocial").replace(/^(.)/, (_, c) => c.toUpperCase()); platformName = platform.replace("gotosocial", "GoToSocial").replace(/^(.)/, (_, c) => c.toUpperCase());
url = postData.id; url = postData.id;
} }
@ -514,7 +498,6 @@ async function processUrl(url) {
const user = author.name ? `${author.name} (${author.handle})` : author.handle; const user = author.name ? `${author.name} (${author.handle})` : author.handle;
const baseEmbed = { const baseEmbed = {
color,
url, url,
timestamp, timestamp,
description: desc, description: desc,