2024-06-04 18:45:19 +02:00
|
|
|
const express = require("express");
|
|
|
|
const { uploadFile, getFile } = require("../controllers/file.controller");
|
|
|
|
|
|
|
|
const router = express.Router();
|
|
|
|
|
2024-06-04 18:48:52 +02:00
|
|
|
const authenticate = (req, res, next) => {
|
|
|
|
const apiKey = req.headers["x-api-key"];
|
|
|
|
if (!apiKey || !apiKeys.includes(apiKey)) {
|
|
|
|
if (allowPublicUploads) {
|
|
|
|
req.isPublicUpload = true;
|
|
|
|
next();
|
|
|
|
} else {
|
|
|
|
return res.status(403).json({ error: "Forbidden" });
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
router.post("/upload", authenticate, uploadFile);
|
2024-06-04 18:45:19 +02:00
|
|
|
router.get("/u/:filename", getFile);
|
|
|
|
|
|
|
|
module.exports = router;
|