From 6c1e619bf32f26da8d9f37c2942c947d04c6bcce Mon Sep 17 00:00:00 2001 From: Leonxie Date: Fri, 23 Jan 2026 13:51:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BF=9D=E7=A6=81=E8=AF=8D?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/main.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/back/main.py b/back/main.py index 1bf017c..5df142f 100644 --- a/back/main.py +++ b/back/main.py @@ -65,6 +65,11 @@ class Comment(db.Model): downvotes = db.Column(db.Integer, default=0) parent_comment_id = db.Column(db.Integer, db.ForeignKey('comments.id'), nullable=True) +class DenyWord(db.Model): + __tablename__ = 'deny_words' + id = db.Column(db.Integer, primary_key=True, autoincrement=True) + word = db.Column(db.String(255), unique=True, nullable=False) + # 初始化数据库函数 def init_db(): if not os.path.exists('./data'): @@ -180,6 +185,12 @@ def submit_post(): identity_token = data.get('identity') + # 违禁词检测 + deny_words = DenyWord.query.all() + for dw in deny_words: + if dw.word in content: + return jsonify({"code": 2005, "data": "提交内容包含违禁词"}) + # Identity 验证 if identity_token: if not Identity.query.filter_by(token=identity_token).first():