You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

76 lines
2.3 KiB

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)
];
// Try the most likely path first (based on your volume mapping)
console.log(path.join(__dirname, '../uploads/profiles', file))
const filePath = path.join(__dirname, '../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 {
}
});
} 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 {
}
});
} catch (error) {
console.error("Error fetching thumbnail:", error);
res.status(500).json({ error: "Internal server error while fetching thumbnail." });
}
}
export async function getVideo(req, res) {
const file = req.params.file;
const filePath = path.join('/app/app/uploads/videos', file);
try {
res.sendFile(filePath, (err) => {
if (err) {
console.error("Error sending video:", err);
} else {
}
});
} catch (error) {
console.error("Error fetching video:", error);
res.status(500).json({error: "Internal server error while fetching video."});
}
}