changes to how authorized fetch works
This commit is contained in:
parent
a7910e5f78
commit
e0d21c04e2
3 changed files with 36 additions and 47 deletions
4
auth-fetch-notice.txt
Normal file
4
auth-fetch-notice.txt
Normal 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
|
|
@ -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);
|
||||
|
|
|
@ -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)) ?? "<no nodeinfo>";
|
||||
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,
|
||||
|
|
Loading…
Reference in a new issue