import express from "express"; const router = express.Router(); import apiController from "../controllers/apiController.js"; import { register, login, checkAuth, logout, getprofile, } from "../controllers/authController.js"; import {verifyToken} from "../middleware/tokenJWTMiddleware.js"; import multer from "multer"; import { v4 as uuidv4 } from 'uuid'; import path from "node:path"; import {getVideo} from "../controllers/videoController.js"; router.get('', apiController); // Upload const generateFileName = (originalName) => { const ext = path.extname(originalName); const now = new Date(); const timestamp = now.getFullYear().toString() + String(now.getMonth() + 1).padStart(2, '0') + String(now.getDate()).padStart(2, '0') + String(now.getHours()).padStart(2, '0') + String(now.getMinutes()).padStart(2, '0') + String(now.getSeconds()).padStart(2, '0'); const uuid = uuidv4(); return `${timestamp}_${uuid}${ext}`; }; const storage = multer.diskStorage({ destination: function (req, file, cb) { cb(null, 'uploads/'); }, filename: function (req, file, cb) { cb(null, generateFileName(file.originalname)); } }); const upload = multer({ storage: storage }); router.post('/upload', verifyToken, upload.single('file'), (req, res) => { if (!req.file) { return res.status(400).json({ message: 'Aucun fichier fourni' }); } const filePath = `/uploads/${req.file.filename}`; res.json({ filePath }); }); // Authentification et utilisateur router.post('/auth/register', register); router.post('/auth/login', login); router.post('/auth/logout', logout); router.get('/auth/user', verifyToken, getprofile); router.get('/auth/check-auth', verifyToken, checkAuth); // Récupérer vidéo router.get('/video', getVideo) export default router;