moved skins&capes target paths to config

This commit is contained in:
leca 2025-02-19 17:21:35 +03:00
parent c282c6b597
commit a805cb77fc
3 changed files with 17 additions and 5 deletions

View File

@ -20,3 +20,11 @@ WS_CONNECTION_STRING=ws://localhost:3000
#Map #Map
ENABLE_WORLDMAP=false ENABLE_WORLDMAP=false
WORLDMAP_URL=http://localhost/map WORLDMAP_URL=http://localhost/map
#Skins
SKINS_TARGET_DIRECTORY=/opt/skins
SKINS_URL=https://launcher.foxarmy.org/skins/%username%.png
#Capes
CAPES_TARGET_DIRECTORY=/opt/cloaks
CAPES_URL=https://launcher.foxarmy.org/cloaks/%username%.png

View File

@ -21,7 +21,13 @@ const config = {
ws_connection_string: process.env.WS_CONNECTION_STRING, ws_connection_string: process.env.WS_CONNECTION_STRING,
enable_worldmap: getBoolean(process.env.ENABLE_WORLDMAP), enable_worldmap: getBoolean(process.env.ENABLE_WORLDMAP),
worldmap_url: process.env.WORLDMAP_URL worldmap_url: process.env.WORLDMAP_URL,
skins_target_directory: process.env.SKINS_TARGET_DIRECTORY,
skins_url: process.env.SKINS_URL,
capes_target_directory: process.env.CAPES_TARGET_DIRECTORY,
capes_url: process.env.CAPES_URL
} }
export default config; export default config;

View File

@ -76,13 +76,12 @@ class UserController {
const token = req.cookies["jwt"]; const token = req.cookies["jwt"];
const decoded = jwt.decode(token); const decoded = jwt.decode(token);
const tempPath = req.file.path; const tempPath = req.file.path;
const targetPath = `/opt/skins/${decoded.username}.png`; const targetPath = config.skins_target_directory + `/${decoded.username}.png`;
if (path.extname(req.file.originalname).toLowerCase() !== ".png") { if (path.extname(req.file.originalname).toLowerCase() !== ".png") {
return res.status(400).send("Only .png files are allowed!"); return res.status(400).send("Only .png files are allowed!");
} }
const image = await Jimp.read(tempPath); const image = await Jimp.read(tempPath);
if (image.bitmap.width != 64 || image.bitmap.height != 64) { if (image.bitmap.width != 64 || image.bitmap.height != 64) {
return res.status(400).send('This does not look like a minecraft skin.'); return res.status(400).send('This does not look like a minecraft skin.');
@ -98,13 +97,12 @@ class UserController {
const token = req.cookies["jwt"]; const token = req.cookies["jwt"];
const decoded = jwt.decode(token); const decoded = jwt.decode(token);
const tempPath = req.file.path; const tempPath = req.file.path;
const targetPath = `/opt/cloaks/${decoded.username}.png`; const targetPath = config.capes_target_directory + `/${decoded.username}.png`;
if (path.extname(req.file.originalname).toLowerCase() !== ".png") { if (path.extname(req.file.originalname).toLowerCase() !== ".png") {
return res.status(400).send("Only .png files are allowed!"); return res.status(400).send("Only .png files are allowed!");
} }
const image = await Jimp.read(tempPath); const image = await Jimp.read(tempPath);
if ((image.bitmap.width != 64 || image.bitmap.height != 32) && (image.bitmap.width != 128 || image.bitmap.height != 64)) { if ((image.bitmap.width != 64 || image.bitmap.height != 32) && (image.bitmap.width != 128 || image.bitmap.height != 64)) {
return res.status(400).send('This does not look like a minecraft cape.'); return res.status(400).send('This does not look like a minecraft cape.');