Assorted SD fixes

This commit is contained in:
Cohee 2023-11-19 00:40:21 +02:00
parent b6936584fe
commit 53c3fc16c1
4 changed files with 39 additions and 45 deletions

View File

@ -9055,19 +9055,12 @@ jQuery(async function () {
});
$(document).on('click', '.mes .avatar', function () {
//console.log(isMobile());
//console.log($('body').hasClass('waifuMode'));
/* if (isMobile() === true && !$('body').hasClass('waifuMode')) {
console.debug('saw mobile regular mode, returning');
return;
} else { console.debug('saw valid env for zoomed display') } */
let thumbURL = $(this).children('img').attr('src');
let charsPath = '/characters/'
let targetAvatarImg = thumbURL.substring(thumbURL.lastIndexOf("=") + 1);
let charname = targetAvatarImg.replace('.png', '');
const messageElement = $(this).closest('.mes');
const thumbURL = $(this).children('img').attr('src');
const charsPath = '/characters/'
const targetAvatarImg = thumbURL.substring(thumbURL.lastIndexOf("=") + 1);
const charname = targetAvatarImg.replace('.png', '');
const isValidCharacter = characters.some(x => x.avatar === targetAvatarImg);
// Remove existing zoomed avatars for characters that are not the clicked character when moving UI is not enabled
if (!power_user.movingUI) {
@ -9080,7 +9073,7 @@ jQuery(async function () {
});
}
let avatarSrc = isDataURL(thumbURL) ? thumbURL : charsPath + targetAvatarImg;
const avatarSrc = isDataURL(thumbURL) ? thumbURL : charsPath + targetAvatarImg;
if ($(`.zoomed_avatar[forChar="${charname}"]`).length) {
console.debug('removing container as it already existed')
$(`.zoomed_avatar[forChar="${charname}"]`).remove();
@ -9094,11 +9087,11 @@ jQuery(async function () {
newElement.find('.drag-grabber').attr('id', `zoomFor_${charname}header`);
$('body').append(newElement);
if ($(this).parent().parent().attr('is_user') == 'true') { //handle user avatars
if (messageElement.attr('is_user') == 'true') { //handle user avatars
$(`.zoomed_avatar[forChar="${charname}"] img`).attr('src', thumbURL);
} else if ($(this).parent().parent().attr('is_system') == 'true') { //handle system avatars
} else if (messageElement.attr('is_system') == 'true' && !isValidCharacter) { //handle system avatars
$(`.zoomed_avatar[forChar="${charname}"] img`).attr('src', thumbURL);
} else if ($(this).parent().parent().attr('is_user') == 'false') { //handle char avatars
} else if (messageElement.attr('is_user') == 'false') { //handle char avatars
$(`.zoomed_avatar[forChar="${charname}"] img`).attr('src', avatarSrc);
}
loadMovingUIState();

View File

@ -365,10 +365,9 @@ function addExtensionsButtonAndMenu() {
});
$("html").on('touchstart mousedown', function (e) {
// let clickTarget = $(e.target);
if (dropdown.is(':visible')
/*&& clickTarget.closest(button).length == 0
&& clickTarget.closest(dropdown).length == 0*/) {
const clickTarget = $(e.target);
const noCloseTargets = ['#sd_gen'];
if (dropdown.is(':visible') && !noCloseTargets.some(id => clickTarget.closest(id).length > 0)) {
$(dropdown).fadeOut(animation_duration);
}
});

View File

@ -7,10 +7,11 @@ import {
getRequestHeaders,
event_types,
eventSource,
appendImageToMessage,
generateQuietPrompt,
this_chid,
getCurrentChatId,
animation_duration,
appendMediaToMessage,
} from "../../../script.js";
import { getApiUrl, getContext, extension_settings, doExtrasFetch, modules, renderExtensionTemplate } from "../../extensions.js";
import { selected_group } from "../../group-chats.js";
@ -1764,10 +1765,10 @@ function addSDGenButtons() {
if (target.is(button) && !dropdown.is(":visible") && $("#send_but").is(":visible")) {
e.preventDefault();
dropdown.fadeIn(250);
dropdown.fadeIn(animation_duration);
popper.update();
} else {
dropdown.fadeOut(250);
dropdown.fadeOut(animation_duration);
}
});
}
@ -1865,7 +1866,7 @@ async function sdMessageButton(e) {
message.extra.image = image;
message.extra.title = prompt;
message.extra.generationType = generationType;
appendImageToMessage(message, $mes);
appendMediaToMessage(message, $mes);
context.saveChat();
}

View File

@ -2493,27 +2493,28 @@ app.post('/uploadimage', jsonParser, async (request, response) => {
return response.status(400).send({ error: "No image data provided" });
}
// Extracting the base64 data and the image format
const match = request.body.image.match(/^data:image\/(png|jpg|webp|jpeg|gif);base64,(.+)$/);
if (!match) {
return response.status(400).send({ error: "Invalid image format" });
}
const [, format, base64Data] = match;
// Constructing filename and path
let filename = `${Date.now()}.${format}`;
if (request.body.filename) {
filename = `${request.body.filename}.${format}`;
}
// if character is defined, save to a sub folder for that character
let pathToNewFile = path.join(DIRECTORIES.userImages, filename);
if (request.body.ch_name) {
pathToNewFile = path.join(DIRECTORIES.userImages, request.body.ch_name, filename);
}
try {
// Extracting the base64 data and the image format
const splitParts = request.body.image.split(',');
const format = splitParts[0].split(';')[0].split('/')[1];
const base64Data = splitParts[1];
const validFormat = ['png', 'jpg', 'webp', 'jpeg', 'gif'].includes(format);
if (!validFormat) {
return response.status(400).send({ error: "Invalid image format" });
}
// Constructing filename and path
let filename = `${Date.now()}.${format}`;
if (request.body.filename) {
filename = `${request.body.filename}.${format}`;
}
// if character is defined, save to a sub folder for that character
let pathToNewFile = path.join(DIRECTORIES.userImages, filename);
if (request.body.ch_name) {
pathToNewFile = path.join(DIRECTORIES.userImages, request.body.ch_name, filename);
}
ensureDirectoryExistence(pathToNewFile);
const imageBuffer = Buffer.from(base64Data, 'base64');
await fs.promises.writeFile(pathToNewFile, imageBuffer);