diff --git a/server.js b/server.js index 94e8118..cd10fb2 100644 --- a/server.js +++ b/server.js @@ -108,8 +108,8 @@ const upload = multer({ }, fileFilter: function (req, file, cb) { // Accept images only - if (!file.originalname.match(/\.(jpg|jpeg|png|gif|webp)$/)) { - return cb(new Error('Only image files are allowed!'), false); + if (!file.originalname.match(/\.(jpg|jpeg|png|gif|webp|svg)$/i)) { + return cb(new Error('Only image files (jpg, jpeg, png, gif, webp, svg) are allowed!'), false); } cb(null, true); } @@ -649,7 +649,7 @@ app.post('/api/upload/single', upload.single('file'), async (req, res) => { }); // Upload multiple files -app.post('/api/upload/multiple', upload.array('files', 10), async (req, res) => { +app.post('/api/upload/multiple', upload.array('files', 50), async (req, res) => { try { if (!req.files || req.files.length === 0) { return res.status(400).json({ @@ -686,7 +686,7 @@ app.post('/api/upload/multiple', upload.array('files', 10), async (req, res) => }); // Upload and save to event_images table -app.post('/api/upload/event-images/:eventId', upload.array('files', 10), async (req, res) => { +app.post('/api/upload/event-images/:eventId', upload.array('files', 50), async (req, res) => { try { const eventId = req.params.eventId; diff --git a/setup-db.js b/setup-db.js index 328be9d..6ef4d3d 100644 --- a/setup-db.js +++ b/setup-db.js @@ -13,7 +13,7 @@ async function setup() { console.log('Connected to MySQL...'); - // Create table + // Create admin_users table await pool.execute(` CREATE TABLE IF NOT EXISTS admin_users ( id INT AUTO_INCREMENT PRIMARY KEY, @@ -25,6 +25,32 @@ async function setup() { `); console.log('Verified admin_users table exists.'); + // Create events table + await pool.execute(` + CREATE TABLE IF NOT EXISTS events ( + id INT AUTO_INCREMENT PRIMARY KEY, + year INT NOT NULL, + eventdate VARCHAR(100), + eventtitle VARCHAR(255) NOT NULL, + eventimageurl TEXT, + eventdescription TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + ) + `); + console.log('Verified events table exists.'); + + // Create event_images table + await pool.execute(` + CREATE TABLE IF NOT EXISTS event_images ( + id INT AUTO_INCREMENT PRIMARY KEY, + eventid INT, + imageurl TEXT NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (eventid) REFERENCES events(id) ON DELETE CASCADE + ) + `); + console.log('Verified event_images table exists.'); + // Check if admin user exists const [rows] = await pool.execute('SELECT * FROM admin_users WHERE email = ?', ['admin@example.com']); diff --git a/view-db.js b/view-db.js new file mode 100644 index 0000000..b17c5b9 --- /dev/null +++ b/view-db.js @@ -0,0 +1,45 @@ +const mysql = require('mysql2/promise'); +require('dotenv').config(); + +async function viewDB() { + try { + const pool = mysql.createPool({ + host: process.env.DB_HOST, + user: process.env.DB_USER, + password: process.env.DB_PASSWORD, + database: process.env.DB_NAME, + }); + + console.log('\n--- Database: ' + process.env.DB_NAME + ' ---\n'); + + // List Tables + const [tables] = await pool.execute('SHOW TABLES'); + const tableNames = tables.map(t => Object.values(t)[0]); + + if (tableNames.length === 0) { + console.log('No tables found in database.'); + } else { + console.log('Tables found:', tableNames.join(', ')); + console.log('\n-----------------------------------\n'); + + for (const tableName of tableNames) { + console.log(`Table: ${tableName}`); + const [rows] = await pool.execute(`SELECT * FROM ${tableName} LIMIT 10`); + if (rows.length === 0) { + console.log(' (Empty table)'); + } else { + console.table(rows); + } + console.log('\n'); + } + } + + await pool.end(); + process.exit(0); + } catch (err) { + console.error('Error viewing DB:', err); + process.exit(1); + } +} + +viewDB();