From 8835720a85fcaf9765388ca7eca975b3d844a7dc Mon Sep 17 00:00:00 2001
From: 65160117 <65160117@go.buu.ac.th>
Date: Mon, 24 Mar 2025 11:01:07 +0000
Subject: [PATCH] Edit server.js

---
 server.js | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/server.js b/server.js
index 8dd972c..b88ad5b 100644
--- a/server.js
+++ b/server.js
@@ -18,22 +18,16 @@ app.use(express.static(path.join(__dirname, 'public')));
 // กำหนดการจัดเก็บไฟล์
 const storage = multer.diskStorage({
     destination: function (req, file, cb) {
-        const uploadDir = path.join(__dirname, 'public/uploads');
+        const uploadDir = 'public/uploads';
         // สร้างโฟลเดอร์ถ้ายังไม่มี
         if (!fs.existsSync(uploadDir)){
-            try {
-                fs.mkdirSync(uploadDir, { recursive: true });
-            } catch (err) {
-                console.error('Error creating upload directory:', err);
-                return cb(err);
-            }
+            fs.mkdirSync(uploadDir, { recursive: true });
         }
         cb(null, uploadDir);
     },
     filename: function (req, file, cb) {
         // สร้างชื่อไฟล์ใหม่เพื่อป้องกันการซ้ำ
-        const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9);
-        cb(null, uniqueSuffix + path.extname(file.originalname));
+        cb(null, Date.now() + path.extname(file.originalname));
     }
 });
 
-- 
GitLab