Fixed relative image paths for settings v2 admin api

refs #10363
This commit is contained in:
kirrg001 2019-01-14 21:01:12 +01:00
parent 56db4ddd75
commit 95b5fb1c81
2 changed files with 20 additions and 8 deletions

View File

@ -26,6 +26,7 @@ _private.settingsFilter = (settings, filter) => {
module.exports = {
browse(models, apiConfig, frame) {
let filteredSettings;
// If this is public, we already have the right data, we just need to add an Array wrapper
if (utils.isContentAPI(frame)) {
filteredSettings = models;

View File

@ -1,3 +1,4 @@
const _ = require('lodash');
const urlService = require('../../../../../../services/url');
const forPost = (id, attrs, options) => {
@ -64,16 +65,26 @@ const forTag = (id, attrs) => {
};
const forSettings = (attrs) => {
if (attrs.cover_image) {
attrs.cover_image = urlService.utils.urlFor('image', {image: attrs.cover_image}, true);
}
// @TODO: https://github.com/TryGhost/Ghost/issues/10106
// @NOTE: Admin & Content API return a different format, need to mappers
if (_.isArray(attrs)) {
attrs.forEach((obj) => {
if (['cover_image', 'logo', 'icon'].includes(obj.key) && obj.value) {
obj.value = urlService.utils.urlFor('image', {image: obj.value}, true);
}
});
} else {
if (attrs.cover_image) {
attrs.cover_image = urlService.utils.urlFor('image', {image: attrs.cover_image}, true);
}
if (attrs.logo) {
attrs.logo = urlService.utils.urlFor('image', {image: attrs.logo}, true);
}
if (attrs.logo) {
attrs.logo = urlService.utils.urlFor('image', {image: attrs.logo}, true);
}
if (attrs.icon) {
attrs.icon = urlService.utils.urlFor('image', {image: attrs.icon}, true);
if (attrs.icon) {
attrs.icon = urlService.utils.urlFor('image', {image: attrs.icon}, true);
}
}
return attrs;