重构结构
This commit is contained in:
parent
dbbbc9c6dc
commit
a6fc384383
|
@ -4,7 +4,7 @@ COPY ./output/study_xxqg /opt/study_xxqg
|
|||
|
||||
RUN mkdir /opt/config/
|
||||
|
||||
COPY ./lib/config_default.yml /opt/config/config.yml
|
||||
COPY conf/config_default.yml /opt/config/config.yml
|
||||
|
||||
RUN apt-get -qq update \
|
||||
&& apt-get -qq install -y --no-install-recommends ca-certificates curl \
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package lib
|
||||
package conf
|
||||
|
||||
import (
|
||||
_ "embed"
|
|
@ -26,6 +26,7 @@ import (
|
|||
goqrcode "github.com/skip2/go-qrcode"
|
||||
"golang.org/x/image/bmp"
|
||||
|
||||
"github.com/huoxue1/study_xxqg/conf"
|
||||
"github.com/huoxue1/study_xxqg/model"
|
||||
)
|
||||
|
||||
|
@ -158,14 +159,14 @@ func (c *Core) GenerateCode() (string, string, error) {
|
|||
} else {
|
||||
log.Infoln("二维码已生成到目录下的qrcode.png")
|
||||
}
|
||||
if GetConfig().QrCOde {
|
||||
if conf.GetConfig().QrCOde {
|
||||
data, _ := os.ReadFile("qrcode.png")
|
||||
c.Push("image", base64.StdEncoding.EncodeToString(data))
|
||||
}
|
||||
|
||||
qrCodeString := qrcodeTerminal.New2(qrcodeTerminal.ConsoleColors.BrightBlack, qrcodeTerminal.ConsoleColors.BrightWhite, qrcodeTerminal.QRCodeRecoveryLevels.Low).Get(codeURL)
|
||||
qrCodeString.Print()
|
||||
c.Push("flush", "登录链接:\r\n"+config.Scheme+url.QueryEscape(codeURL))
|
||||
c.Push("flush", "登录链接:\r\n"+conf.GetConfig().Scheme+url.QueryEscape(codeURL))
|
||||
return codeURL, g.Result, err
|
||||
}
|
||||
|
||||
|
@ -256,7 +257,7 @@ func (c *Core) L(retryTimes int) (*model.User, error) {
|
|||
return nil, errors.New("time out")
|
||||
} else {
|
||||
// 等待几分钟后重新执行
|
||||
time.Sleep(time.Duration(GetConfig().Retry.Intervals) * time.Minute)
|
||||
time.Sleep(time.Duration(conf.GetConfig().Retry.Intervals) * time.Minute)
|
||||
c.Push("text", fmt.Sprintf("登录超时,将进行第%d重新次登录", retryTimes))
|
||||
return c.L(retryTimes - 1)
|
||||
}
|
||||
|
@ -279,7 +280,7 @@ func (c *Core) initWindows() {
|
|||
return
|
||||
}
|
||||
c.pw = pwt
|
||||
path := GetConfig().EdgePath
|
||||
path := conf.GetConfig().EdgePath
|
||||
if path == "" {
|
||||
path = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe"
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/google/uuid"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/huoxue1/study_xxqg/conf"
|
||||
"github.com/huoxue1/study_xxqg/model"
|
||||
)
|
||||
|
||||
|
@ -90,7 +91,7 @@ func (t *Telegram) Init() {
|
|||
update := <-channel
|
||||
if update.Message == nil {
|
||||
update.Message = &tgbotapi.Message{Text: update.CallbackQuery.Data}
|
||||
t.bot.Send(tgbotapi.NewDeleteMessage(config.TG.ChatID, update.CallbackQuery.Message.MessageID))
|
||||
t.bot.Send(tgbotapi.NewDeleteMessage(conf.GetConfig().TG.ChatID, update.CallbackQuery.Message.MessageID))
|
||||
log.Infoln(update.CallbackQuery.Data)
|
||||
}
|
||||
log.Infoln("收到tg消息 ", update)
|
||||
|
@ -149,7 +150,7 @@ func (t *Telegram) SendMsg(message string) int {
|
|||
}
|
||||
|
||||
func login(bot *Telegram, args []string) {
|
||||
config := GetConfig()
|
||||
config := conf.GetConfig()
|
||||
go func() {
|
||||
defer func() {
|
||||
err := recover()
|
||||
|
@ -202,7 +203,7 @@ func getAllUser(bot *Telegram, args []string) {
|
|||
}
|
||||
|
||||
func studyAll(bot *Telegram, args []string) {
|
||||
config := GetConfig()
|
||||
config := conf.GetConfig()
|
||||
users, err := model.Query()
|
||||
if err != nil {
|
||||
bot.SendMsg(err.Error())
|
||||
|
@ -272,7 +273,7 @@ func studyAll(bot *Telegram, args []string) {
|
|||
}
|
||||
|
||||
func study(bot *Telegram, args []string) {
|
||||
config := GetConfig()
|
||||
config := conf.GetConfig()
|
||||
users, err := model.Query()
|
||||
if err != nil {
|
||||
bot.SendMsg(err.Error())
|
||||
|
|
5
main.go
5
main.go
|
@ -14,6 +14,7 @@ import (
|
|||
log "github.com/sirupsen/logrus"
|
||||
easy "github.com/t-tomalak/logrus-easy-formatter"
|
||||
|
||||
"github.com/huoxue1/study_xxqg/conf"
|
||||
//"github.com/huoxue1/study_xxqg/gui"
|
||||
"github.com/huoxue1/study_xxqg/lib"
|
||||
"github.com/huoxue1/study_xxqg/model"
|
||||
|
@ -34,7 +35,7 @@ func init() {
|
|||
flag.BoolVar(&i, "init", false, "init the app")
|
||||
flag.Parse()
|
||||
|
||||
config = lib.GetConfig()
|
||||
config = conf.GetConfig()
|
||||
logFormatter := &easy.Formatter{
|
||||
TimestampFormat: "2006-01-02 15:04:05",
|
||||
LogFormat: "[%time%] [%lvl%]: %msg% \n",
|
||||
|
@ -64,7 +65,7 @@ func init() {
|
|||
}
|
||||
|
||||
var (
|
||||
config lib.Config
|
||||
config conf.Config
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
|
|
@ -6,11 +6,11 @@ import (
|
|||
|
||||
"github.com/imroc/req/v3"
|
||||
|
||||
"github.com/huoxue1/study_xxqg/lib"
|
||||
"github.com/huoxue1/study_xxqg/conf"
|
||||
)
|
||||
|
||||
func PushMessage(title, content, message, pushID string) error {
|
||||
if !lib.GetConfig().JiGuangPush.Enable {
|
||||
if !conf.GetConfig().JiGuangPush.Enable {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ func PushMessage(title, content, message, pushID string) error {
|
|||
"message": map[string]string{
|
||||
"msg_content": message,
|
||||
},
|
||||
}).SetHeader("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(lib.GetConfig().JiGuangPush.AppKey+":"+lib.GetConfig().JiGuangPush.Secret))).Post("https://api.jpush.cn/v3/push")
|
||||
}).SetHeader("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(conf.GetConfig().JiGuangPush.AppKey+":"+conf.GetConfig().JiGuangPush.Secret))).Post("https://api.jpush.cn/v3/push")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -3,10 +3,10 @@ package push
|
|||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/huoxue1/study_xxqg/lib"
|
||||
"github.com/huoxue1/study_xxqg/conf"
|
||||
)
|
||||
|
||||
func GetPush(config lib.Config) func(kind string, message string) {
|
||||
func GetPush(config conf.Config) func(kind string, message string) {
|
||||
if config.Push.Ding.Enable {
|
||||
ding := &Ding{
|
||||
Secret: config.Push.Ding.Secret,
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/huoxue1/study_xxqg/conf"
|
||||
"github.com/huoxue1/study_xxqg/lib"
|
||||
"github.com/huoxue1/study_xxqg/model"
|
||||
"github.com/huoxue1/study_xxqg/push"
|
||||
|
@ -25,7 +26,7 @@ var (
|
|||
func CheckToken() gin.HandlerFunc {
|
||||
return func(ctx *gin.Context) {
|
||||
token := ctx.Param("token")
|
||||
config := lib.GetConfig()
|
||||
config := conf.GetConfig()
|
||||
md5 := utils.StrMd5(config.Web.Account + config.Web.Password)
|
||||
if md5 == token {
|
||||
ctx.JSON(200, Resp{
|
||||
|
@ -55,7 +56,7 @@ func Login() gin.HandlerFunc {
|
|||
}
|
||||
u := new(user)
|
||||
_ = ctx.BindJSON(u)
|
||||
config := lib.GetConfig()
|
||||
config := conf.GetConfig()
|
||||
if u.Account == config.Web.Account && u.Password == config.Web.Password {
|
||||
ctx.JSON(200, Resp{
|
||||
Code: 200,
|
||||
|
@ -220,7 +221,7 @@ func study() gin.HandlerFunc {
|
|||
}
|
||||
core.Init()
|
||||
state.Store(uid, core)
|
||||
config := lib.GetConfig()
|
||||
config := conf.GetConfig()
|
||||
go func() {
|
||||
core.LearnArticle(user)
|
||||
core.LearnVideo(user)
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/huoxue1/study_xxqg/lib"
|
||||
"github.com/huoxue1/study_xxqg/conf"
|
||||
"github.com/huoxue1/study_xxqg/utils"
|
||||
)
|
||||
|
||||
|
@ -54,7 +54,7 @@ func RouterInit() *gin.Engine {
|
|||
}
|
||||
|
||||
func check() gin.HandlerFunc {
|
||||
config := lib.GetConfig()
|
||||
config := conf.GetConfig()
|
||||
return func(ctx *gin.Context) {
|
||||
token := ctx.GetHeader("xxqg_token")
|
||||
if token == "" || (utils.StrMd5(config.Web.Account+config.Web.Password) != token) {
|
||||
|
|
Loading…
Reference in New Issue