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.
75 lines
2.5 KiB
75 lines
2.5 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)
|
|
];
|
|
|
|
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." });
|
|
}
|
|
}
|
|
|
|
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 {
|
|
console.log("Video sent successfully.");
|
|
}
|
|
});
|
|
} catch (error) {
|
|
console.error("Error fetching video:", error);
|
|
res.status(500).json({error: "Internal server error while fetching video."});
|
|
}
|
|
}
|