fix(patches): update federation-diag silence patch for new fork version

The fork added an Accept-header upgrade block between the diagnostic
log and the return statement, breaking the OLD_SNIPPET match. Patch
now handles both the original form and the updated form.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Sven
2026-03-22 17:26:12 +01:00
parent 49e8a109c8
commit 4b1dfa20be
2 changed files with 363 additions and 285 deletions

View File

@@ -14,7 +14,8 @@ const candidates = [
const MARKER = "// ap-remove-federation-diag patch";
const OLD_SNIPPET = ` // Diagnostic: log inbox POSTs to detect federation stalls
// Matches the original form (diag block immediately before the return)
const OLD_SNIPPET_V1 = ` // Diagnostic: log inbox POSTs to detect federation stalls
if (req.method === "POST" && req.path.includes("inbox")) {
const ua = req.get("user-agent") || "unknown";
const bodyParsed = req.body !== undefined && Object.keys(req.body || {}).length > 0;
@@ -23,9 +24,23 @@ const OLD_SNIPPET = ` // Diagnostic: log inbox POSTs to detect federation s
return self._fedifyMiddleware(req, res, next);`;
const NEW_SNIPPET = ` // ap-remove-federation-diag patch
const NEW_SNIPPET_V1 = ` // ap-remove-federation-diag patch
return self._fedifyMiddleware(req, res, next);`;
// Matches the updated form (diag block followed by Accept-upgrade block before the return)
const OLD_SNIPPET_V2 = ` // Diagnostic: log inbox POSTs to detect federation stalls
if (req.method === "POST" && req.path.includes("inbox")) {
const ua = req.get("user-agent") || "unknown";
const bodyParsed = req.body !== undefined && Object.keys(req.body || {}).length > 0;
console.info(\`[federation-diag] POST \${req.path} from=\${ua.slice(0, 60)} bodyParsed=\${bodyParsed} readable=\${req.readable}\`);
}
// Fedify's`;
const NEW_SNIPPET_V2 = ` // ap-remove-federation-diag patch
// Fedify's`;
async function exists(filePath) {
try {
await access(filePath);
@@ -50,12 +65,19 @@ for (const filePath of candidates) {
continue; // already patched
}
if (!source.includes(OLD_SNIPPET)) {
let matched = false;
if (source.includes(OLD_SNIPPET_V1)) {
source = source.replace(OLD_SNIPPET_V1, NEW_SNIPPET_V1);
matched = true;
} else if (source.includes(OLD_SNIPPET_V2)) {
source = source.replace(OLD_SNIPPET_V2, NEW_SNIPPET_V2);
matched = true;
}
if (!matched) {
console.log(`[postinstall] patch-ap-remove-federation-diag: snippet not found in ${filePath}`);
continue;
}
source = source.replace(OLD_SNIPPET, NEW_SNIPPET);
await writeFile(filePath, source, "utf8");
patched += 1;
console.log(`[postinstall] Applied patch-ap-remove-federation-diag to ${filePath}`);