Initial commit for open-source version

This commit is contained in:
jiangrui
2024-12-17 11:30:59 +08:00
commit 42c07ed34c
57 changed files with 10559 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
import { Request, Response, NextFunction } from "express";
export const errorHandler = (err: any, req: Request, res: Response, next: NextFunction) => {
console.error(err);
res.status(err.status || 500).json({
success: false,
error: err.message || "服务器内部错误",
});
};

View File

@@ -0,0 +1,14 @@
import { Request, Response, NextFunction } from "express";
export const validateRequest = (requiredParams: string[]) => {
return (req: Request, res: Response, next: NextFunction) => {
const missingParams = requiredParams.filter((param) => !req.query[param] && !req.body[param]);
if (missingParams.length > 0) {
return res.status(400).json({
success: false,
error: `缺少必要的参数: ${missingParams.join(", ")}`,
});
}
next();
};
};