const express = require('express');
const router = express.Router();
const multer = require('multer');
const upload = multer({ storage: multer.memoryStorage() });

const { uploadFile, saveFileDetails, getFiles, getFilesByPage, getFileById, getFileByHash, downloadFile, updateFile } = require('../controllers/fileController');
const authMiddleware = require('../middleware/authMiddleware');

router.post('/', authMiddleware, upload.single('file'), uploadFile, saveFileDetails);
router.get('/', authMiddleware, getFiles);
router.get('/page/:pageId', getFilesByPage);
router.get('/:id', getFileById);
router.get('/hash/:hash', getFileByHash);
router.get('/download/:hash', downloadFile); 
router.put('/:id', authMiddleware, updateFile);

module.exports = router;
