2023-05-17 13:13:30 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
2023-06-19 17:29:22 -04:00
|
|
|
const nconf = require('nconf');
|
2024-01-05 22:45:33 -05:00
|
|
|
const winston = require('winston');
|
2024-04-11 10:39:51 -04:00
|
|
|
const { createHash, createSign, createVerify, getHashes } = require('crypto');
|
2024-06-04 14:18:14 -04:00
|
|
|
const { CronJob } = require('cron');
|
2023-05-17 13:13:30 -04:00
|
|
|
|
2023-12-19 14:33:38 -05:00
|
|
|
const request = require('../request');
|
2023-05-29 17:42:44 -04:00
|
|
|
const db = require('../database');
|
2024-02-26 16:12:40 -05:00
|
|
|
const meta = require('../meta');
|
2023-06-19 17:29:22 -04:00
|
|
|
const user = require('../user');
|
2024-01-22 16:18:49 -05:00
|
|
|
const utils = require('../utils');
|
2023-06-23 14:59:47 -04:00
|
|
|
const ttl = require('../cache/ttl');
|
2024-05-06 22:49:31 +02:00
|
|
|
const lru = require('../cache/lru');
|
2024-05-06 22:52:48 +02:00
|
|
|
const batch = require('../batch');
|
2024-05-06 23:16:58 +02:00
|
|
|
const pubsub = require('../pubsub');
|
2024-05-14 12:06:59 -04:00
|
|
|
const analytics = require('../analytics');
|
2023-05-17 13:13:30 -04:00
|
|
|
|
2024-06-04 12:31:13 -04:00
|
|
|
const requestCache = ttl({
|
|
|
|
|
max: 5000,
|
|
|
|
|
ttl: 1000 * 60 * 5, // 5 minutes
|
|
|
|
|
});
|
2023-05-17 13:13:30 -04:00
|
|
|
const ActivityPub = module.exports;
|
|
|
|
|
|
2024-01-24 11:44:10 -05:00
|
|
|
ActivityPub._constants = Object.freeze({
|
2024-02-26 11:39:32 -05:00
|
|
|
uid: -2,
|
2024-01-24 11:44:10 -05:00
|
|
|
publicAddress: 'https://www.w3.org/ns/activitystreams#Public',
|
2024-04-08 20:06:26 +02:00
|
|
|
acceptableTypes: [
|
|
|
|
|
'application/activity+json',
|
|
|
|
|
'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
|
|
|
|
|
],
|
2024-04-14 02:42:30 +02:00
|
|
|
acceptedPostTypes: [
|
|
|
|
|
'Note', 'Page', 'Article', 'Question',
|
|
|
|
|
],
|
2024-04-25 20:05:53 +02:00
|
|
|
acceptedProtocols: ['https', ...(process.env.CI === 'true' ? ['http'] : [])],
|
2024-01-24 11:44:10 -05:00
|
|
|
});
|
2024-02-21 10:26:26 -05:00
|
|
|
ActivityPub._cache = requestCache;
|
2024-01-24 11:44:10 -05:00
|
|
|
|
2023-06-02 14:22:43 -04:00
|
|
|
ActivityPub.helpers = require('./helpers');
|
2023-06-28 14:59:39 -04:00
|
|
|
ActivityPub.inbox = require('./inbox');
|
2024-01-10 14:19:57 -05:00
|
|
|
ActivityPub.mocks = require('./mocks');
|
2024-01-11 10:05:02 -05:00
|
|
|
ActivityPub.notes = require('./notes');
|
2024-01-26 15:10:35 -05:00
|
|
|
ActivityPub.actors = require('./actors');
|
2024-06-17 15:50:27 -04:00
|
|
|
ActivityPub.instances = require('./instances');
|
2023-06-02 14:22:43 -04:00
|
|
|
|
2024-06-04 14:18:14 -04:00
|
|
|
ActivityPub.startJobs = () => {
|
2024-06-07 11:56:58 -04:00
|
|
|
// winston.verbose('[activitypub/jobs] Registering jobs.');
|
2024-06-10 19:24:06 -04:00
|
|
|
new CronJob('0 0 * * *', async () => {
|
|
|
|
|
try {
|
|
|
|
|
await ActivityPub.notes.prune();
|
|
|
|
|
} catch (err) {
|
|
|
|
|
winston.error(err.stack);
|
|
|
|
|
}
|
|
|
|
|
}, null, true, null, null, false); // change last argument to true for debugging
|
|
|
|
|
|
|
|
|
|
new CronJob('0 1 * * *', async () => {
|
|
|
|
|
try {
|
|
|
|
|
await ActivityPub.actors.prune();
|
|
|
|
|
} catch (err) {
|
|
|
|
|
winston.error(err.stack);
|
|
|
|
|
}
|
2024-06-10 19:27:03 -04:00
|
|
|
}, null, true, null, null, false); // change last argument to true for debugging
|
2024-06-04 14:18:14 -04:00
|
|
|
};
|
|
|
|
|
|
2024-02-21 10:58:20 -05:00
|
|
|
ActivityPub.resolveId = async (uid, id) => {
|
|
|
|
|
try {
|
|
|
|
|
const query = new URL(id);
|
|
|
|
|
({ id } = await ActivityPub.get('uid', uid, id));
|
|
|
|
|
const response = new URL(id);
|
|
|
|
|
|
|
|
|
|
if (query.host !== response.host) {
|
|
|
|
|
winston.warn(`[activitypub/resolveId] id resolution domain mismatch: ${query.href} != ${response.href}`);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return id;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-01-26 15:10:35 -05:00
|
|
|
ActivityPub.resolveInboxes = async (ids) => {
|
2024-01-24 11:44:10 -05:00
|
|
|
const inboxes = new Set();
|
|
|
|
|
|
2024-02-26 16:12:40 -05:00
|
|
|
if (!meta.config.activitypubAllowLoopback) {
|
|
|
|
|
ids = ids.filter((id) => {
|
|
|
|
|
const { hostname } = new URL(id);
|
|
|
|
|
return hostname !== nconf.get('url_parsed').hostname;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-26 21:39:20 -05:00
|
|
|
await ActivityPub.actors.assert(ids);
|
2024-01-24 11:44:10 -05:00
|
|
|
await Promise.all(ids.map(async (id) => {
|
2024-01-26 15:10:35 -05:00
|
|
|
const { inbox, sharedInbox } = await user.getUserFields(id, ['inbox', 'sharedInbox']);
|
|
|
|
|
if (sharedInbox || inbox) {
|
|
|
|
|
inboxes.add(sharedInbox || inbox);
|
2024-01-24 11:44:10 -05:00
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
return Array.from(inboxes);
|
|
|
|
|
};
|
2023-06-23 14:59:47 -04:00
|
|
|
|
2024-02-05 16:57:17 -05:00
|
|
|
ActivityPub.getPublicKey = async (type, id) => {
|
2023-05-17 13:13:30 -04:00
|
|
|
let publicKey;
|
|
|
|
|
|
|
|
|
|
try {
|
2024-02-06 10:40:46 -05:00
|
|
|
({ publicKey } = await db.getObject(`${type}:${id}:keys`));
|
2023-05-17 13:13:30 -04:00
|
|
|
} catch (e) {
|
2024-02-05 16:57:17 -05:00
|
|
|
({ publicKey } = await ActivityPub.helpers.generateKeys(type, id));
|
2023-05-17 13:13:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return publicKey;
|
|
|
|
|
};
|
|
|
|
|
|
2024-02-05 16:57:17 -05:00
|
|
|
ActivityPub.getPrivateKey = async (type, id) => {
|
|
|
|
|
// Sanity checking
|
|
|
|
|
if (!['cid', 'uid'].includes(type) || !utils.isNumber(id) || parseInt(id, 10) < 0) {
|
|
|
|
|
throw new Error('[[error:invalid-data]]');
|
|
|
|
|
}
|
|
|
|
|
id = parseInt(id, 10);
|
2023-06-19 17:29:22 -04:00
|
|
|
let privateKey;
|
|
|
|
|
|
|
|
|
|
try {
|
2024-02-05 16:57:17 -05:00
|
|
|
({ privateKey } = await db.getObject(`${type}:${id}:keys`));
|
2023-06-19 17:29:22 -04:00
|
|
|
} catch (e) {
|
2024-02-05 16:57:17 -05:00
|
|
|
({ privateKey } = await ActivityPub.helpers.generateKeys(type, id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let keyId;
|
|
|
|
|
if (type === 'uid') {
|
|
|
|
|
keyId = `${nconf.get('url')}${id > 0 ? `/uid/${id}` : '/actor'}#key`;
|
|
|
|
|
} else {
|
|
|
|
|
keyId = `${nconf.get('url')}/category/${id}#key`;
|
2023-06-19 17:29:22 -04:00
|
|
|
}
|
|
|
|
|
|
2024-02-05 16:57:17 -05:00
|
|
|
return { key: privateKey, keyId };
|
2023-06-19 17:29:22 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ActivityPub.fetchPublicKey = async (uri) => {
|
|
|
|
|
// Used for retrieving the public key from the passed-in keyId uri
|
2024-04-09 19:27:35 +02:00
|
|
|
const body = await ActivityPub.get('uid', 0, uri);
|
2023-05-17 13:13:30 -04:00
|
|
|
|
2024-04-09 19:27:35 +02:00
|
|
|
if (!body.hasOwnProperty('publicKey')) {
|
2024-01-18 15:21:46 -05:00
|
|
|
throw new Error('[[error:activitypub.pubKey-not-found]]');
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-19 14:33:38 -05:00
|
|
|
return body.publicKey;
|
2023-06-19 17:29:22 -04:00
|
|
|
};
|
|
|
|
|
|
2024-02-05 16:57:17 -05:00
|
|
|
ActivityPub.sign = async ({ key, keyId }, url, payload) => {
|
2023-06-19 17:29:22 -04:00
|
|
|
// Returns string for use in 'Signature' header
|
|
|
|
|
const { host, pathname } = new URL(url);
|
|
|
|
|
const date = new Date().toUTCString();
|
|
|
|
|
let digest = null;
|
|
|
|
|
|
|
|
|
|
let headers = '(request-target) host date';
|
|
|
|
|
let signed_string = `(request-target): ${payload ? 'post' : 'get'} ${pathname}\nhost: ${host}\ndate: ${date}`;
|
|
|
|
|
|
|
|
|
|
// Calculate payload hash if payload present
|
|
|
|
|
if (payload) {
|
|
|
|
|
const payloadHash = createHash('sha256');
|
|
|
|
|
payloadHash.update(JSON.stringify(payload));
|
2024-04-06 02:06:41 +02:00
|
|
|
digest = `SHA-256=${payloadHash.digest('base64')}`;
|
2023-06-19 17:29:22 -04:00
|
|
|
headers += ' digest';
|
|
|
|
|
signed_string += `\ndigest: ${digest}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sign string using private key
|
|
|
|
|
let signature = createSign('sha256');
|
2023-12-22 12:58:46 -05:00
|
|
|
signature.update(signed_string);
|
2023-06-19 17:29:22 -04:00
|
|
|
signature.end();
|
2023-12-22 12:58:46 -05:00
|
|
|
signature = signature.sign(key, 'base64');
|
2023-06-19 17:29:22 -04:00
|
|
|
|
|
|
|
|
// Construct signature header
|
|
|
|
|
return {
|
|
|
|
|
date,
|
|
|
|
|
digest,
|
2024-04-11 10:39:51 -04:00
|
|
|
signature: `keyId="${keyId}",headers="${headers}",signature="${signature}",algorithm="hs2019"`,
|
2023-06-19 17:29:22 -04:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ActivityPub.verify = async (req) => {
|
2024-06-07 11:56:58 -04:00
|
|
|
// winston.verbose('[activitypub/verify] Starting signature verification...');
|
2024-01-19 11:43:21 -05:00
|
|
|
if (!req.headers.hasOwnProperty('signature')) {
|
2024-06-07 11:56:58 -04:00
|
|
|
// winston.verbose('[activitypub/verify] Failed, no signature header.');
|
2024-01-19 11:43:21 -05:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-19 17:29:22 -04:00
|
|
|
// Break the signature apart
|
2024-04-11 15:20:59 -04:00
|
|
|
let { keyId, headers, signature, algorithm, created, expires } = req.headers.signature.split(',').reduce((memo, cur) => {
|
2023-06-19 17:29:22 -04:00
|
|
|
const split = cur.split('="');
|
|
|
|
|
const key = split.shift();
|
|
|
|
|
const value = split.join('="');
|
|
|
|
|
memo[key] = value.slice(0, -1);
|
|
|
|
|
return memo;
|
|
|
|
|
}, {});
|
|
|
|
|
|
2024-04-11 10:39:51 -04:00
|
|
|
const acceptableHashes = getHashes();
|
|
|
|
|
if (algorithm === 'hs2019' || !acceptableHashes.includes(algorithm)) {
|
|
|
|
|
algorithm = 'sha256';
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-19 17:29:22 -04:00
|
|
|
// Re-construct signature string
|
|
|
|
|
const signed_string = headers.split(' ').reduce((memo, cur) => {
|
2024-04-11 15:20:59 -04:00
|
|
|
switch (cur) {
|
|
|
|
|
case '(request-target)': {
|
|
|
|
|
memo.push(`${cur}: ${String(req.method).toLowerCase()} ${req.baseUrl}${req.path}`);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case '(created)': {
|
2024-04-11 15:23:19 -04:00
|
|
|
memo.push(`${cur}: ${created}`);
|
2024-04-11 15:20:59 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case '(expires)': {
|
2024-04-11 15:23:19 -04:00
|
|
|
memo.push(`${cur}: ${expires}`);
|
2024-04-11 15:20:59 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default: {
|
|
|
|
|
memo.push(`${cur}: ${req.headers[cur]}`);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-06-19 17:29:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return memo;
|
|
|
|
|
}, []).join('\n');
|
|
|
|
|
|
|
|
|
|
// Verify the signature string via public key
|
|
|
|
|
try {
|
2024-01-18 15:21:46 -05:00
|
|
|
// Retrieve public key from remote instance
|
2024-06-07 11:56:58 -04:00
|
|
|
// winston.verbose(`[activitypub/verify] Retrieving pubkey for ${keyId}`);
|
2024-01-18 15:21:46 -05:00
|
|
|
const { publicKeyPem } = await ActivityPub.fetchPublicKey(keyId);
|
|
|
|
|
|
2023-06-19 17:29:22 -04:00
|
|
|
const verify = createVerify('sha256');
|
2023-12-22 12:58:46 -05:00
|
|
|
verify.update(signed_string);
|
2023-06-19 17:29:22 -04:00
|
|
|
verify.end();
|
2024-06-07 11:56:58 -04:00
|
|
|
// winston.verbose('[activitypub/verify] Attempting signed string verification');
|
2023-12-22 12:58:46 -05:00
|
|
|
const verified = verify.verify(publicKeyPem, signature, 'base64');
|
2023-06-19 17:29:22 -04:00
|
|
|
return verified;
|
|
|
|
|
} catch (e) {
|
2024-06-07 11:56:58 -04:00
|
|
|
// winston.verbose('[activitypub/verify] Failed, key retrieval or verification failure.');
|
2023-06-19 17:29:22 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-02-05 16:57:17 -05:00
|
|
|
ActivityPub.get = async (type, id, uri) => {
|
|
|
|
|
const cacheKey = [id, uri].join(';');
|
2024-06-04 12:31:13 -04:00
|
|
|
const cached = requestCache.get(cacheKey);
|
|
|
|
|
if (cached !== undefined) {
|
|
|
|
|
return cached;
|
2024-01-12 11:27:55 -05:00
|
|
|
}
|
|
|
|
|
|
2024-02-05 16:57:17 -05:00
|
|
|
const keyData = await ActivityPub.getPrivateKey(type, id);
|
|
|
|
|
const headers = id >= 0 ? await ActivityPub.sign(keyData, uri) : {};
|
2024-06-07 11:56:58 -04:00
|
|
|
// winston.verbose(`[activitypub/get] ${uri}`);
|
2024-02-26 11:39:32 -05:00
|
|
|
try {
|
|
|
|
|
const { response, body } = await request.get(uri, {
|
|
|
|
|
headers: {
|
|
|
|
|
...headers,
|
|
|
|
|
Accept: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
|
|
|
|
|
},
|
2024-04-04 12:22:13 -04:00
|
|
|
timeout: 5000,
|
2024-02-26 11:39:32 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!String(response.statusCode).startsWith('2')) {
|
2024-06-13 14:53:47 -04:00
|
|
|
winston.verbose(`[activitypub/get] Received ${response.statusCode} when querying ${uri}`);
|
2024-02-26 11:39:32 -05:00
|
|
|
if (body.hasOwnProperty('error')) {
|
2024-06-13 14:53:47 -04:00
|
|
|
winston.verbose(`[activitypub/get] Error received: ${body.error}`);
|
2024-02-26 11:39:32 -05:00
|
|
|
}
|
|
|
|
|
|
2024-06-13 14:53:47 -04:00
|
|
|
const e = new Error(`[[error:activitypub.get-failed]]`);
|
|
|
|
|
e.code = `ap_get_${response.statusCode}`;
|
|
|
|
|
throw e;
|
2024-01-05 22:45:33 -05:00
|
|
|
}
|
2024-01-08 14:30:09 -05:00
|
|
|
|
2024-02-26 11:39:32 -05:00
|
|
|
requestCache.set(cacheKey, body);
|
|
|
|
|
return body;
|
|
|
|
|
} catch (e) {
|
2024-06-13 14:53:47 -04:00
|
|
|
if (String(e.code).startsWith('ap_get_')) {
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-26 11:39:32 -05:00
|
|
|
// Handle things like non-json body, etc.
|
2024-06-13 14:53:47 -04:00
|
|
|
const { cause } = e;
|
|
|
|
|
throw new Error(`[[error:activitypub.get-failed]]`, { cause });
|
2024-01-05 22:45:33 -05:00
|
|
|
}
|
2024-01-05 11:39:17 -05:00
|
|
|
};
|
|
|
|
|
|
2024-05-06 22:49:31 +02:00
|
|
|
ActivityPub.retryQueue = lru({ name: 'activitypub-retry-queue', max: 4000, ttl: 1000 * 60 * 60 * 24 * 60 });
|
|
|
|
|
|
2024-05-06 23:16:58 +02:00
|
|
|
// handle clearing retry queue from another member of the cluster
|
|
|
|
|
pubsub.on(`activitypub-retry-queue:lruCache:del`, (keys) => {
|
|
|
|
|
if (Array.isArray(keys)) {
|
|
|
|
|
keys.forEach(key => clearTimeout(ActivityPub.retryQueue.get(key)));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-06 22:49:31 +02:00
|
|
|
async function sendMessage(uri, id, type, payload, attempts = 1) {
|
|
|
|
|
const keyData = await ActivityPub.getPrivateKey(type, id);
|
|
|
|
|
const headers = await ActivityPub.sign(keyData, uri, payload);
|
2024-06-07 11:56:58 -04:00
|
|
|
// winston.verbose(`[activitypub/send] ${uri}`);
|
2024-05-06 22:49:31 +02:00
|
|
|
try {
|
|
|
|
|
const { response, body } = await request.post(uri, {
|
|
|
|
|
headers: {
|
|
|
|
|
...headers,
|
|
|
|
|
'content-type': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
|
|
|
|
|
},
|
|
|
|
|
body: payload,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (String(response.statusCode).startsWith('2')) {
|
2024-06-07 11:56:58 -04:00
|
|
|
// winston.verbose(`[activitypub/send] Successfully sent ${payload.type} to ${uri}`);
|
2024-05-06 22:49:31 +02:00
|
|
|
} else {
|
|
|
|
|
throw new Error(String(body));
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
winston.warn(`[activitypub/send] Could not send ${payload.type} to ${uri}; error: ${e.message}`);
|
|
|
|
|
// add to retry queue
|
|
|
|
|
if (attempts < 12) { // stop attempting after ~2 months
|
|
|
|
|
const timeout = (4 ** attempts) * 1000; // exponential backoff
|
|
|
|
|
const queueId = `${payload.type}:${payload.id}:${new URL(uri).hostname}`;
|
|
|
|
|
const timeoutId = setTimeout(() => sendMessage(uri, id, type, payload, attempts + 1), timeout);
|
|
|
|
|
ActivityPub.retryQueue.set(queueId, timeoutId);
|
|
|
|
|
|
2024-06-07 11:56:58 -04:00
|
|
|
// winston.verbose(`[activitypub/send] Added ${payload.type} to ${uri} to retry queue for ${timeout}ms`);
|
2024-05-06 23:06:06 +02:00
|
|
|
} else {
|
|
|
|
|
winston.warn(`[activitypub/send] Max attempts reached for ${payload.type} to ${uri}; giving up on sending`);
|
2024-05-06 22:49:31 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-05 16:57:17 -05:00
|
|
|
ActivityPub.send = async (type, id, targets, payload) => {
|
2023-06-23 14:59:47 -04:00
|
|
|
if (!Array.isArray(targets)) {
|
|
|
|
|
targets = [targets];
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-26 21:39:20 -05:00
|
|
|
const inboxes = await ActivityPub.resolveInboxes(targets);
|
2023-06-23 14:59:47 -04:00
|
|
|
|
2024-04-09 23:58:25 +02:00
|
|
|
const actor = ActivityPub.helpers.resolveActor(type, id);
|
2024-02-06 10:40:46 -05:00
|
|
|
|
2023-06-23 14:59:47 -04:00
|
|
|
payload = {
|
2023-12-13 13:15:03 -05:00
|
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
2024-02-06 10:40:46 -05:00
|
|
|
actor,
|
2023-06-23 14:59:47 -04:00
|
|
|
...payload,
|
|
|
|
|
};
|
|
|
|
|
|
2024-05-06 22:52:48 +02:00
|
|
|
await batch.processArray(
|
|
|
|
|
inboxes,
|
2024-05-06 23:06:06 +02:00
|
|
|
async inboxBatch => Promise.all(inboxBatch.map(async uri => sendMessage(uri, id, type, payload))),
|
|
|
|
|
{
|
|
|
|
|
batch: 50,
|
|
|
|
|
interval: 100,
|
|
|
|
|
},
|
2024-05-06 22:52:48 +02:00
|
|
|
);
|
2023-06-23 14:59:47 -04:00
|
|
|
};
|
2024-05-14 12:06:59 -04:00
|
|
|
|
|
|
|
|
ActivityPub.record = async ({ id, type, actor }) => {
|
|
|
|
|
const now = Date.now();
|
|
|
|
|
const { hostname } = new URL(actor);
|
|
|
|
|
|
|
|
|
|
await Promise.all([
|
|
|
|
|
db.sortedSetAdd(`activities:datetime`, now, id),
|
|
|
|
|
db.sortedSetAdd('domains:lastSeen', now, hostname),
|
|
|
|
|
analytics.increment(['activities', `activities:byType:${type}`, `activities:byHost:${hostname}`]),
|
|
|
|
|
]);
|
|
|
|
|
};
|