fixed file saving in capes/skins, install dependencies early for faster rebuils

This commit is contained in:
leca 2025-07-06 17:55:56 +03:00
parent cccaf58ec3
commit 65530963d7
3 changed files with 25 additions and 13 deletions

View File

@ -2,8 +2,12 @@ FROM node:22-bullseye
WORKDIR /opt/mcserver WORKDIR /opt/mcserver
COPY . . COPY package.json package.json
COPY package-lock.json package-lock.json
RUN npm i RUN npm i
COPY . .
EXPOSE 3000 EXPOSE 3000
ENTRYPOINT ["node", "./src/index.js"] ENTRYPOINT ["node", "./src/index.js"]

View File

@ -1,3 +1,5 @@
import bcrypt from 'bcrypt'; import bcrypt from 'bcrypt';
import jwt from 'jsonwebtoken'; import jwt from 'jsonwebtoken';
import path from 'path'; import path from 'path';
@ -86,10 +88,12 @@ class UserController {
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.');
} }
try {
fs.renameSync(tempPath, targetPath, err => { await fs.promises.cp(tempPath, targetPath);
if (err) return res.status(500).send("Ooops! Something went wrong! Please, report to the developer."); await fs.promises.unlink(tempPath);
}); } catch (err) {
return res.status(500).send("Ooops! Something went wrong! Please, report to the developer.");
}
return res.status(200).send("Skin uploaded!"); return res.status(200).send("Skin uploaded!");
} }
@ -108,9 +112,12 @@ class UserController {
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.');
} }
fs.renameSync(tempPath, targetPath, err => { try {
if (err) return res.status(500).send("Ooops! Something went wrong! Please, report to the developer."); await fs.promises.cp(tempPath, targetPath);
}); await fs.promises.unlink(tempPath);
} catch (err) {
return res.status(500).send("Ooops! Something went wrong! Please, report to the developer.");
}
return res.status(200).send("Cape uploaded!"); return res.status(200).send("Cape uploaded!");
} }

View File

@ -20,8 +20,9 @@ ApiRouter.post('/uploadCape', existance.userExist, auth.authenticate, auth.canHa
ApiRouter.get('/getUsername', existance.userExist, auth.authenticate, UserController.getUsername); ApiRouter.get('/getUsername', existance.userExist, auth.authenticate, UserController.getUsername);
ApiRouter.get('/getChatMessages/:offset/:limit', auth.authenticate, ApiController.getChatMessages); ApiRouter.get('/getChatMessages/:offset/:limit', auth.authenticate, ApiController.getChatMessages);
ApiRouter.get('/webSocketConnection', auth.authenticate, ApiController.getWebsocketConnection) ApiRouter.get('/webSocketConnection', auth.authenticate, ApiController.getWebsocketConnection);
ApiRouter.get('/skinsUrl', auth.authenticate, ApiController.getSkinsUrl); ApiRouter.get('/skinsUrl', auth.authenticate, ApiController.getSkinsUrl);
ApiRouter.get('/capesUrl', auth.authenticate, ApiController.getCapesUrl) ApiRouter.get('/capesUrl', auth.authenticate, ApiController.getCapesUrl);
export default ApiRouter; export default ApiRouter;