mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Move to char+timestamp for img naming.
This commit is contained in:
@ -15,6 +15,7 @@ import {
|
|||||||
import { getApiUrl, getContext, extension_settings, doExtrasFetch, modules } from "../../extensions.js";
|
import { getApiUrl, getContext, extension_settings, doExtrasFetch, modules } from "../../extensions.js";
|
||||||
import { selected_group } from "../../group-chats.js";
|
import { selected_group } from "../../group-chats.js";
|
||||||
import { stringFormat, initScrollHeight, resetScrollHeight, timestampToMoment, getCharaFilename, saveBase64AsFile } from "../../utils.js";
|
import { stringFormat, initScrollHeight, resetScrollHeight, timestampToMoment, getCharaFilename, saveBase64AsFile } from "../../utils.js";
|
||||||
|
import { humanizedDateTime } from "../../RossAscends-mods.js";
|
||||||
export { MODULE_NAME };
|
export { MODULE_NAME };
|
||||||
|
|
||||||
// Wraps a string into monospace font-face span
|
// Wraps a string into monospace font-face span
|
||||||
@ -699,7 +700,9 @@ async function generateExtrasImage(prompt, prefix, characterName, callback) {
|
|||||||
|
|
||||||
if (result.ok) {
|
if (result.ok) {
|
||||||
const data = await result.json();
|
const data = await result.json();
|
||||||
const base64Image = await saveBase64AsFile(data.image, characterName, "jpg");
|
//filename should be character name + human readable timestamp + generation mode
|
||||||
|
const filename = `${characterName}_${humanizedDateTime()}`;
|
||||||
|
const base64Image = await saveBase64AsFile(data.image, characterName, filename, "jpg");
|
||||||
callback ? callback(prompt, base64Image) : sendMessage(prompt, base64Image);
|
callback ? callback(prompt, base64Image) : sendMessage(prompt, base64Image);
|
||||||
} else {
|
} else {
|
||||||
callPopup('Image generation has failed. Please try again.', 'text');
|
callPopup('Image generation has failed. Please try again.', 'text');
|
||||||
@ -740,8 +743,8 @@ async function generateHordeImage(prompt, prefix, characterName, callback) {
|
|||||||
|
|
||||||
if (result.ok) {
|
if (result.ok) {
|
||||||
const data = await result.text();
|
const data = await result.text();
|
||||||
|
const filename = `${characterName}_${humanizedDateTime()}`;
|
||||||
const base64Image = await saveBase64AsFile(data, characterName, "webp");
|
const base64Image = await saveBase64AsFile(data, characterName, filename, "webp");
|
||||||
callback ? callback(prompt, base64Image) : sendMessage(prompt, base64Image);
|
callback ? callback(prompt, base64Image) : sendMessage(prompt, base64Image);
|
||||||
} else {
|
} else {
|
||||||
toastr.error('Image generation has failed. Please try again.');
|
toastr.error('Image generation has failed. Please try again.');
|
||||||
|
@ -1169,15 +1169,18 @@ async function uploadGroupAvatar(event) {
|
|||||||
let thumbnail = await createThumbnail(croppedImage, 96, 144);
|
let thumbnail = await createThumbnail(croppedImage, 96, 144);
|
||||||
//remove data:image/whatever;base64
|
//remove data:image/whatever;base64
|
||||||
thumbnail = thumbnail.replace(/^data:image\/[a-z]+;base64,/, "");
|
thumbnail = thumbnail.replace(/^data:image\/[a-z]+;base64,/, "");
|
||||||
let thumbnailUrl = await saveBase64AsFile(thumbnail, openGroupId.toString(), 'jpg');
|
let _thisGroup = groups.find((x) => x.id == openGroupId);
|
||||||
|
// filename should be group id + human readable timestamp
|
||||||
|
const filename = `${_thisGroup.id}_${humanizedDateTime()}`;
|
||||||
|
let thumbnailUrl = await saveBase64AsFile(thumbnail, openGroupId.toString(), filename, 'jpg');
|
||||||
if (!openGroupId) {
|
if (!openGroupId) {
|
||||||
$('#group_avatar_preview img').attr('src', thumbnailUrl);
|
$('#group_avatar_preview img').attr('src', thumbnailUrl);
|
||||||
$('#rm_group_restore_avatar').show();
|
$('#rm_group_restore_avatar').show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let _thisGroup = groups.find((x) => x.id == openGroupId);
|
|
||||||
console.log(thumbnailUrl);
|
|
||||||
_thisGroup.avatar_url = thumbnailUrl;
|
_thisGroup.avatar_url = thumbnailUrl;
|
||||||
$("#group_avatar_preview").empty().append(getGroupAvatar(_thisGroup));
|
$("#group_avatar_preview").empty().append(getGroupAvatar(_thisGroup));
|
||||||
$("#rm_group_restore_avatar").show();
|
$("#rm_group_restore_avatar").show();
|
||||||
|
@ -565,7 +565,7 @@ export function extractDataFromPng(data, identifier = 'chara') {
|
|||||||
* @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.
|
* Rejects with an error if the upload fails.
|
||||||
*/
|
*/
|
||||||
export async function saveBase64AsFile(base64Data, characterName, ext) {
|
export async function saveBase64AsFile(base64Data, characterName, filename="", ext) {
|
||||||
// Construct the full data URL
|
// Construct the full data URL
|
||||||
const format = ext; // Extract the file extension (jpg, png, webp)
|
const format = ext; // Extract the file extension (jpg, png, webp)
|
||||||
const dataURL = `data:image/${format};base64,${base64Data}`;
|
const dataURL = `data:image/${format};base64,${base64Data}`;
|
||||||
@ -573,7 +573,8 @@ export async function saveBase64AsFile(base64Data, characterName, ext) {
|
|||||||
// Prepare the request body
|
// Prepare the request body
|
||||||
const requestBody = {
|
const requestBody = {
|
||||||
image: dataURL,
|
image: dataURL,
|
||||||
ch_name: characterName
|
ch_name: characterName,
|
||||||
|
filename: filename
|
||||||
};
|
};
|
||||||
|
|
||||||
// Send the data URL to your backend using fetch
|
// Send the data URL to your backend using fetch
|
||||||
|
@ -2655,7 +2655,11 @@ app.post('/uploadimage', jsonParser, async (request, response) => {
|
|||||||
const [, format, base64Data] = match;
|
const [, format, base64Data] = match;
|
||||||
|
|
||||||
// Constructing filename and path
|
// Constructing filename and path
|
||||||
const filename = `${Date.now()}.${format}`;
|
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
|
// if character is defined, save to a sub folder for that character
|
||||||
let pathToNewFile = path.join(directories.userImages, filename);
|
let pathToNewFile = path.join(directories.userImages, filename);
|
||||||
if(request.body.ch_name){
|
if(request.body.ch_name){
|
||||||
|
Reference in New Issue
Block a user