Switch to mastoapi for updating avatar

# Conflicts:
#	src/services/api/api.service.js
This commit is contained in:
taehoon 2019-03-13 13:12:56 -04:00
parent 9e2fa50b74
commit 808e1ac11c
3 changed files with 24 additions and 32 deletions

View file

@ -164,19 +164,23 @@ const UserSettings = {
reader.readAsDataURL(file)
},
submitAvatar (cropper, file) {
let img
if (cropper) {
img = cropper.getCroppedCanvas().toDataURL(file.type)
} else {
img = file
}
return new Promise((resolve, reject) => {
function updateAvatar (avatar) {
this.$store.state.api.backendInteractor.updateAvatar({ avatar })
.then((user) => {
this.$store.commit('addNewUsers', [user])
this.$store.commit('setCurrentUser', user)
resolve()
})
.catch((err) => {
reject(new Error(this.$t('upload.error.base') + ' ' + err.message))
})
}
return this.$store.state.api.backendInteractor.updateAvatar({ params: { img } }).then((user) => {
if (!user.error) {
this.$store.commit('addNewUsers', [user])
this.$store.commit('setCurrentUser', user)
if (cropper) {
cropper.getCroppedCanvas().toBlob(updateAvatar, file.type)
} else {
throw new Error(this.$t('upload.error.base') + user.error)
updateAvatar(file)
}
})
},