From a463a56971c5d39673e8b4f58502cf3fdeb2a46f Mon Sep 17 00:00:00 2001 From: Nazar Gargol Date: Thu, 31 Jan 2019 15:02:33 +0000 Subject: [PATCH] Changed path returned for uploads to absolute refs #10438 - This change affects all /uploads/* and /images/* endpoints in Admin API --- .../api/v2/utils/serializers/output/upload.js | 3 ++- .../v2/utils/serializers/output/utils/mapper.js | 5 +++++ .../api/v2/utils/serializers/output/utils/url.js | 5 +++++ core/test/acceptance/old/admin/upload_spec.js | 16 ++++++++++++---- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/core/server/api/v2/utils/serializers/output/upload.js b/core/server/api/v2/utils/serializers/output/upload.js index ddbb7dc8e9..6b07d440a6 100644 --- a/core/server/api/v2/utils/serializers/output/upload.js +++ b/core/server/api/v2/utils/serializers/output/upload.js @@ -1,9 +1,10 @@ const debug = require('ghost-ignition').debug('api:v2:utils:serializers:output:upload'); +const mapper = require('./utils/mapper'); module.exports = { image(models, apiConfig, frame) { debug('image'); - return frame.response = models; + return frame.response = mapper.mapImage(models); } }; diff --git a/core/server/api/v2/utils/serializers/output/utils/mapper.js b/core/server/api/v2/utils/serializers/output/utils/mapper.js index 1269f2fee4..c6eaa4aac7 100644 --- a/core/server/api/v2/utils/serializers/output/utils/mapper.js +++ b/core/server/api/v2/utils/serializers/output/utils/mapper.js @@ -90,8 +90,13 @@ const mapIntegration = (model, frame) => { return jsonModel; }; +const mapImage = (path) => { + return url.forImage(path); +}; + module.exports.mapPost = mapPost; module.exports.mapUser = mapUser; module.exports.mapTag = mapTag; module.exports.mapIntegration = mapIntegration; module.exports.mapSettings = mapSettings; +module.exports.mapImage = mapImage; diff --git a/core/server/api/v2/utils/serializers/output/utils/url.js b/core/server/api/v2/utils/serializers/output/utils/url.js index 5826d304e7..3ce4ba60e3 100644 --- a/core/server/api/v2/utils/serializers/output/utils/url.js +++ b/core/server/api/v2/utils/serializers/output/utils/url.js @@ -90,7 +90,12 @@ const forSettings = (attrs) => { return attrs; }; +const forImage = (path) => { + return urlService.utils.urlFor('image', {image: path}, true); +}; + module.exports.forPost = forPost; module.exports.forUser = forUser; module.exports.forTag = forTag; module.exports.forSettings = forSettings; +module.exports.forImage = forImage; diff --git a/core/test/acceptance/old/admin/upload_spec.js b/core/test/acceptance/old/admin/upload_spec.js index b5c19923db..7016a7e3d5 100644 --- a/core/test/acceptance/old/admin/upload_spec.js +++ b/core/test/acceptance/old/admin/upload_spec.js @@ -40,7 +40,9 @@ describe('Upload API', function () { return done(err); } - images.push(res.body); + res.body.should.match(new RegExp(`${config.get('url')}/content/images/\\d+/\\d+/ghost-logo.png`)); + + images.push(res.body.replace(config.get('url'), '')); done(); }); }); @@ -56,7 +58,9 @@ describe('Upload API', function () { return done(err); } - images.push(res.body); + res.body.should.match(new RegExp(`${config.get('url')}/content/images/\\d+/\\d+/ghosticon.jpg`)); + + images.push(res.body.replace(config.get('url'), '')); done(); }); }); @@ -72,7 +76,9 @@ describe('Upload API', function () { return done(err); } - images.push(res.body); + res.body.should.match(new RegExp(`${config.get('url')}/content/images/\\d+/\\d+/loadingcat.gif`)); + + images.push(res.body.replace(config.get('url'), '')); done(); }); }); @@ -88,7 +94,9 @@ describe('Upload API', function () { return done(err); } - images.push(res.body); + res.body.should.match(new RegExp(`${config.get('url')}/content/images/\\d+/\\d+/loadingcat_square.gif`)); + + images.push(res.body.replace(config.get('url'), '')); done(); }); });