0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00

Updated /images* response structure

refs #10438
This commit is contained in:
Nazar Gargol 2019-02-22 12:29:40 +07:00
parent 44ce2f5359
commit ac321fa62a
8 changed files with 19 additions and 14 deletions

View file

@ -7,6 +7,7 @@ import {
isVersionMismatchError isVersionMismatchError
} from 'ghost-admin/services/ajax'; } from 'ghost-admin/services/ajax';
import {computed} from '@ember/object'; import {computed} from '@ember/object';
import {get} from '@ember/object';
import {htmlSafe} from '@ember/string'; import {htmlSafe} from '@ember/string';
import {isBlank} from '@ember/utils'; import {isBlank} from '@ember/utils';
import {isArray as isEmberArray} from '@ember/array'; import {isArray as isEmberArray} from '@ember/array';
@ -245,7 +246,7 @@ export default Component.extend({
return xhr; return xhr;
} }
}).then((response) => { }).then((response) => {
let url = JSON.parse(response); let url = get(JSON.parse(response), 'url');
this._uploadSuccess(url); this._uploadSuccess(url);
}).catch((error) => { }).catch((error) => {
this._uploadFailed(error); this._uploadFailed(error);

View file

@ -2,6 +2,7 @@ import Component from '@ember/component';
import EmberObject from '@ember/object'; import EmberObject from '@ember/object';
import ghostPaths from 'ghost-admin/utils/ghost-paths'; import ghostPaths from 'ghost-admin/utils/ghost-paths';
import {all, task} from 'ember-concurrency'; import {all, task} from 'ember-concurrency';
import {get} from '@ember/object';
import {isArray as isEmberArray} from '@ember/array'; import {isArray as isEmberArray} from '@ember/array';
import {isEmpty} from '@ember/utils'; import {isEmpty} from '@ember/utils';
import {run} from '@ember/runloop'; import {run} from '@ember/runloop';
@ -239,11 +240,10 @@ export default Component.extend({
tracker.update({loaded: file.size, total: file.size}); tracker.update({loaded: file.size, total: file.size});
this._updateProgress(); this._updateProgress();
// TODO: is it safe to assume we'll only get a url back? let uploadResponse = JSON.parse(response);
let uploadUrl = JSON.parse(response);
let result = { let result = {
fileName: file.name, fileName: file.name,
url: uploadUrl url: get(uploadResponse, 'url')
}; };
this.get('uploadUrls')[index] = result; this.get('uploadUrls')[index] = result;

View file

@ -2,6 +2,7 @@
import Controller, {inject as controller} from '@ember/controller'; import Controller, {inject as controller} from '@ember/controller';
import RSVP from 'rsvp'; import RSVP from 'rsvp';
import ValidationEngine from 'ghost-admin/mixins/validation-engine'; import ValidationEngine from 'ghost-admin/mixins/validation-engine';
import {get} from '@ember/object';
import {isInvalidError} from 'ember-ajax/errors'; import {isInvalidError} from 'ember-ajax/errors';
import {isVersionMismatchError} from 'ghost-admin/services/ajax'; import {isVersionMismatchError} from 'ghost-admin/services/ajax';
import {inject as service} from '@ember/service'; import {inject as service} from '@ember/service';
@ -85,7 +86,7 @@ export default Controller.extend(ValidationEngine, {
_sendImage(user) { _sendImage(user) {
let formData = new FormData(); let formData = new FormData();
let imageFile = this.get('profileImage'); let imageFile = this.get('profileImage');
let uploadUrl = this.get('ghostPaths.url').api('uploads'); let uploadUrl = this.get('ghostPaths.url').api('images');
formData.append('uploadimage', imageFile, imageFile.name); formData.append('uploadimage', imageFile, imageFile.name);
@ -95,7 +96,7 @@ export default Controller.extend(ValidationEngine, {
contentType: false, contentType: false,
dataType: 'text' dataType: 'text'
}).then((response) => { }).then((response) => {
let imageUrl = JSON.parse(response); let imageUrl = get(JSON.parse(response), 'url');
let usersUrl = this.get('ghostPaths.url').api('users', user.id.toString()); let usersUrl = this.get('ghostPaths.url').api('users', user.id.toString());
user.profile_image = imageUrl; user.profile_image = imageUrl;

View file

@ -1,5 +1,6 @@
import Controller from '@ember/controller'; import Controller from '@ember/controller';
import {alias} from '@ember/object/computed'; import {alias} from '@ember/object/computed';
import {get} from '@ember/object';
import {isArray as isEmberArray} from '@ember/array'; import {isArray as isEmberArray} from '@ember/array';
import { import {
isVersionMismatchError isVersionMismatchError
@ -98,7 +99,7 @@ export default Controller.extend({
_sendImage: task(function* () { _sendImage: task(function* () {
let formData = new FormData(); let formData = new FormData();
let imageFile = this.get('profileImage'); let imageFile = this.get('profileImage');
let uploadUrl = this.get('ghostPaths.url').api('uploads'); let uploadUrl = this.get('ghostPaths.url').api('images');
if (imageFile) { if (imageFile) {
formData.append('uploadimage', imageFile, imageFile.name); formData.append('uploadimage', imageFile, imageFile.name);
@ -111,7 +112,7 @@ export default Controller.extend({
dataType: 'text' dataType: 'text'
}); });
let imageUrl = JSON.parse(response); let imageUrl = get(JSON.parse(response), 'url');
let usersUrl = this.get('ghostPaths.url').api('users', user.id.toString()); let usersUrl = this.get('ghostPaths.url').api('users', user.id.toString());
user.profile_image = imageUrl; user.profile_image = imageUrl;

View file

@ -8,7 +8,9 @@ const fileUploadResponse = function (db, {requestBody}) {
month = `0${month}`; month = `0${month}`;
} }
return `"/content/images/${year}/${month}/${file.name}"`; return {
url: `/content/images/${year}/${month}/${file.name}`
};
}; };
export default function mockUploads(server) { export default function mockUploads(server) {

View file

@ -19,7 +19,7 @@ const notificationsStub = Service.extend({
const stubSuccessfulUpload = function (server, delay = 0) { const stubSuccessfulUpload = function (server, delay = 0) {
server.post('/ghost/api/v2/admin/images/', function () { server.post('/ghost/api/v2/admin/images/', function () {
return [200, {'Content-Type': 'application/json'}, '"/content/images/test.png"']; return [200, {'Content-Type': 'application/json'}, '{"url":"/content/images/test.png"}'];
}, delay); }, delay);
}; };
@ -99,7 +99,7 @@ describe('Integration: Component: gh-file-uploader', function () {
await fileUpload('input[type="file"]', ['test'], {name: 'test.csv'}); await fileUpload('input[type="file"]', ['test'], {name: 'test.csv'});
expect(uploadSuccess.calledOnce).to.be.true; expect(uploadSuccess.calledOnce).to.be.true;
expect(uploadSuccess.firstCall.args[0]).to.equal('/content/images/test.png'); expect(uploadSuccess.firstCall.args[0]).to.eql({url: '/content/images/test.png'});
}); });
it('doesn\'t fire uploadSuccess action on failed upload', async function () { it('doesn\'t fire uploadSuccess action on failed upload', async function () {
@ -313,7 +313,7 @@ describe('Integration: Component: gh-file-uploader', function () {
await settled(); await settled();
expect(uploadSuccess.calledOnce).to.be.true; expect(uploadSuccess.calledOnce).to.be.true;
expect(uploadSuccess.firstCall.args[0]).to.equal('/content/images/test.png'); expect(uploadSuccess.firstCall.args[0]).to.eql({url: '/content/images/test.png'});
}); });
it('validates extension by default', async function () { it('validates extension by default', async function () {

View file

@ -30,7 +30,7 @@ const sessionStub = Service.extend({
const stubSuccessfulUpload = function (server, delay = 0) { const stubSuccessfulUpload = function (server, delay = 0) {
server.post('/ghost/api/v2/admin/images/', function () { server.post('/ghost/api/v2/admin/images/', function () {
return [200, {'Content-Type': 'application/json'}, '"/content/images/test.png"']; return [200, {'Content-Type': 'application/json'}, '{"url":"/content/images/test.png"}'];
}, delay); }, delay);
}; };

View file

@ -10,7 +10,7 @@ import {setupRenderingTest} from 'ember-mocha';
const stubSuccessfulUpload = function (server, delay = 0) { const stubSuccessfulUpload = function (server, delay = 0) {
server.post('/ghost/api/v2/admin/images/', function () { server.post('/ghost/api/v2/admin/images/', function () {
return [200, {'Content-Type': 'application/json'}, '"/content/images/test.png"']; return [200, {'Content-Type': 'application/json'}, '{"url": "/content/images/test.png"}'];
}, delay); }, delay);
}; };