From e0d21c04e2f8f1934e1fba795b3f84201f7c9475 Mon Sep 17 00:00:00 2001 From: Ashley Date: Sat, 24 Aug 2024 10:49:58 +0000 Subject: [PATCH] changes to how authorized fetch works --- auth-fetch-notice.txt | 4 +++ auth-fetch.js | 62 ++++++++++++++++++++++--------------------- lib/fedimbed.js | 17 ------------ 3 files changed, 36 insertions(+), 47 deletions(-) create mode 100644 auth-fetch-notice.txt diff --git a/auth-fetch-notice.txt b/auth-fetch-notice.txt new file mode 100644 index 0000000..b882e73 --- /dev/null +++ b/auth-fetch-notice.txt @@ -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 diff --git a/auth-fetch.js b/auth-fetch.js index e86d80a..3732895 100644 --- a/auth-fetch.js +++ b/auth-fetch.js @@ -1,59 +1,61 @@ -import express from "express"; -import fs from "fs"; +import express from 'express'; +import fs from 'fs'; -import env from "dotenv"; +import env from 'dotenv'; env.config(); 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 notice = `Don't worry, this doesn't scrape your data.`; +const notice = fs.readFileSync('auth-fetch-notice.txt', 'utf8'); const actor = { - "@context": [ - "https://www.w3.org/ns/activitystreams", - "https://w3id.org/security/v1" + '@context': [ + 'https://www.w3.org/ns/activitystreams', + 'https://w3id.org/security/v1' ], - "id": "https://" + domain + "/actor", - "type": "Person", - "preferredUsername": "possumbot", - "inbox": "https://" + domain + "/inbox", + 'id': 'https://' + domain + '/actor', + 'type': 'Person', + 'preferredUsername': 'possumbot', + 'inbox': 'https://' + domain + '/inbox', - "publicKey": { - "id": "https://" + domain + "/actor#main-key", - "owner": "https://" + domain + "/actor", - "publicKeyPem": pubkey + 'publicKey': { + 'id': 'https://' + domain + '/actor#main-key', + 'owner': 'https://' + domain + '/actor', + 'publicKeyPem': pubkey } } const webfinger = { - "subject": "acct:possumbot@" + domain + "", + 'subject': 'acct:possumbot@' + domain + '', - "links": [ + 'links': [ { - "rel": "self", - "type": "application/activity+json", - "href": "https://" + domain + "/actor" + 'rel': 'self', + 'type': 'application/activity+json', + 'href': 'https://' + domain + '/actor' } ] } -app.get("/", (req, res) => { - res.setHeader('content-type', 'text/plain'); - res.send(notice); +app.get('/', (req, res) => { + res.setHeader('content-type', 'text/plain'); + res.write(notice); }); -app.get("/actor", (req, res) => { - res.setHeader('content-type', 'application/activity+json'); - res.send(JSON.stringify(actor)); +app.get('/actor', (req, res) => { + res.writeHead(200, { 'Content-Type': 'application/activity+json' }); + res.write(JSON.stringify(actor)); + res.end(); }); -app.get("/.well-known/webfinger", (req, res) => { - res.setHeader('content-type', 'application/activity+json'); - res.send(JSON.stringify(webfinger)); +app.get('/.well-known/webfinger', (req, res) => { + res.writeHead(200, { 'Content-Type': 'application/json' }); + res.write(JSON.stringify(webfinger)); + res.end(); }); app.listen(process.env.AP_FETCH_PORT); diff --git a/lib/fedimbed.js b/lib/fedimbed.js index 58021b3..0d22c58 100644 --- a/lib/fedimbed.js +++ b/lib/fedimbed.js @@ -18,20 +18,6 @@ const PATH_REGEX = { 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(); domainCache.set("cohost.org", "cohost"); // no nodeinfo @@ -124,7 +110,6 @@ async function processUrl(url) { } let platform = (await resolvePlatform(url)) ?? ""; - let color = PLATFORM_COLORS[platform]; let platformName = platform .replace("gotosocial", "GoToSocial") .replace("birdsitelive", '"Twitter" (BirdsiteLive)') @@ -359,7 +344,6 @@ async function processUrl(url) { const realUrlObj = new URL(postData.id); if(realUrlObj.origin != urlObj.origin) { platform = await resolvePlatform(postData.id); - color = PLATFORM_COLORS[platform]; platformName = platform.replace("gotosocial", "GoToSocial").replace(/^(.)/, (_, c) => c.toUpperCase()); url = postData.id; } @@ -514,7 +498,6 @@ async function processUrl(url) { const user = author.name ? `${author.name} (${author.handle})` : author.handle; const baseEmbed = { - color, url, timestamp, description: desc,