fix(syncedinstance): Prevent same-instance syncs and sanitize post update payloads; update tests and docs

This commit is contained in:
2025-10-11 06:16:44 +00:00
parent 00dd0c69a5
commit 2bb86552e2
9 changed files with 582 additions and 49 deletions

View File

@@ -50,6 +50,20 @@ export class SyncedInstance {
private syncHistory: ISyncReport[];
constructor(sourceGhost: Ghost, targetGhosts: Ghost[]) {
// Validate that no target instance is the same as the source instance
const sourceUrl = sourceGhost.options.baseUrl.replace(/\/$/, '').toLowerCase();
for (const targetGhost of targetGhosts) {
const targetUrl = targetGhost.options.baseUrl.replace(/\/$/, '').toLowerCase();
if (sourceUrl === targetUrl) {
throw new Error(
`Cannot sync to the same instance. Source and target both point to: ${sourceUrl}. ` +
`This would create a circular sync and cause excessive API calls.`
);
}
}
this.sourceGhost = sourceGhost;
this.targetGhosts = targetGhosts;
this.syncMappings = new Map();
@@ -125,6 +139,7 @@ export class SyncedInstance {
if (!optionsArg?.dryRun) {
await targetTag.update({
name: sourceTag.name,
slug: sourceTag.slug,
description: sourceTag.description,
feature_image: sourceTag.feature_image,
visibility: sourceTag.visibility,