From d6490c2d5a264b7dea65a3a607fd290189369485 Mon Sep 17 00:00:00 2001
From: 65160258 <65160258@go.buu.ac.th>
Date: Mon, 24 Mar 2025 11:13:20 +0700
Subject: [PATCH] del Multer

---
 routes/posts.js | 47 ++++++++++++++++++++++++-----------------------
 1 file changed, 24 insertions(+), 23 deletions(-)

diff --git a/routes/posts.js b/routes/posts.js
index 7869aa1..57c71e8 100644
--- a/routes/posts.js
+++ b/routes/posts.js
@@ -145,29 +145,30 @@ router.get('/:id', async (req, res) => {
   });
   
   // ตั้งค่า Storage สำหรับ Multer
-const storage = multer.diskStorage({
-    destination: (req, file, cb) => {
-      cb(null, 'public/uploads/'); // เก็บไฟล์ไว้ที่โฟลเดอร์ public/uploads/
-    },
-    filename: (req, file, cb) => {
-      cb(null, Date.now() + path.extname(file.originalname)); // ตั้งชื่อไฟล์ให้ไม่ซ้ำกัน
-    }
-  });
+// const storage = multer.diskStorage({
+//     destination: (req, file, cb) => {
+//       cb(null, 'public/uploads/'); // เก็บไฟล์ไว้ที่โฟลเดอร์ public/uploads/
+//     },
+//     filename: (req, file, cb) => {
+//       cb(null, Date.now() + path.extname(file.originalname)); // ตั้งชื่อไฟล์ให้ไม่ซ้ำกัน
+//     }
+//   });
   
-  // กำหนดเงื่อนไขการอัปโหลดไฟล์
-  const upload = multer({
-    storage: storage,
-    limits: { fileSize: 5 * 1024 * 1024 }, // จำกัดขนาด 5MB
-    fileFilter: (req, file, cb) => {
-      const fileTypes = /jpeg|jpg|png|gif/;
-      const extName = fileTypes.test(path.extname(file.originalname).toLowerCase());
-      const mimeType = fileTypes.test(file.mimetype);
+//   // กำหนดเงื่อนไขการอัปโหลดไฟล์
+//   const upload = multer({
+//     storage: storage,
+//     limits: { fileSize: 5 * 1024 * 1024 }, // จำกัดขนาด 5MB
+//     fileFilter: (req, file, cb) => {
+//       const fileTypes = /jpeg|jpg|png|gif/;
+//       const extName = fileTypes.test(path.extname(file.originalname).toLowerCase());
+//       const mimeType = fileTypes.test(file.mimetype);
   
-      if (extName && mimeType) {
-        return cb(null, true);
-      } else {
-        return cb(new Error('Only images are allowed!'));
-      }
-    }
-  });
+//       if (extName && mimeType) {
+//         return cb(null, true);
+//       } else {
+//         return cb(new Error('Only images are allowed!'));
+//       }
+//     }
+//   });
+
 module.exports = router;
-- 
GitLab