Update persona upload methods to fetch
| @@ -268,7 +268,7 @@ export async function getUserAvatars(doRender = true, openPageAt = '') { | |||
| 268 | * Uploads an avatar file to the server | 268 | * Uploads an avatar file to the server |
| 269 | * @param {string} url URL for the avatar file | 269 | * @param {string} url URL for the avatar file |
| 270 | * @param {string} [name] Optional name for the avatar file | 270 | * @param {string} [name] Optional name for the avatar file |
| 271 | * @returns {Promise} Promise object representing the AJAX request | 271 | * @returns {Promise} Promise that resolves when the avatar is uploaded |
| 272 | */ | 272 | */ |
| 273 | async function uploadUserAvatar(url, name) { | 273 | async function uploadUserAvatar(url, name) { |
| 274 | const fetchResult = await fetch(url); | 274 | const fetchResult = await fetch(url); |
| @@ -281,18 +281,17 @@ async function uploadUserAvatar(url, name) { | |||
| 281 | formData.append('overwrite_name', name); | 281 | formData.append('overwrite_name', name); |
| 282 | } | 282 | } |
| 283 | 283 | ||
| 284 | return jQuery.ajax({ | 284 | const headers = getRequestHeaders(); |
| 285 | type: 'POST', | 285 | delete headers['Content-Type']; |
| 286 | url: '/api/avatars/upload', | 286 | |
| 287 | data: formData, | 287 | await fetch('/api/avatars/upload', { |
| 288 | beforeSend: () => { }, | 288 | method: 'POST', |
| 289 | cache: false, | 289 | headers: headers, |
| 290 | contentType: false, | 290 | cache: 'no-cache', |
| 291 | processData: false, | 291 | body: formData, |
| 292 | success: async function () { | ||
| 293 | await getUserAvatars(true, name); | ||
| 294 | }, | ||
| 295 | }); | 292 | }); |
| 293 | |||
| 294 | await getUserAvatars(true, name); | ||
| 296 | } | 295 | } |
| 297 | 296 | ||
| 298 | async function changeUserAvatar(e) { | 297 | async function changeUserAvatar(e) { |
| @@ -333,15 +332,19 @@ async function changeUserAvatar(e) { | |||
| 333 | formData.set('avatar', convertedFile); | 332 | formData.set('avatar', convertedFile); |
| 334 | } | 333 | } |
| 335 | 334 | ||
| 336 | jQuery.ajax({ | 335 | const headers = getRequestHeaders(); |
| 337 | type: 'POST', | 336 | delete headers['Content-Type']; |
| 338 | url: url, | 337 | |
| 339 | data: formData, | 338 | const response = await fetch(url, { |
| 340 | beforeSend: () => { }, | 339 | method: 'POST', |
| 341 | cache: false, | 340 | headers: headers, |
| 342 | contentType: false, | 341 | cache: 'no-cache', |
| 343 | processData: false, | 342 | body: formData, |
| 344 | success: async function (data) { | 343 | }); |
| 344 | |||
| 345 | if (response.ok) { | ||
| 346 | const data = await response.json(); | ||
| 347 | |||
| 345 | // If the user uploaded a new avatar, we want to make sure it's not cached | 348 | // If the user uploaded a new avatar, we want to make sure it's not cached |
| 346 | const name = formData.get('overwrite_name'); | 349 | const name = formData.get('overwrite_name'); |
| 347 | if (name) { | 350 | if (name) { |
| @@ -356,9 +359,7 @@ async function changeUserAvatar(e) { | |||
| 356 | } | 359 | } |
| 357 | 360 | ||
| 358 | await getUserAvatars(true, name || data.path); | 361 | await getUserAvatars(true, name || data.path); |
| 359 | }, | 362 | } |
| 360 | error: (jqXHR, exception) => { }, | ||
| 361 | }); | ||
| 362 | 363 | ||
| 363 | // Will allow to select the same file twice in a row | 364 | // Will allow to select the same file twice in a row |
| 364 | form.reset(); | 365 | form.reset(); |