mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-19 00:11:49 +03:00
06262ecf33
refs @TryGhost/Team#3076 - added `save_revision` option to edit post endpoint - this change covers the following cases: 1. we will not save a `post_revision` on every background autosave that occurs after 3 seconds of inactivity in the editor 2. we will save a `post_revision` when the user hits `cmd+s` in the editor to explicitly save 3. we will save a `post_revision` when the user navigates away from the editor (e.g. by clicking the 'Posts' breadcrumb in the editor) 4. we will save a `post_revision` when the user publishes a post 5. we will save a `post_revision` when a user updates an already published post
54 lines
1.8 KiB
JavaScript
54 lines
1.8 KiB
JavaScript
import ApplicationAdapter from 'ghost-admin/adapters/application';
|
|
|
|
export default class Post extends ApplicationAdapter {
|
|
buildIncludeURL(store, modelName, id, snapshot, requestType, query) {
|
|
const url = this.buildURL(modelName, id, snapshot, requestType, query);
|
|
const parsedUrl = new URL(url);
|
|
|
|
if (snapshot?.adapterOptions?.newsletter) {
|
|
const newsletter = snapshot.adapterOptions.newsletter;
|
|
parsedUrl.searchParams.append('newsletter', newsletter);
|
|
|
|
let emailSegment = snapshot?.adapterOptions?.emailSegment;
|
|
|
|
if (emailSegment) {
|
|
if (emailSegment === 'status:free,status:-free') {
|
|
emailSegment = 'all';
|
|
}
|
|
|
|
parsedUrl.searchParams.append('email_segment', emailSegment);
|
|
}
|
|
}
|
|
|
|
if (snapshot?.adapterOptions?.saveRevision) {
|
|
const saveRevision = snapshot.adapterOptions.saveRevision;
|
|
parsedUrl.searchParams.append('save_revision', saveRevision);
|
|
}
|
|
return parsedUrl.toString();
|
|
}
|
|
|
|
buildURL() {
|
|
const url = super.buildURL(...arguments);
|
|
|
|
try {
|
|
const parsedUrl = new URL(url);
|
|
if (!parsedUrl.searchParams.get('formats')) {
|
|
parsedUrl.searchParams.set('formats', 'mobiledoc,lexical');
|
|
return parsedUrl.href;
|
|
}
|
|
} catch (e) {
|
|
// noop, just use the original url
|
|
console.error('Couldn\'t parse URL', e); // eslint-disable-line
|
|
}
|
|
|
|
return url;
|
|
}
|
|
|
|
// posts and pages now include all relations by default so we don't want
|
|
// EmbeddedRelationAdapter.buildQuery adding an `?include=` param that
|
|
// overrides the defaults with a more restrictive list
|
|
buildQuery(store, modelName, options) {
|
|
return options;
|
|
}
|
|
}
|