新增配置项cron_random_wait,tg推送信息修改,新增文档
This commit is contained in:
parent
241a1e953f
commit
7f0255c551
|
@ -8,7 +8,8 @@ RUN mkdir /opt/config/
|
|||
|
||||
COPY conf/config_default.yml /opt/config/config.yml
|
||||
|
||||
RUN apt-get -qq update \
|
||||
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
|
||||
echo 'Asia/Shanghai' >/etc/timezone && apt-get -qq update \
|
||||
&& apt-get -qq install -y --no-install-recommends ca-certificates curl \
|
||||
&& apt-get update && apt-get install -y libx11-6 libgbm1 libasound2 libcairo2 libxshmfence1 libatspi2.0-0 libpango-1.0-0 libnss3 \
|
||||
libatk1.0-0 libatk-bridge2.0-0 libcups2 libxrandr2 libxfixes3 libxdamage1 libxcomposite1 libxkbcommon0 \
|
||||
|
|
|
@ -44,6 +44,7 @@ type Config struct {
|
|||
Announcement string `json:"announcement" yaml:"announcement"`
|
||||
} `json:"web"`
|
||||
Cron string `json:"cron" yaml:"cron"`
|
||||
CronRandomWait int `json:"cron_random_wait" yaml:"cron_random_wait"`
|
||||
EdgePath string `json:"edge_path" yaml:"edge_path"`
|
||||
QrCOde bool `json:"qr_code" yaml:"qr_code"`
|
||||
StartWait int `json:"start_wait" yaml:"start_wait"`
|
||||
|
|
|
@ -84,6 +84,9 @@ retry:
|
|||
# "* 10 * * *” 每天早上十点执行一次
|
||||
cron: "0 0 * * *"
|
||||
|
||||
# 定时任务随机等待时间,单位:分钟
|
||||
cron_random_wait: 0
|
||||
|
||||
#windows环境自定义浏览器路径,仅支持chromium系列
|
||||
edge_path: ""
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* [源码运行](./custom/index)
|
||||
* [推送配置](./push.md)
|
||||
* [配置文件](./config.md)
|
||||
* [跳板搭建](./scheme.md)
|
||||
* [常见问题](./problem.md)
|
||||
* [做出贡献](./contribute.md)
|
||||
* [加群交流](https://t.me/+VWI88z6d1k45NGJl)
|
|
@ -65,7 +65,7 @@ web:
|
|||
password: admin
|
||||
```
|
||||
|
||||
+ 开启后通过浏览器访问 *http://ip:port*即可打开网址 ,若为docker运行,则ip为宿主机公网ip,端口为docker映射到宿主机的端口
|
||||
+ 开启后通过浏览器访问 *http://ip:port*或者*http://ip:port/new*即可打开网址 ,若为docker运行,则ip为宿主机公网ip,端口为docker映射到宿主机的端口
|
||||
+ 若无法访问,首先检查程序运行日志,查看有无报错,其次查看docker的运行情况,端口是否映射正常,然后可以通过curl命令检测在宿主机中能否访问,然后检查防火墙之类的
|
||||
+ 若点击登录之后出现一个小框然后无反应,则说明账户密码错误,请重新配置程序账户密码并重启程序
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
因为学习强国官方app的scheme是dtxuexi://,但是大部分浏览器并不能识别该scheme,所以可以通过自行搭建跳板进行跳转。
|
||||
|
||||
study_xxqg官方搭建的跳板是使用github page进行搭建的,可能访问情况会比较慢,所以可以进自行搭建跳板。
|
||||
|
||||
## 搭建方法
|
||||
+ 在config目录下的创建dist目录
|
||||
+ 将仓库下docs目录里面的**scheme.html**和**qrcode.js**放入该目录
|
||||
+ 配置scheme为**http://ip:port/dist/scheme.html?**
|
||||
+ 重启程序
|
||||
|
||||
> 也可以通过其他静态文件服务器搭建,如 nginx等
|
|
@ -5,5 +5,5 @@ import (
|
|||
)
|
||||
|
||||
func TestName1(t *testing.T) {
|
||||
CheckUserCookie(User{})
|
||||
|
||||
}
|
||||
|
|
18
lib/tg.go
18
lib/tg.go
|
@ -171,7 +171,11 @@ func login(bot *Telegram, args []string) {
|
|||
newMessage := tgbotapi.NewMessage(bot.ChatId, message)
|
||||
newMessage.ParseMode = tgbotapi.ModeMarkdownV2
|
||||
bot.bot.Send(newMessage)
|
||||
default:
|
||||
case kind == "text":
|
||||
if log.GetLevel() == log.DebugLevel {
|
||||
bot.SendMsg(message)
|
||||
}
|
||||
case kind == "flush":
|
||||
bot.SendMsg(message)
|
||||
}
|
||||
},
|
||||
|
@ -229,7 +233,11 @@ func studyAll(bot *Telegram, args []string) {
|
|||
newMessage.ParseMode = tgbotapi.ModeMarkdownV2
|
||||
_, _ = bot.bot.Send(newMessage)
|
||||
|
||||
default:
|
||||
case kind == "text":
|
||||
if log.GetLevel() == log.DebugLevel {
|
||||
bot.SendMsg(message)
|
||||
}
|
||||
case kind == "flush":
|
||||
bot.SendMsg(message)
|
||||
}
|
||||
},
|
||||
|
@ -322,7 +330,11 @@ func study(bot *Telegram, args []string) {
|
|||
newMessage.ParseMode = tgbotapi.ModeMarkdownV2
|
||||
_, _ = bot.bot.Send(newMessage)
|
||||
|
||||
default:
|
||||
case kind == "text":
|
||||
if log.GetLevel() == log.DebugLevel {
|
||||
bot.SendMsg(message)
|
||||
}
|
||||
case kind == "flush":
|
||||
bot.SendMsg(message)
|
||||
}
|
||||
},
|
||||
|
|
15
main.go
15
main.go
|
@ -4,6 +4,7 @@ import (
|
|||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
|
@ -101,9 +102,11 @@ func main() {
|
|||
go func() {
|
||||
h := http.NewServeMux()
|
||||
if config.Web.Enable {
|
||||
log.Infoln(fmt.Sprintf("已开启web配置,web监听地址 ==> %v:%v", config.Web.Host, config.Web.Port))
|
||||
h.Handle("/", engine)
|
||||
}
|
||||
if config.Wechat.Enable {
|
||||
log.Infoln(fmt.Sprintf("已开启wechat公众号配置,监听地址: ==》 %v:%v", config.Web.Host, config.Web.Port))
|
||||
h.HandleFunc("/wx", web.HandleWechat)
|
||||
}
|
||||
if config.Web.Enable || config.Wechat.Enable {
|
||||
|
@ -129,7 +132,10 @@ func main() {
|
|||
}
|
||||
}()
|
||||
log.Infoln("已采用定时执行模式")
|
||||
c := cron.New()
|
||||
c := cron.New(func(c *cron.Cron) {
|
||||
|
||||
})
|
||||
|
||||
_, err := c.AddFunc(config.Cron, func() {
|
||||
defer func() {
|
||||
i := recover()
|
||||
|
@ -138,6 +144,13 @@ func main() {
|
|||
log.Errorln("执行定时任务出现异常")
|
||||
}
|
||||
}()
|
||||
log.Infoln("即将开始执行定时任务")
|
||||
// 检测是否开启了随机等待
|
||||
if config.CronRandomWait > 0 {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
r := rand.Intn(config.CronRandomWait)
|
||||
time.Sleep(time.Duration(r) * time.Minute)
|
||||
}
|
||||
do("cron")
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
@ -5,7 +5,6 @@ package web
|
|||
import (
|
||||
"embed"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
@ -27,6 +26,7 @@ var newUI embed.FS
|
|||
// @return *gin.Engine
|
||||
func RouterInit() *gin.Engine {
|
||||
router := gin.Default()
|
||||
router.RemoveExtraSlash = true
|
||||
router.Use(cors())
|
||||
|
||||
// 挂载静态文件
|
||||
|
@ -47,7 +47,7 @@ func RouterInit() *gin.Engine {
|
|||
f, err := newUI.ReadFile(strings.TrimLeft(ctx.Param("file"), "/"))
|
||||
if err != nil {
|
||||
log.Errorln(err.Error())
|
||||
f, _ = newUI.ReadFile("app/home.html")
|
||||
f, _ = newUI.ReadFile("app/index.html")
|
||||
}
|
||||
_, _ = ctx.Writer.Write(f)
|
||||
ctx.Status(200)
|
||||
|
@ -59,15 +59,9 @@ func RouterInit() *gin.Engine {
|
|||
// 检查登录状态的token是否正确
|
||||
auth.POST("/check/:token", checkToken())
|
||||
|
||||
dir, _ := os.Getwd()
|
||||
// 对于用户可自定义挂载文件的目录
|
||||
if utils.FileIsExist("dist") {
|
||||
router.GET("/dist/*file", func(ctx *gin.Context) {
|
||||
if strings.HasSuffix(ctx.Request.URL.Path, "js") {
|
||||
ctx.Header("Content-Type", "application/javascript; charset=utf-8")
|
||||
}
|
||||
ctx.File(dir + ctx.Request.URL.Path)
|
||||
})
|
||||
if utils.FileIsExist("./config/dist/") {
|
||||
router.StaticFS("/dist", http.Dir("./config/dist/"))
|
||||
}
|
||||
|
||||
// 对用户管理的组
|
||||
|
@ -89,7 +83,7 @@ func RouterInit() *gin.Engine {
|
|||
router.GET("/log", check(), getLog())
|
||||
|
||||
// 登录xxqg的三个接口
|
||||
router.GET("/sign/*proxyPath", check(), sign())
|
||||
router.GET("/sign/", check(), sign())
|
||||
router.GET("/login/*proxyPath", check(), generate())
|
||||
router.POST("/login/*proxyPath", check(), generate())
|
||||
return router
|
||||
|
|
Loading…
Reference in New Issue