Fix embedded WI being replaced with dummy object when importing a file from someone else's ST instance

This commit is contained in:
Cohee 2024-01-08 20:15:43 +02:00
parent 241660087a
commit bc0aee4212
2 changed files with 10 additions and 4 deletions

View File

@ -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) {

View File

@ -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);
});