diff --git a/public/script.js b/public/script.js
index a664c12d2..1002e6359 100644
--- a/public/script.js
+++ b/public/script.js
@@ -9974,10 +9974,10 @@ jQuery(async function () {
const html = `
Enter the URL of the content to import
Supported sources:
- - Chub characters (direct link or id)
Example: Anonymous/example-character
- - Chub lorebooks (direct link or id)
Example: lorebooks/bartleby/example-lorebook
- - JanitorAI character (direct link or id)
Example: https://janitorai.com/characters/ddd1498a-a370-4136-b138-a8cd9461fdfe_character-aqua-the-useless-goddess
- - Pygmalion.chat character (link)
Example: https://pygmalion.chat/character/a7ca95a1-0c88-4e23-91b3-149db1e78ab9
+ - Chub Character (Direct Link or ID)
Example: Anonymous/example-character
+ - Chub Lorebook (Direct Link or ID)
Example: lorebooks/bartleby/example-lorebook
+ - JanitorAI Character (Direct Link or UUID)
Example: ddd1498a-a370-4136-b138-a8cd9461fdfe_character-aqua-the-useless-goddess
+ - Pygmalion.chat Character (Direct Link or UUID)
Example: a7ca95a1-0c88-4e23-91b3-149db1e78ab9
- More coming soon...
`;
const input = await callPopup(html, 'input', '', { okButton: 'Import', rows: 4 });
@@ -9988,13 +9988,23 @@ jQuery(async function () {
}
const url = input.trim();
- console.debug('Custom content import started', url);
+ var request;
- const request = await fetch('/api/content/import', {
- method: 'POST',
- headers: getRequestHeaders(),
- body: JSON.stringify({ url }),
- });
+ if (url.includes("https")) {
+ console.debug('Custom content import started for URL: ', url);
+ request = await fetch('/api/content/importURL', {
+ method: 'POST',
+ headers: getRequestHeaders(),
+ body: JSON.stringify({ url }),
+ });
+ } else {
+ console.debug('Custom content import started for Char UUID: ', url);
+ request = await fetch('/api/content/importUUID', {
+ method: 'POST',
+ headers: getRequestHeaders(),
+ body: JSON.stringify({ url }),
+ });
+ }
if (!request.ok) {
toastr.info(request.statusText, 'Custom content import failed');
diff --git a/src/endpoints/content-manager.js b/src/endpoints/content-manager.js
index 32877173d..ef18395ac 100644
--- a/src/endpoints/content-manager.js
+++ b/src/endpoints/content-manager.js
@@ -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,