From 15a3677408786de989ae06207ec208f08e06441e Mon Sep 17 00:00:00 2001 From: lixiangwuxian Date: Mon, 24 Mar 2025 11:29:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20webhook=E5=9B=9E=E8=B0=83=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=8F=A3=E4=BB=A4=E9=89=B4=E6=9D=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.go | 3 +++ handler/restart/restart.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/config/config.go b/config/config.go index 5a8c0e1..f3d6bab 100644 --- a/config/config.go +++ b/config/config.go @@ -18,6 +18,9 @@ type Config struct { OpenaiApiBaseUrl string `yaml:"openai_api_base_url"` OpenaiModelName string `yaml:"openai_model_name"` OpenaiPrompt string `yaml:"openai_prompt"` + WebServer struct { + Token string `yaml:"token"` + } `yaml:"web_server"` } func init() { diff --git a/handler/restart/restart.go b/handler/restart/restart.go index b80f9ab..62ee07a 100644 --- a/handler/restart/restart.go +++ b/handler/restart/restart.go @@ -8,6 +8,7 @@ import ( "os/exec" "time" + "git.lxtend.com/qqbot/config" "git.lxtend.com/qqbot/constants" "git.lxtend.com/qqbot/handler" "git.lxtend.com/qqbot/model" @@ -186,6 +187,11 @@ func BuildBotHandler(c *gin.Context) { } func RestartBotHandler(c *gin.Context) { + token := c.Request.Header.Get("Authorization") + if token != config.ConfigManager.GetConfig().WebServer.Token { + c.JSON(http.StatusUnauthorized, gin.H{"error": "Unauthorized"}) + return + } err := restartProgram() log.Println("重启程序...") if err != nil {