import path from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); export async function getProfilePicture(req, res) { const file = req.params.file; // Try different path approaches const possiblePaths = [ path.join(__dirname, '../../uploads/profiles', file), path.join(process.cwd(), 'app/uploads/profiles', file), path.join('/app/app/uploads/profiles', file), path.join('/app/uploads/profiles', file) ]; console.log('Possible paths:', possiblePaths); console.log('Current working directory:', process.cwd()); console.log('__dirname:', __dirname); // Try the most likely path first (based on your volume mapping) const filePath = path.join('/app/app/uploads/profiles', file); try { res.sendFile(filePath, (err) => { if (err) { console.error("Error sending profile picture:", err); res.status(404).json({ error: "Profile picture not found." }); } else { console.log("Profile picture sent successfully."); } }); } catch (error) { console.error("Error fetching profile picture:", error); res.status(500).json({ error: "Internal server error while fetching profile picture." }); } } export async function getThumbnail(req, res) { const file = req.params.file; const filePath = path.join('/app/app/uploads/thumbnails', file); try { res.sendFile(filePath, (err) => { if (err) { console.error("Error sending thumbnail:", err); res.status(404).json({ error: "Thumbnail not found." }); } else { console.log("Thumbnail sent successfully."); } }); } catch (error) { console.error("Error fetching thumbnail:", error); res.status(500).json({ error: "Internal server error while fetching thumbnail." }); } }