added sensitive words filtering
This commit is contained in:
parent
f54e124b5c
commit
f2c832330d
|
@ -0,0 +1,3 @@
|
||||||
|
[submodule "tencent-sensitive-words"]
|
||||||
|
path = tencent-sensitive-words
|
||||||
|
url = git@github.com:cjh0613/tencent-sensitive-words.git
|
|
@ -20,6 +20,7 @@
|
||||||
"axios": "^1.4.0",
|
"axios": "^1.4.0",
|
||||||
"body-parser": "^1.20.2",
|
"body-parser": "^1.20.2",
|
||||||
"cookie-parser": "^1.4.6",
|
"cookie-parser": "^1.4.6",
|
||||||
"express": "^4.18.2"
|
"express": "^4.18.2",
|
||||||
|
"js-sensitivewords": "^0.7.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,9 @@ dependencies:
|
||||||
express:
|
express:
|
||||||
specifier: ^4.18.2
|
specifier: ^4.18.2
|
||||||
version: 4.18.2
|
version: 4.18.2
|
||||||
|
js-sensitivewords:
|
||||||
|
specifier: ^0.7.0
|
||||||
|
version: 0.7.0
|
||||||
|
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@types/cookie-parser':
|
'@types/cookie-parser':
|
||||||
|
@ -474,6 +477,10 @@ packages:
|
||||||
engines: {node: '>= 0.10'}
|
engines: {node: '>= 0.10'}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
/js-sensitivewords@0.7.0:
|
||||||
|
resolution: {integrity: sha512-A/UKSftoB0EoDIx2e50w2vABLM2E4JHfvA39YMO8hTMz6hzOZT6NplIJ54d1ftgwt0QAJ9BDXwhOYLIdyMDH2w==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/make-error@1.3.6:
|
/make-error@1.3.6:
|
||||||
resolution: {integrity: sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==}
|
resolution: {integrity: sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
19
server.ts
19
server.ts
|
@ -2,6 +2,11 @@ import express, { Request, Response } from "express"
|
||||||
import { json as bodyParserJson, urlencoded as bodyParserUrlEncoded } from "body-parser"
|
import { json as bodyParserJson, urlencoded as bodyParserUrlEncoded } from "body-parser"
|
||||||
import cookieParser from "cookie-parser"
|
import cookieParser from "cookie-parser"
|
||||||
import { Axios } from "axios"
|
import { Axios } from "axios"
|
||||||
|
import * as fs from "fs"
|
||||||
|
|
||||||
|
const sw = require("js-sensitivewords")
|
||||||
|
|
||||||
|
initSensitiveWordList()
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
|
|
||||||
|
@ -28,6 +33,10 @@ app.post("/register", async (req: Request, res: Response) => {
|
||||||
return res.status(400).send("注册失败:无效的用户名或密码!")
|
return res.status(400).send("注册失败:无效的用户名或密码!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(sw.containsDfa(username)) {
|
||||||
|
return res.status(500).send("服务器正在探索:过往灾祸,欧洲无人区")
|
||||||
|
}
|
||||||
|
|
||||||
if(username.length < 4) {
|
if(username.length < 4) {
|
||||||
return res.status(400).send("账号太短啦~")
|
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..."))
|
const server = app.listen(8090, () => console.log("Server is running..."))
|
||||||
|
|
||||||
|
////////// Interact with Explode Server
|
||||||
|
|
||||||
const _axios = new Axios({})
|
const _axios = new Axios({})
|
||||||
|
|
||||||
type HasId = {
|
type HasId = {
|
||||||
|
@ -93,3 +104,11 @@ async function explode_does_user_exists(username: string) {
|
||||||
|
|
||||||
return !!response.data.data.userByUsername
|
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
|
Loading…
Reference in New Issue