mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 22:43:30 +03:00
parent
44ce2f5359
commit
ac321fa62a
@ -7,6 +7,7 @@ import {
|
||||
isVersionMismatchError
|
||||
} from 'ghost-admin/services/ajax';
|
||||
import {computed} from '@ember/object';
|
||||
import {get} from '@ember/object';
|
||||
import {htmlSafe} from '@ember/string';
|
||||
import {isBlank} from '@ember/utils';
|
||||
import {isArray as isEmberArray} from '@ember/array';
|
||||
@ -245,7 +246,7 @@ export default Component.extend({
|
||||
return xhr;
|
||||
}
|
||||
}).then((response) => {
|
||||
let url = JSON.parse(response);
|
||||
let url = get(JSON.parse(response), 'url');
|
||||
this._uploadSuccess(url);
|
||||
}).catch((error) => {
|
||||
this._uploadFailed(error);
|
||||
|
@ -2,6 +2,7 @@ import Component from '@ember/component';
|
||||
import EmberObject from '@ember/object';
|
||||
import ghostPaths from 'ghost-admin/utils/ghost-paths';
|
||||
import {all, task} from 'ember-concurrency';
|
||||
import {get} from '@ember/object';
|
||||
import {isArray as isEmberArray} from '@ember/array';
|
||||
import {isEmpty} from '@ember/utils';
|
||||
import {run} from '@ember/runloop';
|
||||
@ -239,11 +240,10 @@ export default Component.extend({
|
||||
tracker.update({loaded: file.size, total: file.size});
|
||||
this._updateProgress();
|
||||
|
||||
// TODO: is it safe to assume we'll only get a url back?
|
||||
let uploadUrl = JSON.parse(response);
|
||||
let uploadResponse = JSON.parse(response);
|
||||
let result = {
|
||||
fileName: file.name,
|
||||
url: uploadUrl
|
||||
url: get(uploadResponse, 'url')
|
||||
};
|
||||
|
||||
this.get('uploadUrls')[index] = result;
|
||||
|
@ -2,6 +2,7 @@
|
||||
import Controller, {inject as controller} from '@ember/controller';
|
||||
import RSVP from 'rsvp';
|
||||
import ValidationEngine from 'ghost-admin/mixins/validation-engine';
|
||||
import {get} from '@ember/object';
|
||||
import {isInvalidError} from 'ember-ajax/errors';
|
||||
import {isVersionMismatchError} from 'ghost-admin/services/ajax';
|
||||
import {inject as service} from '@ember/service';
|
||||
@ -85,7 +86,7 @@ export default Controller.extend(ValidationEngine, {
|
||||
_sendImage(user) {
|
||||
let formData = new FormData();
|
||||
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);
|
||||
|
||||
@ -95,7 +96,7 @@ export default Controller.extend(ValidationEngine, {
|
||||
contentType: false,
|
||||
dataType: 'text'
|
||||
}).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());
|
||||
user.profile_image = imageUrl;
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
import Controller from '@ember/controller';
|
||||
import {alias} from '@ember/object/computed';
|
||||
import {get} from '@ember/object';
|
||||
import {isArray as isEmberArray} from '@ember/array';
|
||||
import {
|
||||
isVersionMismatchError
|
||||
@ -98,7 +99,7 @@ export default Controller.extend({
|
||||
_sendImage: task(function* () {
|
||||
let formData = new FormData();
|
||||
let imageFile = this.get('profileImage');
|
||||
let uploadUrl = this.get('ghostPaths.url').api('uploads');
|
||||
let uploadUrl = this.get('ghostPaths.url').api('images');
|
||||
|
||||
if (imageFile) {
|
||||
formData.append('uploadimage', imageFile, imageFile.name);
|
||||
@ -111,7 +112,7 @@ export default Controller.extend({
|
||||
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());
|
||||
|
||||
user.profile_image = imageUrl;
|
||||
|
@ -8,7 +8,9 @@ const fileUploadResponse = function (db, {requestBody}) {
|
||||
month = `0${month}`;
|
||||
}
|
||||
|
||||
return `"/content/images/${year}/${month}/${file.name}"`;
|
||||
return {
|
||||
url: `/content/images/${year}/${month}/${file.name}`
|
||||
};
|
||||
};
|
||||
|
||||
export default function mockUploads(server) {
|
||||
|
@ -19,7 +19,7 @@ const notificationsStub = Service.extend({
|
||||
|
||||
const stubSuccessfulUpload = function (server, delay = 0) {
|
||||
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);
|
||||
};
|
||||
|
||||
@ -99,7 +99,7 @@ describe('Integration: Component: gh-file-uploader', function () {
|
||||
await fileUpload('input[type="file"]', ['test'], {name: 'test.csv'});
|
||||
|
||||
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 () {
|
||||
@ -313,7 +313,7 @@ describe('Integration: Component: gh-file-uploader', function () {
|
||||
await settled();
|
||||
|
||||
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 () {
|
||||
|
@ -30,7 +30,7 @@ const sessionStub = Service.extend({
|
||||
|
||||
const stubSuccessfulUpload = function (server, delay = 0) {
|
||||
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);
|
||||
};
|
||||
|
||||
|
@ -10,7 +10,7 @@ import {setupRenderingTest} from 'ember-mocha';
|
||||
|
||||
const stubSuccessfulUpload = function (server, delay = 0) {
|
||||
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);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user