Fix embedded WI being replaced with dummy object when importing a file from someone else's ST instance
This commit is contained in:
parent
241660087a
commit
bc0aee4212
|
@ -336,7 +336,7 @@ function charaFormatData(data) {
|
||||||
|
|
||||||
if (data.world) {
|
if (data.world) {
|
||||||
try {
|
try {
|
||||||
const file = readWorldInfoFile(data.world);
|
const file = readWorldInfoFile(data.world, false);
|
||||||
|
|
||||||
// File was imported - save it to the character book
|
// File was imported - save it to the character book
|
||||||
if (file && file.originalData) {
|
if (file && file.originalData) {
|
||||||
|
|
|
@ -7,8 +7,14 @@ const writeFileAtomicSync = require('write-file-atomic').sync;
|
||||||
const { jsonParser, urlencodedParser } = require('../express-common');
|
const { jsonParser, urlencodedParser } = require('../express-common');
|
||||||
const { DIRECTORIES, UPLOADS_PATH } = require('../constants');
|
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) {
|
if (!worldInfoName) {
|
||||||
return dummyObject;
|
return dummyObject;
|
||||||
|
@ -34,7 +40,7 @@ router.post('/get', jsonParser, (request, response) => {
|
||||||
return response.sendStatus(400);
|
return response.sendStatus(400);
|
||||||
}
|
}
|
||||||
|
|
||||||
const file = readWorldInfoFile(request.body.name);
|
const file = readWorldInfoFile(request.body.name, true);
|
||||||
|
|
||||||
return response.send(file);
|
return response.send(file);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue