master
jager 3 years ago
parent 8c8a544997
commit dd7e9f5440

@ -20,6 +20,7 @@ import (
"github.com/jageros/hawox/mysql" "github.com/jageros/hawox/mysql"
"github.com/jageros/hawox/redis" "github.com/jageros/hawox/redis"
"idata/internal/api" "idata/internal/api"
"idata/internal/service/dirty"
"idata/internal/service/soup" "idata/internal/service/soup"
"idata/internal/service/user" "idata/internal/service/user"
"math/rand" "math/rand"
@ -43,6 +44,11 @@ func main() {
datePath = "date.json" datePath = "date.json"
} }
dictPath := flags.GetValStr("dict.path")
if dictPath == "" {
dictPath = "dict.txt"
}
err := astro.InitFromJsonFile(datePath) err := astro.InitFromJsonFile(datePath)
if err != nil { if err != nil {
logx.Fatalf("astro init err: %v", err) logx.Fatalf("astro init err: %v", err)
@ -53,6 +59,11 @@ func main() {
logx.Fatalf("soup init err%v", err) logx.Fatalf("soup init err%v", err)
} }
err = dirty.InitDirtyWord(dictPath)
if err != nil {
logx.Fatalf("dirty init err%v", err)
}
redis.Initialize(ctx, func(rdb redis.RdbConfig) { redis.Initialize(ctx, func(rdb redis.RdbConfig) {
rdb.SetAddrs(flags.Options.RedisAddrs) rdb.SetAddrs(flags.Options.RedisAddrs)
rdb.SetUsername(flags.Options.RedisUser) rdb.SetUsername(flags.Options.RedisUser)

@ -36,3 +36,6 @@ soup:
date: date:
path: "conf.d/date.json" path: "conf.d/date.json"
dict:
path: "conf.d/dict.txt"

@ -15,22 +15,31 @@ package api
import ( import (
"github.com/jageros/hawox/jwt" "github.com/jageros/hawox/jwt"
"idata/internal/service/almanac" "idata/internal/service/almanac"
"idata/internal/service/dirty"
"idata/internal/service/soup" "idata/internal/service/soup"
"idata/internal/service/user" "idata/internal/service/user"
"net/http"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
func Registry(engine *gin.Engine) { func Registry(engine *gin.Engine) {
engine.GET("/my-ip", myIp)
r := engine.Group("/haw") r := engine.Group("/haw")
ur := r.Group("/user") ur := r.Group("/user")
ur.POST("/register", user.Register) ur.POST("/register", user.Register)
ur.POST("/login", user.Login) ur.POST("/login", user.Login)
ur.GET("/info", jwt.CheckToken, user.Info) ur.GET("/info", jwt.CheckToken, user.Info)
ur.GET("/secret", jwt.CheckToken, user.Secret) ur.GET("/secret", jwt.CheckToken, user.Secret)
ur.GET("/open", jwt.CheckToken, user.OpenApi) ur.GET("/openapi", jwt.CheckToken, user.OpenApi)
apiR := r.Group("/api") apiR := r.Group("/api")
apiR.GET("/soup", soup.GetRandSoup) apiR.GET("/soup", soup.GetRandSoup)
apiR.GET("/almanac", almanac.Almanac) apiR.GET("/almanac", almanac.Almanac)
apiR.GET("/dirty_word", dirty.IsDirtyWord)
}
func myIp(ctx *gin.Context) {
addr := ctx.Request.RemoteAddr
ctx.String(http.StatusOK, addr)
} }

@ -21,6 +21,7 @@ const (
Weather // 2天气 Weather // 2天气
Obscenity // 3脏词检测 Obscenity // 3脏词检测
Almanac // 4黄历 Almanac // 4黄历
Dirty // 5脏词检测
) )
func Type(ty string) ApiType { func Type(ty string) ApiType {

@ -0,0 +1,40 @@
/**
* @Author: jager
* @Email: lhj168os@gmail.com
* @File: dirty
* @Date: 2022/1/18 11:07
* @package: dirty
* @Version: v1.0.0
*
* @Description:
*
*/
package dirty
import (
"github.com/gin-gonic/gin"
"github.com/jageros/hawox/httpx"
"github.com/jageros/hawox/sensitive"
"idata/internal/apity"
"idata/internal/service/user"
)
var filter *sensitive.Filter
func InitDirtyWord(path string) error {
filter = sensitive.New()
return filter.LoadWordDict(path)
}
func IsDirtyWord(ctx *gin.Context) {
if !user.Auth(ctx, apity.Dirty) {
return
}
word, ok := httpx.DecodeUrlVal(ctx, "word")
if !ok {
return
}
dirty, w := filter.Validate(word)
httpx.PkgMsgWrite(ctx, map[string]interface{}{"dirty": !dirty, "dirty_word": w})
}
Loading…
Cancel
Save