| 333 | 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, |
| 339 | | - data: formData, |
| 340 | | - beforeSend: () => { }, |
| 341 | | - cache: false, |
| 342 | | - contentType: false, |
| 343 | | - processData: false, |
| 344 | | - success: async function (data) { |
| 345 | | - // If the user uploaded a new avatar, we want to make sure it's not cached |
| 346 | | - const name = formData.get('overwrite_name'); |
| 347 | | - if (name) { |
| 348 | | - await fetch(getUserAvatar(String(name)), { cache: 'no-cache' }); |
| 349 | | - reloadUserAvatar(true); |
| 350 | | - } |
| 351 | 337 | |
| 352 | | - if (!name && data.path) { |
| 338 | + const response = await fetch(url, { |
| 353 | | - await getUserAvatars(); |
| 339 | + method: 'POST', |
| 354 | | - await delay(500); |
| 340 | + headers: headers, |
| 355 | | - await createPersona(data.path); |
| 341 | + cache: 'no-cache', |
| 356 | | - } |
| 342 | + body: formData, |
| 357 | | - |
| 358 | | - await getUserAvatars(true, name || data.path); |
| 359 | | - }, |
| 360 | | - error: (jqXHR, exception) => { }, |
| 361 | 343 | }); |
| 362 | 344 | |
| 345 | + if (response.ok) { |
| 346 | + const data = await response.json(); |
| 347 | + |
| 348 | + // If the user uploaded a new avatar, we want to make sure it's not cached |
| 349 | + const name = formData.get('overwrite_name'); |
| 350 | + if (name) { |
| 351 | + await fetch(getUserAvatar(String(name)), { cache: 'no-cache' }); |
| 352 | + reloadUserAvatar(true); |
| 353 | + } |
| 354 | + |
| 355 | + if (!name && data.path) { |
| 356 | + await getUserAvatars(); |
| 357 | + await delay(500); |
| 358 | + await createPersona(data.path); |
| 359 | + } |
| 360 | + |
| 361 | + await getUserAvatars(true, name || data.path); |
| 362 | + } |
| 363 | + |
| 363 | 364 | // Will allow to select the same file twice in a row |
| 364 | 365 | form.reset(); |
| 365 | 366 | } |