feat: increase upload limit to 50 and add svg support
This commit is contained in:
parent
d0c62d05a5
commit
dd0701cca4
@ -108,8 +108,8 @@ const upload = multer({
|
|||||||
},
|
},
|
||||||
fileFilter: function (req, file, cb) {
|
fileFilter: function (req, file, cb) {
|
||||||
// Accept images only
|
// Accept images only
|
||||||
if (!file.originalname.match(/\.(jpg|jpeg|png|gif|webp)$/)) {
|
if (!file.originalname.match(/\.(jpg|jpeg|png|gif|webp|svg)$/i)) {
|
||||||
return cb(new Error('Only image files are allowed!'), false);
|
return cb(new Error('Only image files (jpg, jpeg, png, gif, webp, svg) are allowed!'), false);
|
||||||
}
|
}
|
||||||
cb(null, true);
|
cb(null, true);
|
||||||
}
|
}
|
||||||
@ -649,7 +649,7 @@ app.post('/api/upload/single', upload.single('file'), async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Upload multiple files
|
// 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 {
|
try {
|
||||||
if (!req.files || req.files.length === 0) {
|
if (!req.files || req.files.length === 0) {
|
||||||
return res.status(400).json({
|
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
|
// 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 {
|
try {
|
||||||
const eventId = req.params.eventId;
|
const eventId = req.params.eventId;
|
||||||
|
|
||||||
|
|||||||
28
setup-db.js
28
setup-db.js
@ -13,7 +13,7 @@ async function setup() {
|
|||||||
|
|
||||||
console.log('Connected to MySQL...');
|
console.log('Connected to MySQL...');
|
||||||
|
|
||||||
// Create table
|
// Create admin_users table
|
||||||
await pool.execute(`
|
await pool.execute(`
|
||||||
CREATE TABLE IF NOT EXISTS admin_users (
|
CREATE TABLE IF NOT EXISTS admin_users (
|
||||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
@ -25,6 +25,32 @@ async function setup() {
|
|||||||
`);
|
`);
|
||||||
console.log('Verified admin_users table exists.');
|
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
|
// Check if admin user exists
|
||||||
const [rows] = await pool.execute('SELECT * FROM admin_users WHERE email = ?', ['admin@example.com']);
|
const [rows] = await pool.execute('SELECT * FROM admin_users WHERE email = ?', ['admin@example.com']);
|
||||||
|
|
||||||
|
|||||||
45
view-db.js
Normal file
45
view-db.js
Normal file
@ -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();
|
||||||
Loading…
x
Reference in New Issue
Block a user