Reformat code

This commit is contained in:
Cohee 2023-08-20 12:37:38 +03:00
parent 84e5a63c34
commit 94754af013
5 changed files with 33 additions and 33 deletions

View File

@ -7518,7 +7518,7 @@ $(document).ready(function () {
$("#character_search_bar").val("").trigger("input");
});
$(document).on("click", ".character_select", function() {
$(document).on("click", ".character_select", function () {
const id = $(this).attr("chid");
selectCharacterById(id);
});

View File

@ -651,7 +651,7 @@ async function generatePrompt(quiet_prompt) {
return processReply(reply);
}
async function sendGenerationRequest(generationType, prompt, characterName=null, callback) {
async function sendGenerationRequest(generationType, prompt, characterName = null, callback) {
const prefix = generationType !== generationMode.BACKGROUND
? combinePrefixes(extension_settings.sd.prompt_prefix, getCharacterPrefix())
: extension_settings.sd.prompt_prefix;

View File

@ -337,25 +337,25 @@ async function getGroups() {
}
export function getGroupBlock(group) {
const template = $("#group_list_template .group_select").clone();
template.data("id", group.id);
template.attr("grid", group.id);
template.find(".ch_name").html(group.name);
template.find('.group_fav_icon').css("display", 'none');
template.addClass(group.fav ? 'is_fav' : '');
template.find(".ch_fav").val(group.fav);
const template = $("#group_list_template .group_select").clone();
template.data("id", group.id);
template.attr("grid", group.id);
template.find(".ch_name").html(group.name);
template.find('.group_fav_icon').css("display", 'none');
template.addClass(group.fav ? 'is_fav' : '');
template.find(".ch_fav").val(group.fav);
// Display inline tags
const tags = getTagsList(group.id);
const tagsElement = template.find('.tags');
tags.forEach(tag => appendTagToList(tagsElement, tag, {}));
// Display inline tags
const tags = getTagsList(group.id);
const tagsElement = template.find('.tags');
tags.forEach(tag => appendTagToList(tagsElement, tag, {}));
const avatar = getGroupAvatar(group);
if (avatar) {
$(template).find(".avatar").replaceWith(avatar);
}
const avatar = getGroupAvatar(group);
if (avatar) {
$(template).find(".avatar").replaceWith(avatar);
}
return template;
return template;
}
function updateGroupAvatar(group) {
@ -363,7 +363,7 @@ function updateGroupAvatar(group) {
$(".group_select").each(function () {
if ($(this).data("id") == group.id) {
$(this).find(".avatar").replaceWith(getGroupAvatar(group));
$(this).find(".avatar").replaceWith(getGroupAvatar(group));
}
});
}
@ -382,7 +382,7 @@ function getGroupAvatar(group) {
if (!group) {
return $(`<div class="avatar"><img src="${default_avatar}"></div>`);
}
// if isDataURL or if it's a valid local file url
// if isDataURL or if it's a valid local file url
if (isValidImageUrl(group.avatar_url)) {
return $(`<div class="avatar"><img src="${group.avatar_url}"></div>`);
}
@ -1132,16 +1132,16 @@ function select_group_chats(groupId, skipAnimation) {
$("#rm_group_automode_label").hide();
}
eventSource.emit('groupSelected', {detail: {id: openGroupId, group: group}});
eventSource.emit('groupSelected', { detail: { id: openGroupId, group: group } });
}
/**
* Handles the upload and processing of a group avatar.
* The selected image is read, cropped using a popup, processed into a thumbnail,
* and then uploaded to the server.
*
*
* @param {Event} event - The event triggered by selecting a file input, containing the image file to upload.
*
*
* @returns {Promise<void>} - A promise that resolves when the processing and upload is complete.
*/
async function uploadGroupAvatar(event) {

View File

@ -557,15 +557,15 @@ export function extractDataFromPng(data, identifier = 'chara') {
/**
* Sends a base64 encoded image to the backend to be saved as a file.
*
*
* @param {string} base64Data - The base64 encoded image data.
* @param {string} characterName - The character name to determine the sub-directory for saving.
* @param {string} ext - The file extension for the image (e.g., 'jpg', 'png', 'webp').
*
* @returns {Promise<string>} - Resolves to the saved image's path on the server.
*
* @returns {Promise<string>} - Resolves to the saved image's path on the server.
* Rejects with an error if the upload fails.
*/
export async function saveBase64AsFile(base64Data, characterName, filename="", ext) {
export async function saveBase64AsFile(base64Data, characterName, filename = "", ext) {
// Construct the full data URL
const format = ext; // Extract the file extension (jpg, png, webp)
const dataURL = `data:image/${format};base64,${base64Data}`;

View File

@ -2617,7 +2617,7 @@ app.post('/uploaduseravatar', urlencodedParser, async (request, response) => {
/**
* Ensure the directory for the provided file path exists.
* If not, it will recursively create the directory.
*
*
* @param {string} filePath - The full path of the file for which the directory should be ensured.
*/
function ensureDirectoryExistence(filePath) {
@ -2633,7 +2633,7 @@ function ensureDirectoryExistence(filePath) {
* Endpoint to handle image uploads.
* The image should be provided in the request body in base64 format.
* Optionally, a character name can be provided to save the image in a sub-folder.
*
*
* @route POST /uploadimage
* @param {Object} request.body - The request payload.
* @param {string} request.body.image - The base64 encoded image data.
@ -2656,13 +2656,13 @@ app.post('/uploadimage', jsonParser, async (request, response) => {
// Constructing filename and path
let filename = `${Date.now()}.${format}`;
if(request.body.filename){
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){
let pathToNewFile = path.join(directories.userImages, filename);
if (request.body.ch_name) {
pathToNewFile = path.join(directories.userImages, request.body.ch_name, filename);
}
@ -2672,7 +2672,7 @@ app.post('/uploadimage', jsonParser, async (request, response) => {
await fs.promises.writeFile(pathToNewFile, imageBuffer);
// send the path to the image, relative to the client folder, which means removing the first folder from the path which is 'public'
pathToNewFile = pathToNewFile.split(path.sep).slice(1).join(path.sep);
response.send({ path:pathToNewFile });
response.send({ path: pathToNewFile });
} catch (error) {
console.log(error);
response.status(500).send({ error: "Failed to save the image" });