Pass file name of cropped avatar to form data

This commit is contained in:
Alexander Tumin 2022-05-20 02:36:55 +03:00
parent 96a24ec625
commit 29b084b4b8
2 changed files with 12 additions and 6 deletions

View file

@ -193,8 +193,8 @@ const ProfileTab = {
submitAvatar (cropper, file) { submitAvatar (cropper, file) {
const that = this const that = this
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
function updateAvatar (avatar) { function updateAvatar (avatar, avatarName) {
that.$store.state.api.backendInteractor.updateProfileImages({ avatar }) that.$store.state.api.backendInteractor.updateProfileImages({ avatar, avatarName })
.then((user) => { .then((user) => {
that.$store.commit('addNewUsers', [user]) that.$store.commit('addNewUsers', [user])
that.$store.commit('setCurrentUser', user) that.$store.commit('setCurrentUser', user)
@ -207,9 +207,9 @@ const ProfileTab = {
} }
if (cropper) { if (cropper) {
cropper.getCroppedCanvas().toBlob(updateAvatar, file.type) cropper.getCroppedCanvas().toBlob((data) => updateAvatar(data, file.name), file.type)
} else { } else {
updateAvatar(file) updateAvatar(file, file.name)
} }
}) })
}, },

View file

@ -151,9 +151,15 @@ const updateNotificationSettings = ({ credentials, settings }) => {
}).then((data) => data.json()) }).then((data) => data.json())
} }
const updateProfileImages = ({ credentials, avatar = null, banner = null, background = null }) => { const updateProfileImages = ({ credentials, avatar = null, avatarName = null, banner = null, background = null }) => {
const form = new FormData() const form = new FormData()
if (avatar !== null) form.append('avatar', avatar) if (avatar !== null) {
if (avatarName !== null) {
form.append('avatar', avatar, avatarName)
} else {
form.append('avatar', avatar)
}
}
if (banner !== null) form.append('header', banner) if (banner !== null) form.append('header', banner)
if (background !== null) form.append('pleroma_background_image', background) if (background !== null) form.append('pleroma_background_image', background)
return fetch(MASTODON_PROFILE_UPDATE_URL, { return fetch(MASTODON_PROFILE_UPDATE_URL, {