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

Updated profile image uploads in setup/signup flows for new /images/upload/ endpoint

This commit is contained in:
Kevin Ansfield 2019-02-26 11:21:24 +07:00
parent 738823d8f8
commit 43b6f7add2
2 changed files with 13 additions and 14 deletions

View file

@ -86,9 +86,10 @@ export default Controller.extend(ValidationEngine, {
_sendImage(user) {
let formData = new FormData();
let imageFile = this.get('profileImage');
let uploadUrl = this.get('ghostPaths.url').api('images');
let uploadUrl = this.get('ghostPaths.url').api('images', 'upload');
formData.append('uploadimage', imageFile, imageFile.name);
formData.append('file', imageFile, imageFile.name);
formData.append('purpose', 'profile_image');
return this.get('ajax').post(uploadUrl, {
data: formData,
@ -96,7 +97,8 @@ export default Controller.extend(ValidationEngine, {
contentType: false,
dataType: 'text'
}).then((response) => {
let imageUrl = get(JSON.parse(response), 'url');
let [image] = get(JSON.parse(response), 'images');
let imageUrl = image.url;
let usersUrl = this.get('ghostPaths.url').api('users', user.id.toString());
user.profile_image = imageUrl;

View file

@ -49,7 +49,7 @@ export default Controller.extend({
try {
yield this._authenticateWithPassword();
yield this.get('_sendImage').perform();
yield this._sendImage.perform();
} catch (error) {
notifications.showAPIError(error, {key: 'signup.complete'});
}
@ -99,10 +99,11 @@ export default Controller.extend({
_sendImage: task(function* () {
let formData = new FormData();
let imageFile = this.get('profileImage');
let uploadUrl = this.get('ghostPaths.url').api('images');
let uploadUrl = this.get('ghostPaths.url').api('images', 'upload');
if (imageFile) {
formData.append('uploadimage', imageFile, imageFile.name);
formData.append('file', imageFile, imageFile.name);
formData.append('purpose', 'profile_image');
let user = yield this.get('session.user');
let response = yield this.get('ajax').post(uploadUrl, {
@ -112,16 +113,12 @@ export default Controller.extend({
dataType: 'text'
});
let imageUrl = get(JSON.parse(response), 'url');
let usersUrl = this.get('ghostPaths.url').api('users', user.id.toString());
let [image] = get(JSON.parse(response), 'images');
let imageUrl = image.url;
user.profile_image = imageUrl;
user.set('profileImage', imageUrl);
return yield this.get('ajax').put(usersUrl, {
data: {
users: [user]
}
});
return yield user.save();
}
})
});