From 65530963d7b30eea4ff188fcff809795e15afff3 Mon Sep 17 00:00:00 2001 From: leca Date: Sun, 6 Jul 2025 17:55:56 +0300 Subject: [PATCH] fixed file saving in capes/skins, install dependencies early for faster rebuils --- Dockerfile | 8 ++++++-- src/controllers/user.js | 23 +++++++++++++++-------- src/routers/api.js | 7 ++++--- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 45ef147..05a7a53 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,12 @@ FROM node:22-bullseye WORKDIR /opt/mcserver -COPY . . +COPY package.json package.json +COPY package-lock.json package-lock.json + RUN npm i +COPY . . + EXPOSE 3000 -ENTRYPOINT ["node", "./src/index.js"] \ No newline at end of file +ENTRYPOINT ["node", "./src/index.js"] diff --git a/src/controllers/user.js b/src/controllers/user.js index 9153a0d..ae5fe4c 100644 --- a/src/controllers/user.js +++ b/src/controllers/user.js @@ -1,3 +1,5 @@ + + import bcrypt from 'bcrypt'; import jwt from 'jsonwebtoken'; import path from 'path'; @@ -86,10 +88,12 @@ class UserController { if (image.bitmap.width != 64 || image.bitmap.height != 64) { return res.status(400).send('This does not look like a minecraft skin.'); } - - fs.renameSync(tempPath, targetPath, err => { - if (err) return res.status(500).send("Ooops! Something went wrong! Please, report to the developer."); - }); + try { + 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("Skin uploaded!"); } @@ -108,9 +112,12 @@ class UserController { return res.status(400).send('This does not look like a minecraft cape.'); } - fs.renameSync(tempPath, targetPath, err => { - if (err) return res.status(500).send("Ooops! Something went wrong! Please, report to the developer."); - }); + try { + 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!"); } @@ -121,4 +128,4 @@ class UserController { } } -export default new UserController(); \ No newline at end of file +export default new UserController(); diff --git a/src/routers/api.js b/src/routers/api.js index 4f7e088..bd3c3ab 100644 --- a/src/routers/api.js +++ b/src/routers/api.js @@ -20,8 +20,9 @@ ApiRouter.post('/uploadCape', existance.userExist, auth.authenticate, auth.canHa ApiRouter.get('/getUsername', existance.userExist, auth.authenticate, UserController.getUsername); 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('/capesUrl', auth.authenticate, ApiController.getCapesUrl) -export default ApiRouter; \ No newline at end of file +ApiRouter.get('/capesUrl', auth.authenticate, ApiController.getCapesUrl); + +export default ApiRouter;