Skip to content

Commit 3122af0

Browse files
author
19983467897
committed
feat: 更新代码
1 parent fa66c90 commit 3122af0

File tree

27 files changed

+263
-232
lines changed

27 files changed

+263
-232
lines changed

.DS_Store

0 Bytes
Binary file not shown.

blog-server/.DS_Store

0 Bytes
Binary file not shown.

blog-server/db/online_blog.sql

+17-16
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Target Server Version : 80027
1212
File Encoding : 65001
1313
14-
Date: 06/07/2024 10:18:20
14+
Date: 01/09/2024 12:26:51
1515
*/
1616

1717
SET NAMES utf8mb4;
@@ -40,7 +40,7 @@ CREATE TABLE `blog_article` (
4040
`reading_duration` double DEFAULT '0' COMMENT '文章阅读时长',
4141
`order` int DEFAULT NULL COMMENT '排序 1 最大 往后越小 用于置顶文章的排序',
4242
PRIMARY KEY (`id`) USING BTREE
43-
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
43+
) ENGINE=InnoDB AUTO_INCREMENT=37 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
4444

4545
-- ----------------------------
4646
-- Table structure for blog_article_tag
@@ -53,7 +53,7 @@ CREATE TABLE `blog_article_tag` (
5353
`createdAt` datetime DEFAULT NULL,
5454
`updatedAt` datetime DEFAULT NULL,
5555
PRIMARY KEY (`id`) USING BTREE
56-
) ENGINE=InnoDB AUTO_INCREMENT=309 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
56+
) ENGINE=InnoDB AUTO_INCREMENT=356 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
5757

5858
-- ----------------------------
5959
-- Table structure for blog_category
@@ -89,12 +89,12 @@ DROP TABLE IF EXISTS `blog_chat`;
8989
CREATE TABLE `blog_chat` (
9090
`id` int NOT NULL AUTO_INCREMENT,
9191
`user_id` int DEFAULT NULL COMMENT '用户id 用于判断是谁发送的',
92-
`content` varchar(555) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '聊天内容',
92+
`content` varchar(555) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '聊天内容',
9393
`createdAt` datetime DEFAULT NULL,
9494
`updatedAt` datetime DEFAULT NULL,
95-
`content_type` varchar(55) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '聊天的内容格式 如果是文本就是text 图片就是 img',
95+
`content_type` varchar(55) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '聊天的内容格式 如果是文本就是text 图片就是 img',
9696
PRIMARY KEY (`id`)
97-
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
97+
) ENGINE=InnoDB AUTO_INCREMENT=214 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
9898

9999
-- ----------------------------
100100
-- Table structure for blog_comment
@@ -117,7 +117,7 @@ CREATE TABLE `blog_comment` (
117117
`updatedAt` datetime DEFAULT NULL,
118118
`ip` varchar(255) DEFAULT NULL COMMENT 'ip地址',
119119
PRIMARY KEY (`id`)
120-
) ENGINE=InnoDB AUTO_INCREMENT=446 DEFAULT CHARSET=utf8mb3;
120+
) ENGINE=InnoDB AUTO_INCREMENT=489 DEFAULT CHARSET=utf8mb3;
121121

122122
-- ----------------------------
123123
-- Table structure for blog_config
@@ -156,7 +156,7 @@ CREATE TABLE `blog_header` (
156156
`updatedAt` datetime DEFAULT NULL,
157157
`route_name` varchar(555) DEFAULT NULL COMMENT '路由名称',
158158
PRIMARY KEY (`id`)
159-
) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8mb3;
159+
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8mb3;
160160

161161
-- ----------------------------
162162
-- Table structure for blog_like
@@ -169,8 +169,9 @@ CREATE TABLE `blog_like` (
169169
`user_id` int DEFAULT NULL COMMENT '点赞用户id',
170170
`createdAt` datetime DEFAULT NULL,
171171
`updatedAt` datetime DEFAULT NULL,
172+
`ip` varchar(255) DEFAULT NULL COMMENT '点赞ip',
172173
PRIMARY KEY (`id`)
173-
) ENGINE=InnoDB AUTO_INCREMENT=444 DEFAULT CHARSET=utf8mb3;
174+
) ENGINE=InnoDB AUTO_INCREMENT=930 DEFAULT CHARSET=utf8mb3;
174175

175176
-- ----------------------------
176177
-- Table structure for blog_links
@@ -187,7 +188,7 @@ CREATE TABLE `blog_links` (
187188
`updatedAt` datetime DEFAULT NULL,
188189
`user_id` varchar(255) DEFAULT NULL COMMENT '申请者id',
189190
PRIMARY KEY (`id`)
190-
) ENGINE=InnoDB AUTO_INCREMENT=36 DEFAULT CHARSET=utf8mb3;
191+
) ENGINE=InnoDB AUTO_INCREMENT=40 DEFAULT CHARSET=utf8mb3;
191192

192193
-- ----------------------------
193194
-- Table structure for blog_message
@@ -208,7 +209,7 @@ CREATE TABLE `blog_message` (
208209
`font_weight` int DEFAULT '500' COMMENT '字体宽度',
209210
`nick_name` varchar(255) DEFAULT NULL COMMENT '游客用户的昵称',
210211
PRIMARY KEY (`id`)
211-
) ENGINE=InnoDB AUTO_INCREMENT=138 DEFAULT CHARSET=utf8mb3;
212+
) ENGINE=InnoDB AUTO_INCREMENT=3465 DEFAULT CHARSET=utf8mb3;
212213

213214
-- ----------------------------
214215
-- Table structure for blog_notify
@@ -224,7 +225,7 @@ CREATE TABLE `blog_notify` (
224225
`createdAt` datetime DEFAULT NULL,
225226
`updatedAt` datetime DEFAULT NULL,
226227
PRIMARY KEY (`id`)
227-
) ENGINE=InnoDB AUTO_INCREMENT=471 DEFAULT CHARSET=utf8mb3;
228+
) ENGINE=InnoDB AUTO_INCREMENT=3839 DEFAULT CHARSET=utf8mb3;
228229

229230
-- ----------------------------
230231
-- Table structure for blog_photo
@@ -301,7 +302,7 @@ CREATE TABLE `blog_tag` (
301302
UNIQUE KEY `tag_name_22` (`tag_name`) USING BTREE,
302303
UNIQUE KEY `tag_name_23` (`tag_name`) USING BTREE,
303304
UNIQUE KEY `tag_name_24` (`tag_name`) USING BTREE
304-
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
305+
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
305306

306307
-- ----------------------------
307308
-- Table structure for blog_talk
@@ -317,7 +318,7 @@ CREATE TABLE `blog_talk` (
317318
`createdAt` datetime DEFAULT NULL,
318319
`updatedAt` datetime DEFAULT NULL,
319320
PRIMARY KEY (`id`) USING BTREE
320-
) ENGINE=InnoDB AUTO_INCREMENT=59 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
321+
) ENGINE=InnoDB AUTO_INCREMENT=62 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
321322

322323
-- ----------------------------
323324
-- Table structure for blog_talk_photo
@@ -330,7 +331,7 @@ CREATE TABLE `blog_talk_photo` (
330331
`createdAt` datetime DEFAULT NULL,
331332
`updatedAt` datetime DEFAULT NULL,
332333
PRIMARY KEY (`id`) USING BTREE
333-
) ENGINE=InnoDB AUTO_INCREMENT=114 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
334+
) ENGINE=InnoDB AUTO_INCREMENT=115 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
334335

335336
-- ----------------------------
336337
-- Table structure for blog_user
@@ -370,6 +371,6 @@ CREATE TABLE `blog_user` (
370371
UNIQUE KEY `username_20` (`username`) USING BTREE,
371372
UNIQUE KEY `username_21` (`username`) USING BTREE,
372373
UNIQUE KEY `username_22` (`username`)
373-
) ENGINE=InnoDB AUTO_INCREMENT=373 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
374+
) ENGINE=InnoDB AUTO_INCREMENT=522 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;
374375

375376
SET FOREIGN_KEY_CHECKS = 1;

blog-server/src/controller/comment/index.js

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const { createComment, applyComment, thumbUpComment, cancelThumbUp, deleteComment, backGetCommentList, frontGetParentComment, frontGetChildrenComment, getCommentTotal } = require("../../service/comment/index");
1+
const { createComment, applyComment, commentLike, cancelCommentLike, deleteComment, backGetCommentList, frontGetParentComment, frontGetChildrenComment, getCommentTotal } = require("../../service/comment/index");
22

33
const { result, ERRORCODE, throwError } = require("../../result/index");
44
const errorCode = ERRORCODE.CATEGORY;
55
const { addNotify } = require("../notify/index");
6-
const { getCurrentTypeName } = require("../../utils/tool")
6+
const { getCurrentTypeName } = require("../../utils/tool");
77

88
const filterSensitive = require("../../utils/sensitive");
99

@@ -74,9 +74,9 @@ class CommentController {
7474
/**
7575
* 点赞评论
7676
*/
77-
async thumbUpComment(ctx) {
77+
async commentLike(ctx) {
7878
try {
79-
let res = await thumbUpComment(ctx.params.id);
79+
let res = await commentLike(ctx.params.id);
8080
ctx.body = result("点赞成功", {
8181
res,
8282
});
@@ -89,9 +89,9 @@ class CommentController {
8989
/**
9090
* 取消点赞评论
9191
*/
92-
async cancelThumbUp(ctx) {
92+
async cancelCommentLike(ctx) {
9393
try {
94-
let res = await cancelThumbUp(ctx.params.id);
94+
let res = await cancelCommentLike(ctx.params.id);
9595
ctx.body = result("取消点赞成功", {
9696
res,
9797
});
@@ -136,8 +136,10 @@ class CommentController {
136136
*/
137137
async frontGetParentComment(ctx) {
138138
try {
139+
let ip = ctx.get("X-Real-IP") || ctx.get("X-Forwarded-For") || ctx.ip;
140+
ip = ip.split(":").pop();
139141
const { current, size, type, for_id, user_id, order } = ctx.request.body;
140-
let res = await frontGetParentComment({ current, size, type, for_id, user_id, order });
142+
let res = await frontGetParentComment({ current, size, type, for_id, user_id, order, ip });
141143
ctx.body = result("分页查找评论成功", res);
142144
} catch (err) {
143145
console.error(err);
@@ -150,8 +152,10 @@ class CommentController {
150152
*/
151153
async frontGetChildrenComment(ctx) {
152154
try {
155+
let ip = ctx.get("X-Real-IP") || ctx.get("X-Forwarded-For") || ctx.ip;
156+
ip = ip.split(":").pop();
153157
const { current, size, type, for_id, user_id, parent_id } = ctx.request.body;
154-
let res = await frontGetChildrenComment({ current, size, type, for_id, user_id, parent_id });
158+
let res = await frontGetChildrenComment({ current, size, type, for_id, user_id, parent_id, ip });
155159
ctx.body = result("分页查找子评论成功", res);
156160
} catch (err) {
157161
console.error(err);
@@ -160,8 +164,8 @@ class CommentController {
160164
}
161165

162166
/**
163-
* 获取当前评论的总条数
164-
*/
167+
* 获取当前评论的总条数
168+
*/
165169
async getCommentTotal(ctx) {
166170
try {
167171
const { for_id, type } = ctx.request.body;

blog-server/src/controller/like/index.js

+75-10
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,61 @@
11
const { result, ERRORCODE, throwError } = require("../../result/index");
22
const errorCode = ERRORCODE.LIKE;
33

4-
const { addLike, cancelLike, getIsLikeByIdAndType } = require("../../service/like/index");
5-
4+
const { addLike, cancelLike, getIsLikeByIdAndType, getIsLikeByIpAndType } = require("../../service/like/index");
5+
const { articleLike, cancelArticleLike } = require("../../service/article/index");
6+
const { talkLike, cancelTalkLike } = require("../../service/talk/index");
7+
const { messageLike, cancelMessageLike } = require("../../service/message/index");
8+
const { commentLike, cancelCommentLike } = require("../../service/comment/index");
69
class HeaderController {
710
/**
811
* 点赞
912
*/
1013
async addLike(ctx) {
1114
try {
15+
let ip = ctx.get("X-Real-IP") || ctx.get("X-Forwarded-For") || ctx.ip;
16+
ip = ip.split(":").pop();
1217
const { for_id, type, user_id } = ctx.request.body;
1318
if (!for_id) {
1419
return ctx.app.emit("error", throwError(errorCode, "点赞对象不能为空"), ctx);
1520
}
1621
if (!type) {
1722
return ctx.app.emit("error", throwError(errorCode, "点赞类型不能为空"), ctx);
1823
}
19-
let res
24+
25+
let res;
2026
if (!user_id) {
21-
res = false
27+
let isLike = await getIsLikeByIpAndType({ for_id, type, ip });
28+
if (isLike) {
29+
return ctx.app.emit("error", throwError(errorCode, "您已经点过赞了"), ctx);
30+
}
31+
res = await addLike({ for_id, type, ip });
2232
} else {
33+
let isLike = await getIsLikeByIdAndType({ for_id, type, user_id });
34+
if (isLike) {
35+
return ctx.app.emit("error", throwError(errorCode, "您已经点过赞了"), ctx);
36+
}
2337
res = await addLike({ for_id, type, user_id });
38+
}
39+
40+
if (!res) {
41+
return ctx.app.emit("error", throwError(errorCode, "点赞失败"), ctx);
42+
}
2443

44+
// 在这里调用对应的 说说/文章/评论 的点赞方法
45+
// 点赞类型 1 文章 2 说说 3 留言 4 评论
46+
switch (type + "") {
47+
case "1":
48+
articleLike(for_id);
49+
break;
50+
case "2":
51+
talkLike(for_id);
52+
break;
53+
case "3":
54+
messageLike(for_id);
55+
break;
56+
case "4":
57+
commentLike(for_id);
58+
break;
2559
}
2660

2761
ctx.body = result("点赞成功", res);
@@ -37,19 +71,49 @@ class HeaderController {
3771
async cancelLike(ctx) {
3872
try {
3973
const { for_id, type, user_id } = ctx.request.body;
74+
let ip = ctx.get("X-Real-IP") || ctx.get("X-Forwarded-For") || ctx.ip;
75+
ip = ip.split(":").pop();
4076
if (!for_id) {
4177
return ctx.app.emit("error", throwError(errorCode, "取消点赞对象不能为空"), ctx);
4278
}
4379
if (!type) {
4480
return ctx.app.emit("error", throwError(errorCode, "取消点赞类型不能为空"), ctx);
4581
}
46-
let res
82+
let res;
4783
if (!user_id) {
48-
res = false
84+
let isLike = await getIsLikeByIpAndType({ for_id, type, ip });
85+
if (!isLike) {
86+
return ctx.app.emit("error", throwError(errorCode, "您没有点过赞"), ctx);
87+
}
88+
res = await cancelLike({ for_id, type, ip });
4989
} else {
90+
let isLike = await getIsLikeByIdAndType({ for_id, type, user_id });
91+
if (!isLike) {
92+
return ctx.app.emit("error", throwError(errorCode, "您没有点过赞"), ctx);
93+
}
5094
res = await cancelLike({ for_id, type, user_id });
5195
}
5296

97+
if (!res) {
98+
return ctx.app.emit("error", throwError(errorCode, "取消点赞失败"), ctx);
99+
}
100+
101+
// 在这里调用对应的 说说/文章/评论 的点赞方法
102+
// 点赞类型 1 文章 2 说说 3 留言 4 评论
103+
switch (type + "") {
104+
case "1":
105+
cancelArticleLike(for_id);
106+
break;
107+
case "2":
108+
cancelTalkLike(for_id);
109+
break;
110+
case "3":
111+
cancelMessageLike(for_id);
112+
break;
113+
case "4":
114+
cancelCommentLike(for_id);
115+
break;
116+
}
53117

54118
ctx.body = result("取消点赞成功", res);
55119
} catch (err) {
@@ -59,23 +123,24 @@ class HeaderController {
59123
}
60124

61125
// 根据点赞类型和用户id、文章id 判断用户是否点赞
62-
async getIsLikeByIdAndType(ctx) {
126+
async getIsLikeByIdOrIpAndType(ctx) {
63127
try {
64128
const { for_id, type, user_id } = ctx.request.body;
129+
let ip = ctx.get("X-Real-IP") || ctx.get("X-Forwarded-For") || ctx.ip;
130+
ip = ip.split(":").pop();
65131
if (!for_id) {
66132
return ctx.app.emit("error", throwError(errorCode, "取消点赞对象不能为空"), ctx);
67133
}
68134
if (!type) {
69135
return ctx.app.emit("error", throwError(errorCode, "取消点赞类型不能为空"), ctx);
70136
}
71-
let res
137+
let res;
72138
if (!user_id) {
73-
res = false
139+
res = await getIsLikeByIpAndType({ for_id, type, ip });
74140
} else {
75141
res = await getIsLikeByIdAndType({ for_id, type, user_id });
76142
}
77143

78-
79144
ctx.body = result("获取用户是否点赞成功", res);
80145
} catch (err) {
81146
console.error(err);

blog-server/src/controller/message/index.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { result, ERRORCODE, throwError } = require("../../result/index");
22
const errorCode = ERRORCODE.MESSAGE;
33

4-
const { addMessage, deleteMessage, getMessageList, getAllMessage, updateMessage, likeMessage, cancelLikeMessage, getMessageTag } = require("../../service/message/index");
4+
const { addMessage, deleteMessage, getMessageList, getAllMessage, updateMessage, messageLike, cancelMessageLike, getMessageTag } = require("../../service/message/index");
55
const { addNotify } = require("../notify/index");
66

77
const filterSensitive = require("../../utils/sensitive");
@@ -72,9 +72,9 @@ class MessageController {
7272
/**
7373
* 留言点赞
7474
*/
75-
async likeMessage(ctx) {
75+
async messageLike(ctx) {
7676
try {
77-
const res = await likeMessage(ctx.params.id);
77+
const res = await messageLike(ctx.params.id);
7878

7979
ctx.body = result("留言点赞成功", res);
8080
} catch (err) {
@@ -86,9 +86,9 @@ class MessageController {
8686
/**
8787
* 取消留言点赞
8888
*/
89-
async cancelLikeMessage(ctx) {
89+
async cancelMessageLike(ctx) {
9090
try {
91-
const res = await cancelLikeMessage(ctx.params.id);
91+
const res = await cancelMessageLike(ctx.params.id);
9292

9393
ctx.body = result("取消留言点赞成功", res);
9494
} catch (err) {
@@ -100,7 +100,9 @@ class MessageController {
100100
// 分页获取留言
101101
async getMessageList(ctx) {
102102
try {
103-
const res = await getMessageList(ctx.request.body);
103+
let ip = ctx.get("X-Real-IP") || ctx.get("X-Forwarded-For") || ctx.ip;
104+
ip = ip.split(":").pop();
105+
const res = await getMessageList({ ...ctx.request.body, ip });
104106

105107
ctx.body = result("分页获取留言成功", res);
106108
} catch (err) {

0 commit comments

Comments
 (0)