Allow clearing Mastodon migration alias
This commit is contained in:
+2
-2
@@ -4,8 +4,8 @@
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"postinstall": "node scripts/patch-lightningcss.mjs && node scripts/patch-endpoint-media-scope.mjs && node scripts/patch-endpoint-media-sharp-runtime.mjs && node scripts/patch-frontend-sharp-runtime.mjs && node scripts/patch-endpoint-files-upload-route.mjs && node scripts/patch-endpoint-files-upload-locales.mjs && node scripts/patch-endpoint-activitypub-locales.mjs && node scripts/patch-endpoint-activitypub-docloader-loglevel.mjs && node scripts/patch-endpoint-homepage-locales.mjs && node scripts/patch-federation-unlisted-guards.mjs && node scripts/patch-endpoint-micropub-where-note-visibility.mjs && node scripts/patch-endpoint-posts-ai-fields.mjs && node scripts/patch-endpoint-podroll-opml-upload.mjs && node scripts/patch-preset-eleventy-ai-frontmatter.mjs && node scripts/patch-frontend-serviceworker-file.mjs && node scripts/patch-conversations-collection-guards.mjs && node scripts/patch-conversations-mastodon-disconnect.mjs && node scripts/patch-indiekit-routes-rate-limits.mjs && node scripts/patch-indiekit-error-production-stack.mjs && node scripts/patch-indieauth-devmode-guard.mjs && node scripts/patch-listening-endpoint-runtime-guards.mjs",
|
||||
"serve": "export NODE_ENV=${NODE_ENV:-production} INDIEKIT_DEBUG=${INDIEKIT_DEBUG:-0} && node scripts/preflight-production-security.mjs && node scripts/preflight-mongo-connection.mjs && node scripts/preflight-activitypub-rsa-key.mjs && node scripts/preflight-activitypub-profile-urls.mjs && node scripts/patch-lightningcss.mjs && node scripts/patch-endpoint-media-scope.mjs && node scripts/patch-endpoint-media-sharp-runtime.mjs && node scripts/patch-frontend-sharp-runtime.mjs && node scripts/patch-endpoint-files-upload-route.mjs && node scripts/patch-endpoint-files-upload-locales.mjs && node scripts/patch-endpoint-activitypub-locales.mjs && node scripts/patch-endpoint-activitypub-docloader-loglevel.mjs && node scripts/patch-endpoint-homepage-locales.mjs && node scripts/patch-federation-unlisted-guards.mjs && node scripts/patch-endpoint-micropub-where-note-visibility.mjs && node scripts/patch-endpoint-posts-ai-fields.mjs && node scripts/patch-endpoint-podroll-opml-upload.mjs && node scripts/patch-preset-eleventy-ai-frontmatter.mjs && node scripts/patch-frontend-serviceworker-file.mjs && node scripts/patch-conversations-collection-guards.mjs && node scripts/patch-conversations-mastodon-disconnect.mjs && node scripts/patch-indiekit-routes-rate-limits.mjs && node scripts/patch-indiekit-error-production-stack.mjs && node scripts/patch-indieauth-devmode-guard.mjs && node scripts/patch-listening-endpoint-runtime-guards.mjs && node node_modules/@indiekit/indiekit/bin/cli.js serve --config indiekit.config.mjs",
|
||||
"postinstall": "node scripts/patch-lightningcss.mjs && node scripts/patch-endpoint-media-scope.mjs && node scripts/patch-endpoint-media-sharp-runtime.mjs && node scripts/patch-frontend-sharp-runtime.mjs && node scripts/patch-endpoint-files-upload-route.mjs && node scripts/patch-endpoint-files-upload-locales.mjs && node scripts/patch-endpoint-activitypub-locales.mjs && node scripts/patch-endpoint-activitypub-docloader-loglevel.mjs && node scripts/patch-endpoint-activitypub-migrate-alias-clear.mjs && node scripts/patch-endpoint-homepage-locales.mjs && node scripts/patch-federation-unlisted-guards.mjs && node scripts/patch-endpoint-micropub-where-note-visibility.mjs && node scripts/patch-endpoint-posts-ai-fields.mjs && node scripts/patch-endpoint-podroll-opml-upload.mjs && node scripts/patch-preset-eleventy-ai-frontmatter.mjs && node scripts/patch-frontend-serviceworker-file.mjs && node scripts/patch-conversations-collection-guards.mjs && node scripts/patch-conversations-mastodon-disconnect.mjs && node scripts/patch-indiekit-routes-rate-limits.mjs && node scripts/patch-indiekit-error-production-stack.mjs && node scripts/patch-indieauth-devmode-guard.mjs && node scripts/patch-listening-endpoint-runtime-guards.mjs",
|
||||
"serve": "export NODE_ENV=${NODE_ENV:-production} INDIEKIT_DEBUG=${INDIEKIT_DEBUG:-0} && node scripts/preflight-production-security.mjs && node scripts/preflight-mongo-connection.mjs && node scripts/preflight-activitypub-rsa-key.mjs && node scripts/preflight-activitypub-profile-urls.mjs && node scripts/patch-lightningcss.mjs && node scripts/patch-endpoint-media-scope.mjs && node scripts/patch-endpoint-media-sharp-runtime.mjs && node scripts/patch-frontend-sharp-runtime.mjs && node scripts/patch-endpoint-files-upload-route.mjs && node scripts/patch-endpoint-files-upload-locales.mjs && node scripts/patch-endpoint-activitypub-locales.mjs && node scripts/patch-endpoint-activitypub-docloader-loglevel.mjs && node scripts/patch-endpoint-activitypub-migrate-alias-clear.mjs && node scripts/patch-endpoint-homepage-locales.mjs && node scripts/patch-federation-unlisted-guards.mjs && node scripts/patch-endpoint-micropub-where-note-visibility.mjs && node scripts/patch-endpoint-posts-ai-fields.mjs && node scripts/patch-endpoint-podroll-opml-upload.mjs && node scripts/patch-preset-eleventy-ai-frontmatter.mjs && node scripts/patch-frontend-serviceworker-file.mjs && node scripts/patch-conversations-collection-guards.mjs && node scripts/patch-conversations-mastodon-disconnect.mjs && node scripts/patch-indiekit-routes-rate-limits.mjs && node scripts/patch-indiekit-error-production-stack.mjs && node scripts/patch-indieauth-devmode-guard.mjs && node scripts/patch-listening-endpoint-runtime-guards.mjs && node node_modules/@indiekit/indiekit/bin/cli.js serve --config indiekit.config.mjs",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
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)`,
|
||||
);
|
||||
}
|
||||
@@ -60,6 +60,7 @@ unset DEBUG
|
||||
/usr/local/bin/node scripts/patch-endpoint-files-upload-locales.mjs
|
||||
/usr/local/bin/node scripts/patch-endpoint-activitypub-locales.mjs
|
||||
/usr/local/bin/node scripts/patch-endpoint-activitypub-docloader-loglevel.mjs
|
||||
/usr/local/bin/node scripts/patch-endpoint-activitypub-migrate-alias-clear.mjs
|
||||
/usr/local/bin/node scripts/patch-endpoint-homepage-locales.mjs
|
||||
/usr/local/bin/node scripts/patch-frontend-serviceworker-file.mjs
|
||||
/usr/local/bin/node scripts/patch-conversations-collection-guards.mjs
|
||||
|
||||
Reference in New Issue
Block a user