feat: webhook回调支持口令鉴权

This commit is contained in:
lixiangwuxian 2025-03-24 11:29:05 +08:00
parent 9d512fd4e3
commit 15a3677408
2 changed files with 9 additions and 0 deletions

View File

@ -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() {

View File

@ -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 {