Sanitized character bgm request.
This commit is contained in:
parent
9da9c73279
commit
017df860e5
|
@ -193,7 +193,7 @@ async function getCharacterBgmList(name) {
|
||||||
console.debug(DEBUG_PREFIX, "getting bgm list for", name);
|
console.debug(DEBUG_PREFIX, "getting bgm list for", name);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await fetch(`/get_character_assets_list?name=${encodeURIComponent(name)}&assetsFolder=${CHARACTER_BGM_FOLDER}`, {
|
const result = await fetch(`/get_character_assets_list?name=${encodeURIComponent(name)}&category=${CHARACTER_BGM_FOLDER}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: getRequestHeaders(),
|
headers: getRequestHeaders(),
|
||||||
});
|
});
|
||||||
|
|
26
server.js
26
server.js
|
@ -5117,10 +5117,23 @@ app.post('/asset_download', jsonParser, async (request, response) => {
|
||||||
*/
|
*/
|
||||||
app.post('/get_character_assets_list', jsonParser, async (request, response) => {
|
app.post('/get_character_assets_list', jsonParser, async (request, response) => {
|
||||||
const name = request.query.name;
|
const name = request.query.name;
|
||||||
const assetsFolder = request.query.assetsFolder
|
const inputCategory = request.query.category;
|
||||||
const folderPath = path.join(directories.characters, name, assetsFolder);
|
const validCategories = ["bgm","ambient"]
|
||||||
let output = [];
|
|
||||||
|
// Check category
|
||||||
|
let category = null
|
||||||
|
for(i of validCategories)
|
||||||
|
if (i == inputCategory)
|
||||||
|
category = i
|
||||||
|
|
||||||
|
if (category === null) {
|
||||||
|
console.debug("Bad request: unsuported asset category.");
|
||||||
|
return response.sendStatus(400);
|
||||||
|
}
|
||||||
|
|
||||||
|
const folderPath = path.join(directories.characters, name, category);
|
||||||
|
|
||||||
|
let output = [];
|
||||||
try {
|
try {
|
||||||
if (fs.existsSync(folderPath) && fs.statSync(folderPath).isDirectory()) {
|
if (fs.existsSync(folderPath) && fs.statSync(folderPath).isDirectory()) {
|
||||||
const files = fs.readdirSync(folderPath)
|
const files = fs.readdirSync(folderPath)
|
||||||
|
@ -5129,13 +5142,16 @@ app.post('/get_character_assets_list', jsonParser, async (request, response) =>
|
||||||
});
|
});
|
||||||
|
|
||||||
for (i of files)
|
for (i of files)
|
||||||
output.push(`/characters/${name}/${assetsFolder}/${i}`);
|
output.push(`/characters/${name}/${category}/${i}`);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
return response.send(output);
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
return response.sendStatus(500);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
return response.send(output);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
Loading…
Reference in New Issue