TASK22211: normalize hash and metadata endpoint contracts
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user