From 7fbef328697576f0512278b5fa8fe4a26af7c5dd Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 16 Feb 2024 20:24:06 +0200 Subject: [PATCH] Use uuid extraction from Pygsite URL --- src/endpoints/content-manager.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/endpoints/content-manager.js b/src/endpoints/content-manager.js index 2cd2d9ce6..2f9812270 100644 --- a/src/endpoints/content-manager.js +++ b/src/endpoints/content-manager.js @@ -234,7 +234,7 @@ async function downloadPygmalionCharacter(id) { if (!result.ok) { const text = await result.text(); - console.log('Pygsite returned error', result.statusText, text); + console.log('Pygsite returned error', result.status, text); throw new Error('Failed to download character'); } @@ -264,7 +264,7 @@ async function downloadPygmalionCharacter(id) { fileName: `${sanitize(id)}.png`, fileType: 'image/png', }; - } catch(e) { + } catch (e) { console.error('Failed to download avatar, using JSON instead', e); return { buffer: Buffer.from(JSON.stringify(jsonData)), @@ -349,7 +349,7 @@ async function downloadJannyCharacter(uuid) { * @param {String} url * @returns {String | null } UUID of the character */ -function parseJannyUrl(url) { +function getUuidFromUrl(url) { // Extract UUID from URL const uuidRegex = /[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/; const matches = url.match(uuidRegex); @@ -375,7 +375,7 @@ router.post('/import', jsonParser, async (request, response) => { const isPygmalionContent = url.includes('pygmalion.chat'); if (isPygmalionContent) { - const uuid = url.split('/').pop(); + const uuid = getUuidFromUrl(url); if (!uuid) { return response.sendStatus(404); } @@ -383,7 +383,7 @@ router.post('/import', jsonParser, async (request, response) => { type = 'character'; result = await downloadPygmalionCharacter(uuid); } else if (isJannnyContent) { - const uuid = parseJannyUrl(url); + const uuid = getUuidFromUrl(url); if (!uuid) { return response.sendStatus(404); }