mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-05-02 03:18:42 +02:00
Update persona upload methods to fetch
This commit is contained in:
parent
3d817352ec
commit
cbeb7ddcec
@ -268,7 +268,7 @@ export async function getUserAvatars(doRender = true, openPageAt = '') {
|
|||||||
* Uploads an avatar file to the server
|
* Uploads an avatar file to the server
|
||||||
* @param {string} url URL for the avatar file
|
* @param {string} url URL for the avatar file
|
||||||
* @param {string} [name] Optional name for the avatar file
|
* @param {string} [name] Optional name for the avatar file
|
||||||
* @returns {Promise} Promise object representing the AJAX request
|
* @returns {Promise} Promise that resolves when the avatar is uploaded
|
||||||
*/
|
*/
|
||||||
async function uploadUserAvatar(url, name) {
|
async function uploadUserAvatar(url, name) {
|
||||||
const fetchResult = await fetch(url);
|
const fetchResult = await fetch(url);
|
||||||
@ -281,18 +281,17 @@ async function uploadUserAvatar(url, name) {
|
|||||||
formData.append('overwrite_name', name);
|
formData.append('overwrite_name', name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return jQuery.ajax({
|
const headers = getRequestHeaders();
|
||||||
type: 'POST',
|
delete headers['Content-Type'];
|
||||||
url: '/api/avatars/upload',
|
|
||||||
data: formData,
|
await fetch('/api/avatars/upload', {
|
||||||
beforeSend: () => { },
|
method: 'POST',
|
||||||
cache: false,
|
headers: headers,
|
||||||
contentType: false,
|
cache: 'no-cache',
|
||||||
processData: false,
|
body: formData,
|
||||||
success: async function () {
|
|
||||||
await getUserAvatars(true, name);
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await getUserAvatars(true, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function changeUserAvatar(e) {
|
async function changeUserAvatar(e) {
|
||||||
@ -333,33 +332,35 @@ async function changeUserAvatar(e) {
|
|||||||
formData.set('avatar', convertedFile);
|
formData.set('avatar', convertedFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
jQuery.ajax({
|
const headers = getRequestHeaders();
|
||||||
type: 'POST',
|
delete headers['Content-Type'];
|
||||||
url: url,
|
|
||||||
data: formData,
|
|
||||||
beforeSend: () => { },
|
|
||||||
cache: false,
|
|
||||||
contentType: false,
|
|
||||||
processData: false,
|
|
||||||
success: async function (data) {
|
|
||||||
// If the user uploaded a new avatar, we want to make sure it's not cached
|
|
||||||
const name = formData.get('overwrite_name');
|
|
||||||
if (name) {
|
|
||||||
await fetch(getUserAvatar(String(name)), { cache: 'no-cache' });
|
|
||||||
reloadUserAvatar(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!name && data.path) {
|
const response = await fetch(url, {
|
||||||
await getUserAvatars();
|
method: 'POST',
|
||||||
await delay(500);
|
headers: headers,
|
||||||
await createPersona(data.path);
|
cache: 'no-cache',
|
||||||
}
|
body: formData,
|
||||||
|
|
||||||
await getUserAvatars(true, name || data.path);
|
|
||||||
},
|
|
||||||
error: (jqXHR, exception) => { },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
// If the user uploaded a new avatar, we want to make sure it's not cached
|
||||||
|
const name = formData.get('overwrite_name');
|
||||||
|
if (name) {
|
||||||
|
await fetch(getUserAvatar(String(name)), { cache: 'no-cache' });
|
||||||
|
reloadUserAvatar(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!name && data.path) {
|
||||||
|
await getUserAvatars();
|
||||||
|
await delay(500);
|
||||||
|
await createPersona(data.path);
|
||||||
|
}
|
||||||
|
|
||||||
|
await getUserAvatars(true, name || data.path);
|
||||||
|
}
|
||||||
|
|
||||||
// Will allow to select the same file twice in a row
|
// Will allow to select the same file twice in a row
|
||||||
form.reset();
|
form.reset();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user