feat: add importUUID API to get Pyg/Janny/Chub bots without link

This commit is contained in:
Bronya-Rand
2024-03-03 03:31:39 +00:00
parent 181657cede
commit 668d1f0fb9
2 changed files with 65 additions and 11 deletions

View File

@ -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,