TASK22211: normalize hash and metadata endpoint contracts

This commit is contained in:
2026-03-23 12:14:17 +00:00
parent cb69bbe732
commit 722ef9846a
4 changed files with 134 additions and 13 deletions
+12 -3
View File
@@ -1,6 +1,7 @@
import { hashAPIPath } from "../../../actions/core/hash";
import nextConnect from "next-connect";
import { getSession } from "next-auth/react";
import { respondError, respondSuccess } from "../middleware/apiResponse";
const ApiProxy = nextConnect();
@@ -8,7 +9,11 @@ ApiProxy.get(async (req, res) => {
const session = await getSession({ req });
if (!session) {
return res.status(401).json();
return respondError(res, {
status: 401,
code: "UNAUTHENTICATED",
message: "Authentication required"
});
}
const rawQueryPath = req.query.path;
@@ -39,10 +44,14 @@ ApiProxy.get(async (req, res) => {
!allowedPrefix.some((prefix) => queryPath.startsWith(prefix)) ||
queryPath.includes("/api/endpoint/gethash_api")
) {
return res.status(400).json();
return respondError(res, {
status: 400,
code: "INVALID_HASH_PATH",
message: "Invalid path for hash generation"
});
}
return res.status(200).json({ hash: hashAPIPath(rawQueryPath) });
return respondSuccess(res, { hash: hashAPIPath(rawQueryPath) });
});
export default ApiProxy;