chore: integrate AP patches into fork — remove 3 scripts, trim federation-unlisted-guards
Deleted scripts (logic now built into the fork): - patch-endpoint-activitypub-docloader-loglevel.mjs - patch-endpoint-activitypub-migrate-alias-clear.mjs - patch-endpoint-activitypub-like-boost-methods.mjs Trimmed patch-federation-unlisted-guards.mjs to only cover endpoint-syndicate (separate package). AP unlisted guards are now in the fork's federation-setup.js. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,80 +0,0 @@
|
||||
import { access, readFile, writeFile } from "node:fs/promises";
|
||||
|
||||
const candidates = [
|
||||
"node_modules/@rmdes/indiekit-endpoint-activitypub/lib/federation-setup.js",
|
||||
"node_modules/@indiekit/indiekit/node_modules/@rmdes/indiekit-endpoint-activitypub/lib/federation-setup.js",
|
||||
];
|
||||
|
||||
const oldSnippet = ` loggers: [
|
||||
{
|
||||
// All Fedify logs — federation, vocab, delivery, HTTP signatures
|
||||
category: ["fedify"],
|
||||
sinks: ["console"],
|
||||
lowestLevel: resolvedLevel,
|
||||
},
|
||||
],`;
|
||||
|
||||
const newSnippet = ` loggers: [
|
||||
{
|
||||
// Noise guard: remote deleted actors often return 404/410 on fetch.
|
||||
// Keep only fatal events for the docloader category.
|
||||
category: ["fedify", "runtime", "docloader"],
|
||||
sinks: ["console"],
|
||||
lowestLevel: "fatal",
|
||||
},
|
||||
{
|
||||
// All remaining Fedify logs - federation, vocab, delivery, signatures.
|
||||
category: ["fedify"],
|
||||
sinks: ["console"],
|
||||
lowestLevel: resolvedLevel,
|
||||
},
|
||||
],`;
|
||||
|
||||
async function exists(filePath) {
|
||||
try {
|
||||
await access(filePath);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
let filesChecked = 0;
|
||||
let filesPatched = 0;
|
||||
|
||||
for (const filePath of candidates) {
|
||||
if (!(await exists(filePath))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
filesChecked += 1;
|
||||
|
||||
const source = await readFile(filePath, "utf8");
|
||||
|
||||
if (source.includes(newSnippet)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!source.includes(oldSnippet)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const updated = source.replace(oldSnippet, newSnippet);
|
||||
|
||||
if (updated === source) {
|
||||
continue;
|
||||
}
|
||||
|
||||
await writeFile(filePath, updated, "utf8");
|
||||
filesPatched += 1;
|
||||
}
|
||||
|
||||
if (filesChecked === 0) {
|
||||
console.log("[postinstall] No activitypub federation setup files found");
|
||||
} else if (filesPatched === 0) {
|
||||
console.log("[postinstall] activitypub docloader loglevel patch already applied");
|
||||
} else {
|
||||
console.log(
|
||||
`[postinstall] Patched activitypub docloader loglevel in ${filesPatched}/${filesChecked} file(s)`,
|
||||
);
|
||||
}
|
||||
@@ -1,226 +0,0 @@
|
||||
import { access, readFile, writeFile } from "node:fs/promises";
|
||||
|
||||
const patchSpecs = [
|
||||
{
|
||||
name: "activitypub-resolveAuthor-import",
|
||||
candidates: [
|
||||
"node_modules/@rmdes/indiekit-endpoint-activitypub/index.js",
|
||||
"node_modules/@indiekit/indiekit/node_modules/@rmdes/indiekit-endpoint-activitypub/index.js",
|
||||
],
|
||||
replacements: [
|
||||
{
|
||||
oldSnippet: [
|
||||
"import { startBatchRefollow } from \"./lib/batch-refollow.js\";",
|
||||
"import { logActivity } from \"./lib/activity-log.js\";",
|
||||
"import { scheduleCleanup } from \"./lib/timeline-cleanup.js\";",
|
||||
].join("\n"),
|
||||
newSnippet: [
|
||||
"import { startBatchRefollow } from \"./lib/batch-refollow.js\";",
|
||||
"import { logActivity } from \"./lib/activity-log.js\";",
|
||||
"import { resolveAuthor } from \"./lib/resolve-author.js\";",
|
||||
"import { scheduleCleanup } from \"./lib/timeline-cleanup.js\";",
|
||||
].join("\n"),
|
||||
},
|
||||
{
|
||||
oldSnippet: [
|
||||
" await this._collections.ap_following.deleteOne({ actorUrl }).catch(() => {});",
|
||||
" return { ok: false, error: error.message };",
|
||||
" }",
|
||||
" }",
|
||||
"",
|
||||
" /**",
|
||||
" * Send an Update(Person) activity to all followers so remote servers",
|
||||
].join("\n"),
|
||||
newSnippet: [
|
||||
" await this._collections.ap_following.deleteOne({ actorUrl }).catch(() => {});",
|
||||
" return { ok: false, error: error.message };",
|
||||
" }",
|
||||
" }",
|
||||
"",
|
||||
" /**",
|
||||
" * Send a native AP Like activity for a post URL (called programmatically,",
|
||||
" * e.g. when a like is created via Micropub).",
|
||||
" * @param {string} postUrl - URL of the post being liked",
|
||||
" * @param {object} [collections] - MongoDB collections map (application.collections)",
|
||||
" * @returns {Promise<{ok: boolean, error?: string}>}",
|
||||
" */",
|
||||
" async likePost(postUrl, collections) {",
|
||||
" if (!this._federation) {",
|
||||
" return { ok: false, error: \"Federation not initialized\" };",
|
||||
" }",
|
||||
"",
|
||||
" try {",
|
||||
" const { Like } = await import(\"@fedify/fedify/vocab\");",
|
||||
" const handle = this.options.actor.handle;",
|
||||
" const ctx = this._federation.createContext(",
|
||||
" new URL(this._publicationUrl),",
|
||||
" { handle, publicationUrl: this._publicationUrl },",
|
||||
" );",
|
||||
" const documentLoader = await ctx.getDocumentLoader({ identifier: handle });",
|
||||
" const cols = collections || this._collections;",
|
||||
"",
|
||||
" const recipient = await resolveAuthor(postUrl, ctx, documentLoader, cols);",
|
||||
" if (!recipient) {",
|
||||
" return { ok: false, error: `Could not resolve post author for ${postUrl}` };",
|
||||
" }",
|
||||
"",
|
||||
" const uuid = crypto.randomUUID();",
|
||||
" const activityId = `${this._publicationUrl.replace(/\\/$/, \"\")}/activitypub/likes/${uuid}`;",
|
||||
"",
|
||||
" const like = new Like({",
|
||||
" id: new URL(activityId),",
|
||||
" actor: ctx.getActorUri(handle),",
|
||||
" object: new URL(postUrl),",
|
||||
" });",
|
||||
"",
|
||||
" await ctx.sendActivity({ identifier: handle }, recipient, like, {",
|
||||
" orderingKey: postUrl,",
|
||||
" });",
|
||||
"",
|
||||
" const interactions = cols?.get?.(\"ap_interactions\") || this._collections.ap_interactions;",
|
||||
" if (interactions) {",
|
||||
" await interactions.updateOne(",
|
||||
" { objectUrl: postUrl, type: \"like\" },",
|
||||
" { $set: { objectUrl: postUrl, type: \"like\", activityId, recipientUrl: recipient.id?.href || \"\", createdAt: new Date().toISOString() } },",
|
||||
" { upsert: true },",
|
||||
" );",
|
||||
" }",
|
||||
"",
|
||||
" console.info(`[ActivityPub] Sent Like for ${postUrl}`);",
|
||||
" return { ok: true };",
|
||||
" } catch (error) {",
|
||||
" console.error(`[ActivityPub] likePost failed for ${postUrl}:`, error.message);",
|
||||
" return { ok: false, error: error.message };",
|
||||
" }",
|
||||
" }",
|
||||
"",
|
||||
" /**",
|
||||
" * Send a native AP Announce (boost) activity for a post URL (called",
|
||||
" * programmatically, e.g. when a repost is created via Micropub).",
|
||||
" * @param {string} postUrl - URL of the post being boosted",
|
||||
" * @param {object} [collections] - MongoDB collections map (application.collections)",
|
||||
" * @returns {Promise<{ok: boolean, error?: string}>}",
|
||||
" */",
|
||||
" async boostPost(postUrl, collections) {",
|
||||
" if (!this._federation) {",
|
||||
" return { ok: false, error: \"Federation not initialized\" };",
|
||||
" }",
|
||||
"",
|
||||
" try {",
|
||||
" const { Announce } = await import(\"@fedify/fedify/vocab\");",
|
||||
" const handle = this.options.actor.handle;",
|
||||
" const ctx = this._federation.createContext(",
|
||||
" new URL(this._publicationUrl),",
|
||||
" { handle, publicationUrl: this._publicationUrl },",
|
||||
" );",
|
||||
" const documentLoader = await ctx.getDocumentLoader({ identifier: handle });",
|
||||
" const cols = collections || this._collections;",
|
||||
"",
|
||||
" const uuid = crypto.randomUUID();",
|
||||
" const activityId = `${this._publicationUrl.replace(/\\/$/, \"\")}/activitypub/boosts/${uuid}`;",
|
||||
" const publicAddress = new URL(\"https://www.w3.org/ns/activitystreams#Public\");",
|
||||
" const followersUri = ctx.getFollowersUri(handle);",
|
||||
"",
|
||||
" const announce = new Announce({",
|
||||
" id: new URL(activityId),",
|
||||
" actor: ctx.getActorUri(handle),",
|
||||
" object: new URL(postUrl),",
|
||||
" to: publicAddress,",
|
||||
" cc: followersUri,",
|
||||
" });",
|
||||
"",
|
||||
" // Broadcast to followers",
|
||||
" await ctx.sendActivity({ identifier: handle }, \"followers\", announce, {",
|
||||
" preferSharedInbox: true,",
|
||||
" syncCollection: true,",
|
||||
" orderingKey: postUrl,",
|
||||
" });",
|
||||
"",
|
||||
" // Also deliver directly to original post author",
|
||||
" const recipient = await resolveAuthor(postUrl, ctx, documentLoader, cols);",
|
||||
" if (recipient) {",
|
||||
" await ctx.sendActivity({ identifier: handle }, recipient, announce, {",
|
||||
" orderingKey: postUrl,",
|
||||
" }).catch((err) => {",
|
||||
" console.warn(`[ActivityPub] Direct boost delivery to author failed: ${err.message}`);",
|
||||
" });",
|
||||
" }",
|
||||
"",
|
||||
" const interactions = cols?.get?.(\"ap_interactions\") || this._collections.ap_interactions;",
|
||||
" if (interactions) {",
|
||||
" await interactions.updateOne(",
|
||||
" { objectUrl: postUrl, type: \"boost\" },",
|
||||
" { $set: { objectUrl: postUrl, type: \"boost\", activityId, createdAt: new Date().toISOString() } },",
|
||||
" { upsert: true },",
|
||||
" );",
|
||||
" }",
|
||||
"",
|
||||
" console.info(`[ActivityPub] Sent Announce (boost) for ${postUrl}`);",
|
||||
" return { ok: true };",
|
||||
" } catch (error) {",
|
||||
" console.error(`[ActivityPub] boostPost failed for ${postUrl}:`, error.message);",
|
||||
" return { ok: false, error: error.message };",
|
||||
" }",
|
||||
" }",
|
||||
"",
|
||||
" /**",
|
||||
" * Send an Update(Person) activity to all followers so remote servers",
|
||||
].join("\n"),
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
async function exists(filePath) {
|
||||
try {
|
||||
await access(filePath);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
let filesChecked = 0;
|
||||
let filesPatched = 0;
|
||||
|
||||
for (const patchSpec of patchSpecs) {
|
||||
for (const filePath of patchSpec.candidates) {
|
||||
if (!(await exists(filePath))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
filesChecked += 1;
|
||||
|
||||
const source = await readFile(filePath, "utf8");
|
||||
let updated = source;
|
||||
|
||||
for (const replacement of patchSpec.replacements) {
|
||||
if (updated.includes(replacement.newSnippet)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!updated.includes(replacement.oldSnippet)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
updated = updated.replace(replacement.oldSnippet, replacement.newSnippet);
|
||||
}
|
||||
|
||||
if (updated === source) {
|
||||
continue;
|
||||
}
|
||||
|
||||
await writeFile(filePath, updated, "utf8");
|
||||
filesPatched += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (filesChecked === 0) {
|
||||
console.log("[postinstall] No activitypub like/boost patch targets found");
|
||||
} else if (filesPatched === 0) {
|
||||
console.log("[postinstall] activitypub like/boost methods patch already applied");
|
||||
} else {
|
||||
console.log(
|
||||
`[postinstall] Patched activitypub likePost/boostPost methods in ${filesPatched}/${filesChecked} file(s)`,
|
||||
);
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
import { access, readFile, writeFile } from "node:fs/promises";
|
||||
|
||||
const patchSpecs = [
|
||||
{
|
||||
name: "activitypub-migrate-alias-clear",
|
||||
marker: "allow clearing alsoKnownAs alias by submitting empty value",
|
||||
oldSnippet: ` const aliasUrl = request.body.aliasUrl?.trim();
|
||||
if (aliasUrl && profileCollection) {
|
||||
await profileCollection.updateOne(
|
||||
{},
|
||||
{ $set: { alsoKnownAs: [aliasUrl] } },
|
||||
{ upsert: true },
|
||||
);
|
||||
result = {
|
||||
type: "success",
|
||||
text: response.locals.__("activitypub.migrate.aliasSuccess"),
|
||||
};
|
||||
}`,
|
||||
newSnippet: ` const aliasUrl = request.body.aliasUrl?.trim();
|
||||
const submittedAliasField = Object.prototype.hasOwnProperty.call(
|
||||
request.body || {},
|
||||
"aliasUrl",
|
||||
);
|
||||
|
||||
// allow clearing alsoKnownAs alias by submitting empty value
|
||||
if (profileCollection && submittedAliasField) {
|
||||
if (aliasUrl) {
|
||||
await profileCollection.updateOne(
|
||||
{},
|
||||
{ $set: { alsoKnownAs: [aliasUrl] } },
|
||||
{ upsert: true },
|
||||
);
|
||||
result = {
|
||||
type: "success",
|
||||
text: response.locals.__("activitypub.migrate.aliasSuccess"),
|
||||
};
|
||||
} else {
|
||||
await profileCollection.updateOne(
|
||||
{},
|
||||
{ $set: { alsoKnownAs: [] } },
|
||||
{ upsert: true },
|
||||
);
|
||||
result = {
|
||||
type: "success",
|
||||
text: "Alias removed - alsoKnownAs is now empty.",
|
||||
};
|
||||
}
|
||||
}`,
|
||||
candidates: [
|
||||
"node_modules/@rmdes/indiekit-endpoint-activitypub/lib/controllers/migrate.js",
|
||||
"node_modules/@indiekit/indiekit/node_modules/@rmdes/indiekit-endpoint-activitypub/lib/controllers/migrate.js",
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
async function exists(filePath) {
|
||||
try {
|
||||
await access(filePath);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
let filesChecked = 0;
|
||||
let filesPatched = 0;
|
||||
|
||||
for (const spec of patchSpecs) {
|
||||
let foundAnyTarget = false;
|
||||
|
||||
for (const filePath of spec.candidates) {
|
||||
if (!(await exists(filePath))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foundAnyTarget = true;
|
||||
filesChecked += 1;
|
||||
|
||||
const source = await readFile(filePath, "utf8");
|
||||
|
||||
if (source.includes(spec.marker)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!source.includes(spec.oldSnippet)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const updated = source.replace(spec.oldSnippet, spec.newSnippet);
|
||||
await writeFile(filePath, updated, "utf8");
|
||||
filesPatched += 1;
|
||||
}
|
||||
|
||||
if (!foundAnyTarget) {
|
||||
console.log(`[postinstall] ${spec.name}: no target files found`);
|
||||
}
|
||||
}
|
||||
|
||||
if (filesChecked === 0) {
|
||||
console.log("[postinstall] No activitypub migrate alias files found");
|
||||
} else if (filesPatched === 0) {
|
||||
console.log("[postinstall] activitypub migrate alias clear already patched");
|
||||
} else {
|
||||
console.log(
|
||||
`[postinstall] Patched activitypub migrate alias clear in ${filesPatched}/${filesChecked} file(s)`,
|
||||
);
|
||||
}
|
||||
@@ -1,20 +1,13 @@
|
||||
import { access, readFile, writeFile } from "node:fs/promises";
|
||||
|
||||
// activitypub index.js and federation-setup.js unlisted guards are now
|
||||
// built into the fork — only endpoint-syndicate (separate package) needs patching.
|
||||
|
||||
const endpointSyndicateCandidates = [
|
||||
"node_modules/@indiekit/endpoint-syndicate/lib/utils.js",
|
||||
"node_modules/@indiekit/indiekit/node_modules/@indiekit/endpoint-syndicate/lib/utils.js",
|
||||
];
|
||||
|
||||
const activityPubIndexCandidates = [
|
||||
"node_modules/@rmdes/indiekit-endpoint-activitypub/index.js",
|
||||
"node_modules/@indiekit/indiekit/node_modules/@rmdes/indiekit-endpoint-activitypub/index.js",
|
||||
];
|
||||
|
||||
const activityPubFederationSetupCandidates = [
|
||||
"node_modules/@rmdes/indiekit-endpoint-activitypub/lib/federation-setup.js",
|
||||
"node_modules/@indiekit/indiekit/node_modules/@rmdes/indiekit-endpoint-activitypub/lib/federation-setup.js",
|
||||
];
|
||||
|
||||
const patchSpecs = [
|
||||
{
|
||||
name: "endpoint-syndicate-source-url-unlisted-guard",
|
||||
@@ -65,89 +58,6 @@ const patchSpecs = [
|
||||
},
|
||||
})`,
|
||||
},
|
||||
{
|
||||
name: "activitypub-syndicator-unlisted-guard",
|
||||
candidates: activityPubIndexCandidates,
|
||||
oldSnippet: ` async syndicate(properties) {
|
||||
if (!self._federation) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
try {`,
|
||||
newSnippet: ` async syndicate(properties) {
|
||||
if (!self._federation) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const visibility = String(properties?.visibility || "").toLowerCase();
|
||||
if (visibility === "unlisted") {
|
||||
console.info(
|
||||
"[ActivityPub] Skipping federation for unlisted post: " +
|
||||
(properties?.url || "unknown"),
|
||||
);
|
||||
await logActivity(self._collections.ap_activities, {
|
||||
direction: "outbound",
|
||||
type: "Syndicate",
|
||||
actorUrl: self._publicationUrl,
|
||||
objectUrl: properties?.url,
|
||||
summary: "Syndication skipped: post visibility is unlisted",
|
||||
}).catch(() => {});
|
||||
return undefined;
|
||||
}
|
||||
|
||||
try {`,
|
||||
},
|
||||
{
|
||||
name: "activitypub-outbox-unlisted-guard",
|
||||
candidates: activityPubFederationSetupCandidates,
|
||||
oldSnippet: ` const pageSize = 20;
|
||||
const skip = cursor ? Number.parseInt(cursor, 10) : 0;
|
||||
const total = await postsCollection.countDocuments();
|
||||
|
||||
const posts = await postsCollection
|
||||
.find()`,
|
||||
newSnippet: ` const pageSize = 20;
|
||||
const skip = cursor ? Number.parseInt(cursor, 10) : 0;
|
||||
const federationVisibilityQuery = {
|
||||
"properties.post-status": { $ne: "draft" },
|
||||
"properties.visibility": { $ne: "unlisted" },
|
||||
};
|
||||
const total = await postsCollection.countDocuments(
|
||||
federationVisibilityQuery,
|
||||
);
|
||||
|
||||
const posts = await postsCollection
|
||||
.find(federationVisibilityQuery)`,
|
||||
},
|
||||
{
|
||||
name: "activitypub-outbox-counter-unlisted-guard",
|
||||
candidates: activityPubFederationSetupCandidates,
|
||||
oldSnippet: ` .setCounter(async (ctx, identifier) => {
|
||||
if (identifier !== handle) return 0;
|
||||
const postsCollection = collections.posts;
|
||||
if (!postsCollection) return 0;
|
||||
return await postsCollection.countDocuments();
|
||||
})`,
|
||||
newSnippet: ` .setCounter(async (ctx, identifier) => {
|
||||
if (identifier !== handle) return 0;
|
||||
const postsCollection = collections.posts;
|
||||
if (!postsCollection) return 0;
|
||||
return await postsCollection.countDocuments({
|
||||
"properties.post-status": { $ne: "draft" },
|
||||
"properties.visibility": { $ne: "unlisted" },
|
||||
});
|
||||
})`,
|
||||
},
|
||||
{
|
||||
name: "activitypub-object-dispatch-unlisted-guard",
|
||||
candidates: activityPubFederationSetupCandidates,
|
||||
oldSnippet: ` const post = await collections.posts.findOne({ "properties.url": postUrl });
|
||||
if (!post) return null;`,
|
||||
newSnippet: ` const post = await collections.posts.findOne({ "properties.url": postUrl });
|
||||
if (!post) return null;
|
||||
if (post?.properties?.["post-status"] === "draft") return null;
|
||||
if (post?.properties?.visibility === "unlisted") return null;`,
|
||||
},
|
||||
];
|
||||
|
||||
async function exists(filePath) {
|
||||
|
||||
Reference in New Issue
Block a user