mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 01:41:46 +03:00
d23b7525a4
closes https://github.com/TryGhost/Team/issues/1647 - sending the embedded `email` record back to the API when saving could trigger "Request entity too large" errors for very large posts that were sent as email because it doubles up on the request size - `post.email` is a read-only property and is ignored by the API so there's no point serializing it and making request bodies larger than they need to be
50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
/* eslint-disable camelcase */
|
|
import ApplicationSerializer from 'ghost-admin/serializers/application';
|
|
import {EmbeddedRecordsMixin} from '@ember-data/serializer/rest';
|
|
|
|
export default class PostSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {
|
|
// settings for the EmbeddedRecordsMixin.
|
|
attrs = {
|
|
authors: {embedded: 'always'},
|
|
tags: {embedded: 'always'},
|
|
publishedAtUTC: {key: 'published_at'},
|
|
createdAtUTC: {key: 'created_at'},
|
|
updatedAtUTC: {key: 'updated_at'},
|
|
email: {embedded: 'always'},
|
|
newsletter: {embedded: 'always'}
|
|
};
|
|
|
|
serialize(/*snapshot, options*/) {
|
|
let json = super.serialize(...arguments);
|
|
|
|
// Inserted locally as a convenience.
|
|
delete json.author_id;
|
|
// Read-only virtual properties
|
|
delete json.uuid;
|
|
delete json.url;
|
|
delete json.send_email_when_published;
|
|
delete json.email_recipient_filter;
|
|
delete json.email;
|
|
delete json.newsletter;
|
|
// Deprecated property (replaced with data.authors)
|
|
delete json.author;
|
|
|
|
if (json.visibility === null) {
|
|
delete json.visibility;
|
|
delete json.visibility_filter;
|
|
delete json.tiers;
|
|
}
|
|
|
|
if (json.visibility === 'tiers') {
|
|
delete json.visibility_filter;
|
|
}
|
|
|
|
if (json.visibility === 'tiers' && !json.tiers?.length) {
|
|
delete json.visibility;
|
|
delete json.tiers;
|
|
}
|
|
|
|
return json;
|
|
}
|
|
}
|