Software: Apache. PHP/8.1.30 uname -a: Linux server1.tuhinhossain.com 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC uid=1002(picotech) gid=1003(picotech) groups=1003(picotech),0(root) Safe-mode: OFF (not secure) /home/picotech/domains/rentals.picotech.app/public_html/server/routes/ drwxr-xr-x |
Viewing file: Select action/file-type: import express from 'express'; import path from 'path'; import fs from 'fs'; import { fileURLToPath } from 'url'; import { auth } from '../middleware/auth.js'; import upload from '../middleware/upload.js'; import { RenterDocument } from '../models/index.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const router = express.Router(); // Upload file for renter router.post('/renter/:renterId/:type', auth, upload.single('file'), async (req, res) => { try { if (!req.file) { return res.status(400).json({ message: 'No file uploaded' }); } const { renterId, type } = req.params; const { description } = req.body; const document = await RenterDocument.create({ renter_id: renterId, type, file_name: req.file.originalname, file_url: `/uploads/${type}/${req.file.filename}`, file_size: req.file.size, mime_type: req.file.mimetype, description }); res.status(201).json(document); } catch (error) { console.error('Upload error:', error); res.status(500).json({ message: 'Server error' }); } }); // Delete uploaded file router.delete('/document/:id', auth, async (req, res) => { try { const document = await RenterDocument.findByPk(req.params.id); if (!document) { return res.status(404).json({ message: 'Document not found' }); } // Delete file from filesystem const filePath = path.join(__dirname, '../../uploads', document.file_url.replace('/uploads/', '')); if (fs.existsSync(filePath)) { fs.unlinkSync(filePath); } await document.destroy(); res.json({ message: 'Document deleted successfully' }); } catch (error) { console.error('Delete document error:', error); res.status(500).json({ message: 'Server error' }); } }); // Serve uploaded files router.get('/:type/:filename', (req, res) => { const { type, filename } = req.params; const filePath = path.join(__dirname, '../../uploads', type, filename); if (fs.existsSync(filePath)) { res.sendFile(filePath); } else { res.status(404).json({ message: 'File not found' }); } }); export default router; |
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0048 ]-- |