fix(syncedinstance): Prevent same-instance syncs and sanitize post update payloads; update tests and docs
This commit is contained in:
@@ -118,9 +118,34 @@ export class Post {
|
||||
return this.postData;
|
||||
}
|
||||
|
||||
public async update(postData: IPost): Promise<Post> {
|
||||
public async update(postData: Partial<IPost>): Promise<Post> {
|
||||
try {
|
||||
const updatedPostData = await this.ghostInstanceRef.adminApi.posts.edit(postData);
|
||||
// Only send fields that should be updated, not the entire post object with nested relations
|
||||
const updatePayload: any = {
|
||||
id: this.postData.id,
|
||||
updated_at: this.postData.updated_at, // Required for conflict detection
|
||||
...postData
|
||||
};
|
||||
|
||||
// Remove read-only or computed fields that shouldn't be sent
|
||||
delete updatePayload.uuid;
|
||||
delete updatePayload.comment_id;
|
||||
delete updatePayload.url;
|
||||
delete updatePayload.excerpt;
|
||||
delete updatePayload.reading_time;
|
||||
delete updatePayload.created_at; // Don't send created_at in updates
|
||||
delete updatePayload.primary_author;
|
||||
delete updatePayload.primary_tag;
|
||||
delete updatePayload.count;
|
||||
delete updatePayload.email;
|
||||
delete updatePayload.newsletter;
|
||||
|
||||
// Remove nested objects if they're not being updated
|
||||
if (!postData.authors) delete updatePayload.authors;
|
||||
if (!postData.tags) delete updatePayload.tags;
|
||||
if (!postData.tiers) delete updatePayload.tiers;
|
||||
|
||||
const updatedPostData = await this.ghostInstanceRef.adminApi.posts.edit(updatePayload);
|
||||
this.postData = updatedPostData;
|
||||
return this;
|
||||
} catch (error) {
|
||||
|
Reference in New Issue
Block a user