mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
feat: add importUUID
API to get Pyg/Janny/Chub bots without link
This commit is contained in:
@ -357,7 +357,7 @@ function getUuidFromUrl(url) {
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.post('/import', jsonParser, async (request, response) => {
|
||||
router.post('/importURL', jsonParser, async (request, response) => {
|
||||
if (!request.body.url) {
|
||||
return response.sendStatus(400);
|
||||
}
|
||||
@ -413,6 +413,50 @@ router.post('/import', jsonParser, async (request, response) => {
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/importUUID', jsonParser, async (request, response) => {
|
||||
if (!request.body.url) {
|
||||
return response.sendStatus(400);
|
||||
}
|
||||
|
||||
try {
|
||||
const uuid = request.body.url;
|
||||
let result;
|
||||
|
||||
const isJannny = uuid.includes("_character")
|
||||
const isPygmalion = (!isJannny && uuid.length == 36)
|
||||
const uuidType = uuid.includes("lorebook") ? "lorebook" : "character";
|
||||
|
||||
if (isPygmalion) {
|
||||
console.debug("We have a Pyg character")
|
||||
result = await downloadPygmalionCharacter(uuid);
|
||||
} else if (isJannny) {
|
||||
console.debug("We have a Janny character")
|
||||
result = await downloadJannyCharacter(uuid.split("_")[0]);
|
||||
} else {
|
||||
console.debug("We have something from Chub?")
|
||||
if (uuidType === 'character') {
|
||||
console.log('Downloading chub character:', uuid);
|
||||
result = await downloadChubCharacter(uuid);
|
||||
}
|
||||
else if (uuidType === 'lorebook') {
|
||||
console.log('Downloading chub lorebook:', uuid);
|
||||
result = await downloadChubLorebook(uuid);
|
||||
}
|
||||
else {
|
||||
return response.sendStatus(404);
|
||||
}
|
||||
}
|
||||
|
||||
if (result.fileType) response.set('Content-Type', result.fileType);
|
||||
response.set('Content-Disposition', `attachment; filename="${result.fileName}"`);
|
||||
response.set('X-Custom-Content-Type', uuidType);
|
||||
return response.send(result.buffer);
|
||||
} catch (error) {
|
||||
console.log('Importing custom content failed', error);
|
||||
return response.sendStatus(500);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
checkForNewContent,
|
||||
getDefaultPresets,
|
||||
|
Reference in New Issue
Block a user