mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Move missed endpoints
This commit is contained in:
74
server.js
74
server.js
@ -2701,64 +2701,6 @@ app.post('/deletegroup', jsonParser, async (request, response) => {
|
||||
return response.send({ ok: true });
|
||||
});
|
||||
|
||||
/**
|
||||
* Gets the path to the sprites folder for the provided character name
|
||||
* @param {string} name - The name of the character
|
||||
* @param {boolean} isSubfolder - Whether the name contains a subfolder
|
||||
* @returns {string | null} The path to the sprites folder. Null if the name is invalid.
|
||||
*/
|
||||
function getSpritesPath(name, isSubfolder) {
|
||||
if (isSubfolder) {
|
||||
const nameParts = name.split('/');
|
||||
const characterName = sanitize(nameParts[0]);
|
||||
const subfolderName = sanitize(nameParts[1]);
|
||||
|
||||
if (!characterName || !subfolderName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return path.join(DIRECTORIES.characters, characterName, subfolderName);
|
||||
}
|
||||
|
||||
name = sanitize(name);
|
||||
|
||||
if (!name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return path.join(DIRECTORIES.characters, name);
|
||||
}
|
||||
|
||||
app.get('/get_sprites', jsonParser, function (request, response) {
|
||||
const name = String(request.query.name);
|
||||
const isSubfolder = name.includes('/');
|
||||
const spritesPath = getSpritesPath(name, isSubfolder);
|
||||
let sprites = [];
|
||||
|
||||
try {
|
||||
if (spritesPath && fs.existsSync(spritesPath) && fs.statSync(spritesPath).isDirectory()) {
|
||||
sprites = fs.readdirSync(spritesPath)
|
||||
.filter(file => {
|
||||
const mimeType = mime.lookup(file);
|
||||
return mimeType && mimeType.startsWith('image/');
|
||||
})
|
||||
.map((file) => {
|
||||
const pathToSprite = path.join(spritesPath, file);
|
||||
return {
|
||||
label: path.parse(pathToSprite).name.toLowerCase(),
|
||||
path: `/characters/${name}/${file}`,
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
finally {
|
||||
return response.send(sprites);
|
||||
}
|
||||
});
|
||||
|
||||
function cleanUploads() {
|
||||
try {
|
||||
if (fs.existsSync(UPLOADS_PATH)) {
|
||||
@ -2880,22 +2822,6 @@ app.post("/openai_bias", jsonParser, async function (request, response) {
|
||||
return response.send(result);
|
||||
});
|
||||
|
||||
app.post("/deletepreset_openai", jsonParser, function (request, response) {
|
||||
if (!request.body || !request.body.name) {
|
||||
return response.sendStatus(400);
|
||||
}
|
||||
|
||||
const name = request.body.name;
|
||||
const pathToFile = path.join(DIRECTORIES.openAI_Settings, `${name}.settings`);
|
||||
|
||||
if (fs.existsSync(pathToFile)) {
|
||||
fs.rmSync(pathToFile);
|
||||
return response.send({ ok: true });
|
||||
}
|
||||
|
||||
return response.send({ error: true });
|
||||
});
|
||||
|
||||
function convertChatMLPrompt(messages) {
|
||||
const messageStrings = [];
|
||||
messages.forEach(m => {
|
||||
|
Reference in New Issue
Block a user