oapix / src /controllers /mediaController.js
woiceatus's picture
init
e43a4a9
raw
history blame contribute delete
525 Bytes
import { HttpError } from "../utils/httpError.js";
export function createMediaController({ mediaStore }) {
return function mediaController(req, res, next) {
try {
const media = mediaStore.get(req.params.mediaId);
if (!media) {
throw new HttpError(404, "Media file not found or expired.");
}
res.setHeader("content-type", media.mimeType);
res.setHeader("cache-control", "private, max-age=3600");
res.send(media.buffer);
} catch (error) {
next(error);
}
};
}