49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
import { hashAPIPath } from "../../../actions/core/hash";
|
|
import nextConnect from "next-connect";
|
|
import { getSession } from "next-auth/react";
|
|
|
|
const ApiProxy = nextConnect();
|
|
|
|
ApiProxy.get(async (req, res) => {
|
|
const session = await getSession({ req });
|
|
|
|
if (!session) {
|
|
return res.status(401).json();
|
|
}
|
|
|
|
const rawQueryPath = req.query.path;
|
|
|
|
const queryPath =
|
|
typeof rawQueryPath === "string"
|
|
? rawQueryPath.split("?")[0]
|
|
: rawQueryPath;
|
|
|
|
const allowedPrefix = [
|
|
"/api/endpoint/getportallogin_api",
|
|
"/api/endpoint/deletemyrepresentations_api",
|
|
"/api/endpoint/deletewatchedcases_api",
|
|
"/api/file/upload",
|
|
"/api/file/uploadsinglefile",
|
|
"/api/file/deleteblobcase",
|
|
"/api/file/deleteblobrep",
|
|
"/api/file/createrepcompletemessage_api",
|
|
"/api/file/createappealcompletemessage_api",
|
|
"/api/file/generatepdf",
|
|
"/api/file/generateappealpdf"
|
|
];
|
|
|
|
if (
|
|
typeof queryPath !== "string" ||
|
|
queryPath.length === 0 ||
|
|
!queryPath.startsWith("/api/") ||
|
|
!allowedPrefix.some((prefix) => queryPath.startsWith(prefix)) ||
|
|
queryPath.includes("/api/endpoint/gethash_api")
|
|
) {
|
|
return res.status(400).json();
|
|
}
|
|
|
|
return res.status(200).json({ hash: hashAPIPath(rawQueryPath) });
|
|
});
|
|
|
|
export default ApiProxy;
|