From 58b0a1b90d156ec2ffa43d970209d169fc6c0e22 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Thu, 15 Sep 2022 17:40:45 +0100 Subject: [PATCH] Fixed post/page requests in Admin not including correct ?formats param no issue - `buildQuery` method in adapters is only used for store `.query()` calls so when saving the formats param wasn't being added meaning we were losing the `lexical` field in the API response - switched to `buildURL` which is always used --- ghost/admin/app/adapters/page.js | 17 +++++++++++++---- ghost/admin/app/adapters/post.js | 17 +++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/ghost/admin/app/adapters/page.js b/ghost/admin/app/adapters/page.js index 5199196a8b..0500a9fffd 100644 --- a/ghost/admin/app/adapters/page.js +++ b/ghost/admin/app/adapters/page.js @@ -6,11 +6,20 @@ export default class Page extends ApplicationAdapter { return this.buildURL(modelName, id, snapshot, requestType, query); } - buildQuery(store, modelName, options) { - if (!options.formats) { - options.formats = 'mobiledoc,lexical'; + 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 options; + return url; } } diff --git a/ghost/admin/app/adapters/post.js b/ghost/admin/app/adapters/post.js index edce3d0bd1..cafe897233 100644 --- a/ghost/admin/app/adapters/post.js +++ b/ghost/admin/app/adapters/post.js @@ -24,11 +24,20 @@ export default class Post extends ApplicationAdapter { return parsedUrl.toString(); } - buildQuery(store, modelName, options) { - if (!options.formats) { - options.formats = 'mobiledoc,lexical'; + 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 options; + return url; } }