修改题库文件目录,添加检测题库的功能
This commit is contained in:
parent
7f846ef707
commit
e9f0e3bbc7
|
@ -15,7 +15,7 @@ RUN apt-get -qq update && \
|
|||
mkdir /opt/config/
|
||||
|
||||
COPY conf/config_default.yml /opt/config/config.yml
|
||||
COPY conf/QuestionBank.db /opt/config/QuestionBank.db
|
||||
COPY conf/QuestionBank.db /opt/QuestionBank.db
|
||||
|
||||
COPY ./dist/docker_linux_$TARGETARCH*/study_xxqg /opt/study_xxqg
|
||||
|
||||
|
|
|
@ -89,6 +89,9 @@ type Config struct {
|
|||
SuperUser string `json:"super_user" yaml:"super_user"`
|
||||
SuperPassword string `json:"super_password" yaml:"super_password"`
|
||||
|
||||
// github的代理地址,用于检查更新或者其他的
|
||||
GithubProxy string `json:"github_proxy" yaml:"github_proxy"`
|
||||
|
||||
version string
|
||||
}
|
||||
|
||||
|
|
|
@ -116,6 +116,9 @@ special_min_score: 10
|
|||
# 题目搜索的顺序,为true则从2018年最开始搜题,否则从现在最新开始搜题
|
||||
reverse_order: false
|
||||
|
||||
# github的代理地址
|
||||
github_proxy: https://github.com
|
||||
|
||||
weekly_min_score:
|
||||
|
||||
ji_guang_push:
|
||||
|
|
6
main.go
6
main.go
|
@ -18,6 +18,8 @@ import (
|
|||
easy "github.com/t-tomalak/logrus-easy-formatter"
|
||||
|
||||
"github.com/johlanse/study_xxqg/conf"
|
||||
"github.com/johlanse/study_xxqg/utils"
|
||||
|
||||
// "github.com/johlanse/study_xxqg/gui"
|
||||
"github.com/johlanse/study_xxqg/lib"
|
||||
"github.com/johlanse/study_xxqg/model"
|
||||
|
@ -59,6 +61,10 @@ func init() {
|
|||
log.SetLevel(log.DebugLevel)
|
||||
}
|
||||
log.SetLevel(level)
|
||||
if !utils.CheckQuestionDB() {
|
||||
utils.DownloadDbFile()
|
||||
log.Errorln("题库文件不存在或已损坏,请手动前往 https://github.com/johlanse/study_xxqg/blob/main/conf/QuestionBank.db 下载并放入程序根目录")
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
|
@ -43,7 +43,7 @@ func initQuestionDb() {
|
|||
once := sync.Once{}
|
||||
once.Do(func() {
|
||||
var err error
|
||||
db1, err = sql.Open("sqlite", "./config/QuestionBank.db")
|
||||
db1, err = sql.Open("sqlite", "./QuestionBank.db")
|
||||
if err != nil {
|
||||
log.Errorln("题目数据库打开失败,请检查config目录权限")
|
||||
log.Panicln(err.Error())
|
||||
|
|
|
@ -15,7 +15,9 @@ func init() {
|
|||
if log.GetLevel() == log.DebugLevel {
|
||||
client.DebugLog = true
|
||||
client = client.DevMode()
|
||||
|
||||
}
|
||||
client.EnableForceHTTP1()
|
||||
client.SetLogger(&myLog{})
|
||||
client.SetCommonHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36")
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ import (
|
|||
"github.com/kardianos/osext"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
"github.com/johlanse/study_xxqg/conf"
|
||||
)
|
||||
|
||||
// CheckUpdate 检查更新
|
||||
|
@ -156,6 +158,7 @@ func wait() {
|
|||
|
||||
// SelfUpdate 自更新
|
||||
func SelfUpdate(github string, version string) {
|
||||
github = conf.GetConfig().GithubProxy
|
||||
if github == "" {
|
||||
github = "https://github.com"
|
||||
}
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
"github.com/imroc/req/v3"
|
||||
"github.com/sirupsen/logrus"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
"github.com/johlanse/study_xxqg/conf"
|
||||
|
@ -44,7 +47,7 @@ func CheckUserCookie(cookies []*http.Cookie) bool {
|
|||
client := req.C().DevMode()
|
||||
response, err := client.R().SetCookies(cookies...).Get("https://pc-api.xuexi.cn/open/api/score/get")
|
||||
if err != nil {
|
||||
logrus.Errorln("获取用户总分错误" + err.Error())
|
||||
log.Errorln("获取用户总分错误" + err.Error())
|
||||
return false
|
||||
}
|
||||
if !gjson.GetBytes(response.Bytes(), "ok").Bool() {
|
||||
|
@ -52,3 +55,59 @@ func CheckUserCookie(cookies []*http.Cookie) bool {
|
|||
}
|
||||
return true
|
||||
}
|
||||
|
||||
var (
|
||||
dbSum = "a71c289c9423dd71a88d1fd9db48d51479a4beed8e013f9519c691f524613cff"
|
||||
)
|
||||
|
||||
// CheckQuestionDB
|
||||
/**
|
||||
* @Description: 检查数据库文件完整性
|
||||
* @param user
|
||||
* @return bool
|
||||
*/
|
||||
func CheckQuestionDB() bool {
|
||||
|
||||
if !FileIsExist("./QuestionBank.db") {
|
||||
return false
|
||||
}
|
||||
f, err := os.Open("./QuestionBank.db")
|
||||
if err != nil {
|
||||
log.Errorln(err.Error())
|
||||
return false
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
h := sha256.New()
|
||||
//h := sha1.New()
|
||||
//h := sha512.New()
|
||||
|
||||
if _, err := io.Copy(h, f); err != nil {
|
||||
log.Errorln(err.Error())
|
||||
return false
|
||||
}
|
||||
|
||||
// 格式化为16进制字符串
|
||||
sha := fmt.Sprintf("%x", h.Sum(nil))
|
||||
log.Infoln("db_sha: " + sha)
|
||||
if sha != dbSum {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
func DownloadDbFile() {
|
||||
log.Infoln("正在从github下载题库文件!")
|
||||
response, err := http.Get("https://github.com/johlanse/study_xxqg/releases/download/v1.0.34/QuestionBank.db")
|
||||
if err != nil {
|
||||
log.Errorln("下载db文件错误" + err.Error())
|
||||
return
|
||||
}
|
||||
data, _ := io.ReadAll(response.Body)
|
||||
err = os.WriteFile("./QuestionBank.db", data, 0666)
|
||||
if err != nil {
|
||||
log.Errorln(err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue