新增获取博客评论接口
This commit is contained in:
28
Server/src/APIs/GetBlogComment.ts
Normal file
28
Server/src/APIs/GetBlogComment.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { API } from "../Plugs/API/API";
|
||||
import ServerStdResponse from "../ServerStdResponse";
|
||||
import MySQLConnection from '../Plugs/MySQLConnection'
|
||||
|
||||
// 获取博客评论
|
||||
class GetBlogComment extends API {
|
||||
constructor() {
|
||||
super('GET', '/blogComment');
|
||||
}
|
||||
|
||||
private pageSize = 100;
|
||||
|
||||
public async onRequset(data: any, res: any) {
|
||||
let { bloguuid, page = 1 } = data;
|
||||
if (!bloguuid || bloguuid.length != 32 || page < 1) {
|
||||
return res.json(ServerStdResponse.INVALID_PARAMS);
|
||||
}
|
||||
|
||||
let blogCommentRes = await MySQLConnection.execute('SELECT content, name, ip_address, time FROM blog_comment WHERE uuid = ? AND display = 1 ORDER BY time DESC LIMIT ? OFFSET ?;', [bloguuid, this.pageSize, (page - 1) * this.pageSize]);
|
||||
if (!blogCommentRes) {
|
||||
this.logger.error('获取博客评论时,数据库发生错误');
|
||||
return res.json(ServerStdResponse.SERVER_ERROR);
|
||||
}
|
||||
return res.json({ ...ServerStdResponse.OK, data: blogCommentRes });
|
||||
}
|
||||
}
|
||||
|
||||
export default GetBlogComment;
|
||||
17
Server/src/Plugs/Middleware/CheckCaptchaPassed.ts
Normal file
17
Server/src/Plugs/Middleware/CheckCaptchaPassed.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Request, Response, NextFunction } from "express";
|
||||
import ServerStdResponse from "../../ServerStdResponse";
|
||||
import Logger from "../Logger";
|
||||
import captchaSession from "../Service/captchaSession";
|
||||
const logger = new Logger("CheckCaptcha");
|
||||
const CheckCaptchaPassed = async (req: Request, res: Response, next: NextFunction) => {
|
||||
let session = req.query.session || req.body.session || '';
|
||||
if (session) {
|
||||
if (await captchaSession.isPassed(session))
|
||||
return next();
|
||||
}
|
||||
let ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress || req.ip;
|
||||
logger.info(`API[${req.method}][${req.url.split('?')[0]}] 请求人机验证未通过[${ip}]`);
|
||||
res.json(ServerStdResponse.AUTH_ERROR);
|
||||
}
|
||||
|
||||
export default CheckCaptchaPassed;
|
||||
@@ -12,6 +12,7 @@ import GetBlogList from "../APIs/GetBlogList";
|
||||
import GetBlogContent from "../APIs/GetBlogContent";
|
||||
import BlogLike from "../APIs/BlogLike";
|
||||
import BlogComment from "../APIs/BlogComment";
|
||||
import GetBlogComment from "../APIs/GetBlogComment";
|
||||
import GetCaptcha from "../APIs/GetCaptcha";
|
||||
import CheckCaptcha from "../APIs/CheckCaptcha";
|
||||
|
||||
@@ -32,6 +33,7 @@ class Server {
|
||||
this.apiLoader.add(GetBlogContent);
|
||||
this.apiLoader.add(BlogLike);
|
||||
this.apiLoader.add(BlogComment);
|
||||
this.apiLoader.add(GetBlogComment);
|
||||
this.apiLoader.add(GetCaptcha);
|
||||
this.apiLoader.add(CheckCaptcha);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user