From bc0aee42125c85df2af7b380e767f142aeae765a Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Mon, 8 Jan 2024 20:15:43 +0200 Subject: [PATCH] Fix embedded WI being replaced with dummy object when importing a file from someone else's ST instance --- src/endpoints/characters.js | 2 +- src/endpoints/worldinfo.js | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/endpoints/characters.js b/src/endpoints/characters.js index 1b5fd8528..05ef210de 100644 --- a/src/endpoints/characters.js +++ b/src/endpoints/characters.js @@ -336,7 +336,7 @@ function charaFormatData(data) { if (data.world) { try { - const file = readWorldInfoFile(data.world); + const file = readWorldInfoFile(data.world, false); // File was imported - save it to the character book if (file && file.originalData) { diff --git a/src/endpoints/worldinfo.js b/src/endpoints/worldinfo.js index 16a1db8eb..19c67c157 100644 --- a/src/endpoints/worldinfo.js +++ b/src/endpoints/worldinfo.js @@ -7,8 +7,14 @@ const writeFileAtomicSync = require('write-file-atomic').sync; const { jsonParser, urlencodedParser } = require('../express-common'); const { DIRECTORIES, UPLOADS_PATH } = require('../constants'); -function readWorldInfoFile(worldInfoName) { - const dummyObject = { entries: {} }; +/** + * Reads a World Info file and returns its contents + * @param {string} worldInfoName Name of the World Info file + * @param {boolean} allowDummy If true, returns an empty object if the file doesn't exist + * @returns {object} World Info file contents + */ +function readWorldInfoFile(worldInfoName, allowDummy) { + const dummyObject = allowDummy ? { entries: {} } : null; if (!worldInfoName) { return dummyObject; @@ -34,7 +40,7 @@ router.post('/get', jsonParser, (request, response) => { return response.sendStatus(400); } - const file = readWorldInfoFile(request.body.name); + const file = readWorldInfoFile(request.body.name, true); return response.send(file); });