mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge remote-tracking branch 'upstream/staging' into staging
This commit is contained in:
@@ -22,8 +22,25 @@ const { importRisuSprites } = require('./sprites');
|
||||
|
||||
let characters = {};
|
||||
|
||||
// KV-store for parsed character data
|
||||
const characterDataCache = new Map();
|
||||
|
||||
/**
|
||||
* Reads the character card from the specified image file.
|
||||
* @param {string} img_url - Path to the image file
|
||||
* @param {string} input_format - 'png'
|
||||
* @returns {Promise<string | undefined>} - Character card data
|
||||
*/
|
||||
async function charaRead(img_url, input_format) {
|
||||
return characterCardParser.parse(img_url, input_format);
|
||||
const stat = fs.statSync(img_url);
|
||||
const cacheKey = `${img_url}-${stat.mtimeMs}`;
|
||||
if (characterDataCache.has(cacheKey)) {
|
||||
return characterDataCache.get(cacheKey);
|
||||
}
|
||||
|
||||
const result = characterCardParser.parse(img_url, input_format);
|
||||
characterDataCache.set(cacheKey, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,6 +49,13 @@ async function charaRead(img_url, input_format) {
|
||||
*/
|
||||
async function charaWrite(img_url, data, target_img, response = undefined, mes = 'ok', crop = undefined) {
|
||||
try {
|
||||
// Reset the cache
|
||||
for (const key of characterDataCache.keys()) {
|
||||
if (key.startsWith(img_url)) {
|
||||
characterDataCache.delete(key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Read the image, resize, and save it as a PNG into the buffer
|
||||
const image = await tryReadImage(img_url, crop);
|
||||
|
||||
|
@@ -10,9 +10,9 @@ const { DIRECTORIES, UPLOADS_PATH } = require('../constants');
|
||||
const { getConfigValue, humanizedISO8601DateTime, tryParse, generateTimestamp, removeOldBackups } = require('../util');
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} name
|
||||
* @param {string} chat
|
||||
* Saves a chat to the backups directory.
|
||||
* @param {string} name The name of the chat.
|
||||
* @param {string} chat The serialized chat to save.
|
||||
*/
|
||||
function backupChat(name, chat) {
|
||||
try {
|
||||
@@ -65,7 +65,6 @@ router.post('/get', jsonParser, function (request, response) {
|
||||
return response.send({});
|
||||
}
|
||||
|
||||
|
||||
if (!request.body.file_name) {
|
||||
return response.send({});
|
||||
}
|
||||
@@ -140,7 +139,6 @@ router.post('/delete', jsonParser, function (request, response) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
return response.send('ok');
|
||||
});
|
||||
|
||||
@@ -190,6 +188,10 @@ router.post('/export', jsonParser, async function (request, response) {
|
||||
let buffer = '';
|
||||
rl.on('line', (line) => {
|
||||
const data = JSON.parse(line);
|
||||
// Skip non-printable/prompt-hidden messages
|
||||
if (data.is_system) {
|
||||
return;
|
||||
}
|
||||
if (data.mes) {
|
||||
const name = data.name;
|
||||
const message = (data?.extra?.display_text || data?.mes || '').replace(/\r?\n/g, '\n');
|
||||
|
Reference in New Issue
Block a user