From 33fca2564e78076593697e2de03cc2429d318dbb Mon Sep 17 00:00:00 2001 From: slawk0 Date: Thu, 21 Nov 2024 22:44:15 +0100 Subject: [PATCH] fixed file naming --- client/src/components/chat/FIleBox.tsx | 2 +- server/.env | 2 +- server/db/db.js | 2 +- server/server.js | 6 ++++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/client/src/components/chat/FIleBox.tsx b/client/src/components/chat/FIleBox.tsx index 5f5f11d..ac4ff8e 100644 --- a/client/src/components/chat/FIleBox.tsx +++ b/client/src/components/chat/FIleBox.tsx @@ -1,6 +1,6 @@ import { File } from 'lucide-react'; const FileBox = ({ url }: { url: string }) => { - const fileNameWithSuffix = url.split('/').pop(); // 'attachment.pdf-321321321312312' + const fileNameWithSuffix = url.split('/').pop(); const fullFileName = fileNameWithSuffix?.replace(/-\d+$/, ''); const filename = fullFileName?.slice(0, 25) + '...'; diff --git a/server/.env b/server/.env index 111441d..aebc714 100644 --- a/server/.env +++ b/server/.env @@ -5,7 +5,7 @@ SERVER_PORT=3000 #DO NOT CHANGE JWT_SECRET=fdsfsdfds@ ORIGIN=http://localhost:5173 +PG_HOST=192.168.0.47 PG_USER=postgres PG_PASSWORD=haslo PG_DATABASE=relay -PG_HOST=192.168.0.47 \ No newline at end of file diff --git a/server/db/db.js b/server/db/db.js index fd16ce6..abc8768 100644 --- a/server/db/db.js +++ b/server/db/db.js @@ -6,7 +6,7 @@ const client = new Client({ password: process.env.PG_PASSWORD, database: process.env.PG_DATABASE, host: process.env.PG_HOST, - port: 5432, + port: 5433, }); client diff --git a/server/server.js b/server/server.js index 4c4b17f..20e0076 100644 --- a/server/server.js +++ b/server/server.js @@ -55,9 +55,11 @@ const storage = multer.diskStorage({ }, filename: function (req, file, cb) { const uniqueSuffix = Date.now() + "-" + Math.round(Math.random() * 1e9); - const extension = extname(file.originalname); + const extension = extname(file.originalname).toString(); + const originalName = file.originalname; + const filename = originalName?.substring(0, originalName.lastIndexOf(".")); //const finalName = uniqueSuffix + extension; - const finalName = `${file.originalname}-${Math.round(Math.random() * 1e9)}`; + const finalName = `${filename}-${Math.round(Math.random() * 1e9)}${extension}`; file.finalName = finalName; cb(null, finalName); },