fix(syncedinstance): Prevent same-instance syncs and sanitize post update payloads; update tests and docs
This commit is contained in:
@@ -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,
|
||||
|
Reference in New Issue
Block a user