diff --git a/adapter/midjourney/api.go b/adapter/midjourney/api.go index 62940f0..f27a1c2 100644 --- a/adapter/midjourney/api.go +++ b/adapter/midjourney/api.go @@ -1,9 +1,9 @@ package midjourney import ( + "chat/globals" "chat/utils" "fmt" - "github.com/spf13/viper" "strings" ) @@ -21,7 +21,7 @@ func (c *ChatInstance) CreateImagineRequest(prompt string) (*ImagineResponse, er ImagineRequest{ NotifyHook: fmt.Sprintf( "%s/mj/notify", - viper.GetString("system.general.backend"), + globals.NotifyUrl, ), Prompt: prompt, }, diff --git a/auth/controller.go b/auth/controller.go index c23ff65..ad60546 100644 --- a/auth/controller.go +++ b/auth/controller.go @@ -263,6 +263,16 @@ func StateAPI(c *gin.Context) { }) } +func IndexAPI(c *gin.Context) { + username := utils.GetUserFromContext(c) + + c.JSON(http.StatusOK, gin.H{ + "status": true, + "auth": len(username) != 0, + "method": c.Request.Method, + }) +} + func KeyAPI(c *gin.Context) { user := GetUser(c) if user == nil { diff --git a/auth/router.go b/auth/router.go index 0357336..76a1ad5 100644 --- a/auth/router.go +++ b/auth/router.go @@ -3,6 +3,7 @@ package auth import "github.com/gin-gonic/gin" func Register(app *gin.RouterGroup) { + app.Any("/", IndexAPI) app.POST("/verify", VerifyAPI) app.POST("/reset", ResetAPI) app.POST("/register", RegisterAPI) diff --git a/channel/system.go b/channel/system.go index 04e9ca2..fdce49e 100644 --- a/channel/system.go +++ b/channel/system.go @@ -1,6 +1,7 @@ package channel import ( + "chat/globals" "chat/utils" "fmt" "github.com/spf13/viper" @@ -15,8 +16,8 @@ type ApiInfo struct { } type generalState struct { - Title string `json:"title" mapstructure:"title,omitempty"` - Logo string `json:"logo" mapstructure:"logo,omitempty"` + Title string `json:"title" mapstructure:"title"` + Logo string `json:"logo" mapstructure:"logo"` Backend string `json:"backend" mapstructure:"backend"` File string `json:"file" mapstructure:"file"` Docs string `json:"docs" mapstructure:"docs"` @@ -47,18 +48,18 @@ func NewSystemConfig() *SystemConfig { panic(err) } + conf.Load() return conf } +func (c *SystemConfig) Load() { + globals.NotifyUrl = c.GetBackend() +} + func (c *SystemConfig) SaveConfig() error { viper.Set("system", c) + c.Load() - // fix: import cycle not allowed - { - viper.Set("system.general.backend", c.GetBackend()) - viper.Set("system.general.title", c.General.Title) - viper.Set("system.general.logo", c.General.Logo) - } return viper.WriteConfig() } diff --git a/globals/variables.go b/globals/variables.go index 5f840c2..7e51168 100644 --- a/globals/variables.go +++ b/globals/variables.go @@ -16,6 +16,8 @@ var AllowedOrigins = []string{ "fystart.com", } +var NotifyUrl = "" + func OriginIsAllowed(uri string) bool { instance, _ := url.Parse(uri) if instance == nil {