mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 12:40:07 +00:00
feat: multi user template
This commit is contained in:
@@ -249,11 +249,11 @@ func fallbackToFrontend(adminFrontend, userFrontend fs.FS) func(*gin.Context) {
|
||||
}
|
||||
return
|
||||
}
|
||||
localFilePath := path.Join("user-dist", c.Request.URL.Path)
|
||||
localFilePath := path.Join(singleton.Conf.UserTemplate, c.Request.URL.Path)
|
||||
if checkLocalFileOrFs(c, userFrontend, localFilePath) {
|
||||
return
|
||||
}
|
||||
if !checkLocalFileOrFs(c, userFrontend, "user-dist/index.html") {
|
||||
if !checkLocalFileOrFs(c, userFrontend, singleton.Conf.UserTemplate+"/index.html") {
|
||||
c.JSON(http.StatusOK, newErrorResponse(errors.New("404 Not Found")))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/nezhahq/nezha/model"
|
||||
@@ -21,8 +23,9 @@ func listConfig(c *gin.Context) (model.SettingResponse, error) {
|
||||
authorized := isMember // TODO || isViewPasswordVerfied
|
||||
|
||||
conf := model.SettingResponse{
|
||||
Config: *singleton.Conf,
|
||||
Version: singleton.Version,
|
||||
Config: *singleton.Conf,
|
||||
Version: singleton.Version,
|
||||
UserTemplates: singleton.UserTemplates,
|
||||
}
|
||||
|
||||
if !authorized {
|
||||
@@ -55,7 +58,16 @@ func updateConfig(c *gin.Context) (any, error) {
|
||||
if err := c.ShouldBindJSON(&sf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var userTemplateValid bool
|
||||
for _, v := range singleton.UserTemplates {
|
||||
if v.Path == sf.UserTemplate {
|
||||
userTemplateValid = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !userTemplateValid {
|
||||
return nil, errors.New("invalid user template")
|
||||
}
|
||||
singleton.Conf.Language = sf.Language
|
||||
singleton.Conf.EnableIPChangeNotification = sf.EnableIPChangeNotification
|
||||
singleton.Conf.EnablePlainIPInNotification = sf.EnablePlainIPInNotification
|
||||
@@ -69,6 +81,7 @@ func updateConfig(c *gin.Context) (any, error) {
|
||||
singleton.Conf.CustomCodeDashboard = sf.CustomCodeDashboard
|
||||
singleton.Conf.RealIPHeader = sf.RealIPHeader
|
||||
singleton.Conf.TLS = sf.TLS
|
||||
singleton.Conf.UserTemplate = sf.UserTemplate
|
||||
|
||||
if err := singleton.Conf.Save(); err != nil {
|
||||
return nil, newGormError("%v", err)
|
||||
|
||||
@@ -82,7 +82,7 @@ func updateProfile(c *gin.Context) (any, error) {
|
||||
// @Router /user [get]
|
||||
func listUser(c *gin.Context) ([]model.User, error) {
|
||||
var users []model.User
|
||||
if err := singleton.DB.Find(&users).Error; err != nil {
|
||||
if err := singleton.DB.Omit("password").Find(&users).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return users, nil
|
||||
|
||||
Reference in New Issue
Block a user