added sensitive words filtering

This commit is contained in:
Taskeren 2023-06-18 00:29:44 +08:00
parent f54e124b5c
commit f2c832330d
No known key found for this signature in database
GPG Key ID: 1A491EE81C9B7F38
5 changed files with 32 additions and 1 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "tencent-sensitive-words"]
path = tencent-sensitive-words
url = git@github.com:cjh0613/tencent-sensitive-words.git

View File

@ -20,6 +20,7 @@
"axios": "^1.4.0",
"body-parser": "^1.20.2",
"cookie-parser": "^1.4.6",
"express": "^4.18.2"
"express": "^4.18.2",
"js-sensitivewords": "^0.7.0"
}
}

View File

@ -20,6 +20,9 @@ dependencies:
express:
specifier: ^4.18.2
version: 4.18.2
js-sensitivewords:
specifier: ^0.7.0
version: 0.7.0
devDependencies:
'@types/cookie-parser':
@ -474,6 +477,10 @@ packages:
engines: {node: '>= 0.10'}
dev: false
/js-sensitivewords@0.7.0:
resolution: {integrity: sha512-A/UKSftoB0EoDIx2e50w2vABLM2E4JHfvA39YMO8hTMz6hzOZT6NplIJ54d1ftgwt0QAJ9BDXwhOYLIdyMDH2w==}
dev: false
/make-error@1.3.6:
resolution: {integrity: sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==}
dev: true

View File

@ -2,6 +2,11 @@ import express, { Request, Response } from "express"
import { json as bodyParserJson, urlencoded as bodyParserUrlEncoded } from "body-parser"
import cookieParser from "cookie-parser"
import { Axios } from "axios"
import * as fs from "fs"
const sw = require("js-sensitivewords")
initSensitiveWordList()
const app = express()
@ -28,6 +33,10 @@ app.post("/register", async (req: Request, res: Response) => {
return res.status(400).send("注册失败:无效的用户名或密码!")
}
if(sw.containsDfa(username)) {
return res.status(500).send("服务器正在探索:过往灾祸,欧洲无人区")
}
if(username.length < 4) {
return res.status(400).send("账号太短啦~")
}
@ -56,6 +65,8 @@ app.post("/register", async (req: Request, res: Response) => {
const server = app.listen(8090, () => console.log("Server is running..."))
////////// Interact with Explode Server
const _axios = new Axios({})
type HasId = {
@ -92,4 +103,12 @@ async function explode_does_user_exists(username: string) {
}>(`query { userByUsername(username: "${username}") { _id } }`)
return !!response.data.data.userByUsername
}
////////// The Sensitive Words Blocking
async function initSensitiveWordList() {
console.log("Loading sensitive words")
let words = fs.readFileSync(__dirname + "/tencent-sensitive-words/sensitive_words_lines.txt", {encoding: "utf-8"}).split("\n")
sw.addWords(words)
}

@ -0,0 +1 @@
Subproject commit a39ff3487ca8c7ca507cd9d53077797ee2cc89a4