no more 谜语人
- respond with desc of the error - fixed crashes on request error
This commit is contained in:
parent
26a2d0a25d
commit
a43852f958
File diff suppressed because it is too large
Load Diff
|
@ -4,7 +4,8 @@
|
||||||
"description": "You know the rules and so do I~",
|
"description": "You know the rules and so do I~",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "ts-node server.ts"
|
"dev": "ts-node server.ts",
|
||||||
|
"pm2": "pm2 start npm --name explode-ss -- run dev"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
|
|
44
server.ts
44
server.ts
|
@ -1,5 +1,8 @@
|
||||||
import express, { Request, Response } from "express"
|
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"
|
import * as fs from "fs"
|
||||||
|
@ -21,9 +24,10 @@ app.get("/", (req: Request, res: Response) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
app.post("/register", async (req: Request, res: Response) => {
|
app.post("/register", async (req: Request, res: Response) => {
|
||||||
|
try {
|
||||||
let isRegistered = req.cookies.isRegistered
|
let isRegistered = req.cookies.isRegistered
|
||||||
if (isRegistered) {
|
if (isRegistered) {
|
||||||
return res.send("服务器正在探索:利维坦,涅索斯轨道")
|
return res.send("服务器正在探索:利维坦,涅索斯轨道(请勿重复注册!)")
|
||||||
}
|
}
|
||||||
|
|
||||||
let username: string = req.body.RegisterUsername
|
let username: string = req.body.RegisterUsername
|
||||||
|
@ -34,7 +38,7 @@ app.post("/register", async (req: Request, res: Response) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sw.containsDfa(username)) {
|
if (sw.containsDfa(username)) {
|
||||||
return res.status(500).send("服务器正在探索:过往灾祸,欧洲无人区")
|
return res.status(500).send("服务器正在探索:过往灾祸,欧洲无人区(名字或密码带有敏感内容!)")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (username.length < 4) {
|
if (username.length < 4) {
|
||||||
|
@ -54,13 +58,16 @@ app.post("/register", async (req: Request, res: Response) => {
|
||||||
// 使用 cookie 避免重复注册
|
// 使用 cookie 避免重复注册
|
||||||
res.cookie("isRegistered", "1", {
|
res.cookie("isRegistered", "1", {
|
||||||
expires: new Date(Date.now() + 9000000),
|
expires: new Date(Date.now() + 9000000),
|
||||||
httpOnly: true
|
httpOnly: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
return res.send(`注册成功,用户ID:${hasId._id}。要记住哦!`)
|
return res.send(`注册成功,用户ID:${hasId._id}。要记住哦!`)
|
||||||
} else {
|
} else {
|
||||||
return res.status(500).send("出错啦,注册失败了。")
|
return res.status(500).send("出错啦,注册失败了。")
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return res.status(500).send("服务器错误,请联系管理员!")
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const server = app.listen(31234, () => console.log("Server is running..."))
|
const server = app.listen(31234, () => console.log("Server is running..."))
|
||||||
|
@ -74,15 +81,19 @@ type HasId = {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function explode_graphql<T>(query: string) {
|
async function explode_graphql<T>(query: string) {
|
||||||
return _axios.post<T>("http://43.142.173.63:10483/graphql", JSON.stringify({
|
return _axios.post<T>(
|
||||||
"operationName": "",
|
"http://43.142.173.63:10483/graphql",
|
||||||
"query": query,
|
JSON.stringify({
|
||||||
variables: {}
|
operationName: "",
|
||||||
}), {
|
query: query,
|
||||||
|
variables: {},
|
||||||
|
}),
|
||||||
|
{
|
||||||
// idk why is this happening, but it just happened that
|
// idk why is this happening, but it just happened that
|
||||||
// the response is string which should be transformed to JSON auto.
|
// the response is string which should be transformed to JSON auto.
|
||||||
transformResponse: (resp) => JSON.parse(resp)
|
transformResponse: (resp) => JSON.parse(resp),
|
||||||
})
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function explode_register(username: string, password: string) {
|
async function explode_register(username: string, password: string) {
|
||||||
|
@ -90,7 +101,9 @@ async function explode_register(username: string, password: string) {
|
||||||
data: {
|
data: {
|
||||||
registerUser: HasId
|
registerUser: HasId
|
||||||
}
|
}
|
||||||
}>(`mutation { registerUser(username: "${username}", password: "${password}") { _id } }`)
|
}>(
|
||||||
|
`mutation { registerUser(username: "${username}", password: "${password}") { _id } }`
|
||||||
|
)
|
||||||
|
|
||||||
return response.data.data.registerUser
|
return response.data.data.registerUser
|
||||||
}
|
}
|
||||||
|
@ -109,6 +122,11 @@ async function explode_does_user_exists(username: string) {
|
||||||
|
|
||||||
async function initSensitiveWordList() {
|
async function initSensitiveWordList() {
|
||||||
console.log("Loading sensitive words")
|
console.log("Loading sensitive words")
|
||||||
let words = fs.readFileSync(__dirname + "/tencent-sensitive-words/sensitive_words_lines.txt", {encoding: "utf-8"}).split("\n")
|
let words = fs
|
||||||
|
.readFileSync(
|
||||||
|
__dirname + "/tencent-sensitive-words/sensitive_words_lines.txt",
|
||||||
|
{ encoding: "utf-8" }
|
||||||
|
)
|
||||||
|
.split("\n")
|
||||||
sw.addWords(words)
|
sw.addWords(words)
|
||||||
}
|
}
|
Loading…
Reference in New Issue