Update persona upload methods to fetch

cbeb7ddcec7de6b1ab50dc0cb4f89cf7d1b12c2f

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +37 -36Ignore whitespace
public/scripts/personas.js+37 -36
@@ -268,7 +268,7 @@ export async function getUserAvatars(doRender = true, openPageAt = '') {
268268 * Uploads an avatar file to the server
269269 * @param {string} url URL for the avatar file
270270 * @param {string} [name] Optional name for the avatar file
271271 * @returns {Promise} Promise objectthat representingresolves when the AJAXavatar requestis uploaded
272272 */
273273async function uploadUserAvatar(url, name) {
274274 const fetchResult = await fetch(url);
@@ -281,18 +281,17 @@ async function uploadUserAvatar(url, name) {
281281 formData.append('overwrite_name', name);
282282 }
283283
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',
289289 cacheheaders: falseheaders,
290290 contentTypecache: false'no-cache',
291291 processDatabody: falseformData,
292- success: async function () {
293- await getUserAvatars(true, name);
294- },
295292 });
293+
294+ await getUserAvatars(true, name);
296295}
297296
298297async function changeUserAvatar(e) {
@@ -333,33 +332,35 @@ async function changeUserAvatar(e) {
333332 formData.set('avatar', convertedFile);
334333 }
335334
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- }
351337
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) => { },
361343 });
362344
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+
363364 // Will allow to select the same file twice in a row
364365 form.reset();
365366}