Files
indiekit-server/scripts/patch-inbox-ignore-view-activity.mjs
Sven 24a9fb8f6b fix(patches): restore PeerTube View patches and add fetch diagnostic
Re-add PeerTube View activity patches that were prematurely removed in
e52e98c5c — the upstream fork doesn't reliably include these fixes on
all server deployments, causing noisy "Unsupported activity type" errors.

Also add fetch diagnostic patch to surface the real cause of
"TypeError: fetch failed" when posting articles via the form controller.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-16 20:14:26 +01:00

114 lines
3.4 KiB
JavaScript

/**
* Patch: silently ignore PeerTube View (WatchAction) activities in the inbox.
*
* PeerTube broadcasts a non-standard ActivityStreams `View` activity to all
* followers whenever someone watches a video. Fedify has no built-in handler
* registered for this type, which causes a noisy
* "Unsupported activity type" error in the federation inbox log on every view.
*
* Fix: register a no-op `.on(View, ...)` handler at the end of the inbox
* listener chain so Fedify accepts and silently discards these activities
* instead of logging them as errors.
*/
import { access, readFile, writeFile } from "node:fs/promises";
const candidates = [
"node_modules/@rmdes/indiekit-endpoint-activitypub/lib/inbox-listeners.js",
"node_modules/@indiekit/indiekit/node_modules/@rmdes/indiekit-endpoint-activitypub/lib/inbox-listeners.js",
];
const patchSpecs = [
{
name: "inbox-ignore-view-activity-import",
marker: "// View imported",
oldSnippet: ` Undo,
Update,
} from "@fedify/fedify/vocab";`,
newSnippet: ` Undo,
Update,
View, // View imported
} from "@fedify/fedify/vocab";`,
},
{
name: "inbox-ignore-view-activity-handler",
marker: "// PeerTube View handler",
oldSnippet: ` console.info(\`[ActivityPub] Flag received from \${reporterName} — \${reportedIds.length} objects reported\`);
} catch (error) {
console.warn("[ActivityPub] Flag handler error:", error.message);
}
});
}`,
newSnippet: ` console.info(\`[ActivityPub] Flag received from \${reporterName} — \${reportedIds.length} objects reported\`);
} catch (error) {
console.warn("[ActivityPub] Flag handler error:", error.message);
}
})
// ── View (PeerTube watch) ─────────────────────────────────────────────
// PeerTube broadcasts View (WatchAction) activities to all followers
// whenever someone watches a video. Fedify has no built-in handler for
// this type, producing noisy "Unsupported activity type" log errors.
// Silently accept and discard. // PeerTube View handler
.on(View, async () => {});
}`,
},
];
async function exists(filePath) {
try {
await access(filePath);
return true;
} catch {
return false;
}
}
const checkedFiles = new Set();
const patchedFiles = new Set();
for (const spec of patchSpecs) {
let foundAnyTarget = false;
for (const filePath of candidates) {
if (!(await exists(filePath))) {
continue;
}
foundAnyTarget = true;
checkedFiles.add(filePath);
const source = await readFile(filePath, "utf8");
if (spec.marker && source.includes(spec.marker)) {
continue;
}
if (!source.includes(spec.oldSnippet)) {
continue;
}
const updated = source.replace(spec.oldSnippet, spec.newSnippet);
if (updated === source) {
continue;
}
await writeFile(filePath, updated, "utf8");
patchedFiles.add(filePath);
}
if (!foundAnyTarget) {
console.log(`[postinstall] ${spec.name}: no target files found`);
}
}
if (checkedFiles.size === 0) {
console.log("[postinstall] No inbox-listeners files found for View activity patch");
} else if (patchedFiles.size === 0) {
console.log("[postinstall] inbox-ignore-view-activity patches already applied");
} else {
console.log(
`[postinstall] Patched inbox-ignore-view-activity in ${patchedFiles.size}/${checkedFiles.size} file(s)`,
);
}