Update file.routes.js

This commit is contained in:
Daniël 2024-06-09 14:30:12 +02:00 committed by GitHub
parent 8075a58510
commit fe991ae2f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,8 +3,11 @@ const { uploadFile, getFile } = require("../controllers/file.controller");
const router = express.Router(); const router = express.Router();
const apiKeys = process.env.API_KEYS.split(",");
const allowPublicUploads = process.env.ALLOW_PUBLIC;
const authenticate = (req, res, next) => { const authenticate = (req, res, next) => {
const apiKey = req.headers["x-api-key"]; const apiKey = req.headers["x-api-key"] || req.query.api;
if (!apiKey || !apiKeys.includes(apiKey)) { if (!apiKey || !apiKeys.includes(apiKey)) {
if (allowPublicUploads) { if (allowPublicUploads) {
req.isPublicUpload = true; req.isPublicUpload = true;