feat: webhook回调支持口令鉴权
This commit is contained in:
parent
9d512fd4e3
commit
15a3677408
@ -18,6 +18,9 @@ type Config struct {
|
|||||||
OpenaiApiBaseUrl string `yaml:"openai_api_base_url"`
|
OpenaiApiBaseUrl string `yaml:"openai_api_base_url"`
|
||||||
OpenaiModelName string `yaml:"openai_model_name"`
|
OpenaiModelName string `yaml:"openai_model_name"`
|
||||||
OpenaiPrompt string `yaml:"openai_prompt"`
|
OpenaiPrompt string `yaml:"openai_prompt"`
|
||||||
|
WebServer struct {
|
||||||
|
Token string `yaml:"token"`
|
||||||
|
} `yaml:"web_server"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.lxtend.com/qqbot/config"
|
||||||
"git.lxtend.com/qqbot/constants"
|
"git.lxtend.com/qqbot/constants"
|
||||||
"git.lxtend.com/qqbot/handler"
|
"git.lxtend.com/qqbot/handler"
|
||||||
"git.lxtend.com/qqbot/model"
|
"git.lxtend.com/qqbot/model"
|
||||||
@ -186,6 +187,11 @@ func BuildBotHandler(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func RestartBotHandler(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()
|
err := restartProgram()
|
||||||
log.Println("重启程序...")
|
log.Println("重启程序...")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user