mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 04:30:05 +00:00
Refactor: Load UserTemplates from embedded yaml file (#575)
* Refactor: Load UserTemplates from embedded yaml file * feat: add version field to UserTemplates * refactor: use shell script to fetch frontends * chore: add *-dist to .gitignore * refactor: rename to FrontendTemplates BREAKING CHANGE: This commit changes the `user_templates` filed in the communication json between backend and the admin-frontend. Keep user config.yml `user_template` filed.
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package singleton
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/patrickmn/go-cache"
|
||||
"gopkg.in/yaml.v3"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
|
||||
@@ -15,27 +17,17 @@ import (
|
||||
var Version = "debug"
|
||||
|
||||
var (
|
||||
Conf *model.Config
|
||||
Cache *cache.Cache
|
||||
DB *gorm.DB
|
||||
Loc *time.Location
|
||||
UserTemplates = []model.UserTemplate{
|
||||
{
|
||||
Path: "user-dist",
|
||||
Name: "Official",
|
||||
Repository: "https://github.com/hamster1963/nezha-dash",
|
||||
Author: "hamster1963",
|
||||
}, {
|
||||
Path: "nazhua-dist",
|
||||
Name: "Nazhua",
|
||||
Repository: "https://github.com/hi2shark/nazhua",
|
||||
Author: "hi2hi",
|
||||
Community: true,
|
||||
},
|
||||
}
|
||||
Conf *model.Config
|
||||
Cache *cache.Cache
|
||||
DB *gorm.DB
|
||||
Loc *time.Location
|
||||
FrontendTemplates []model.FrontendTemplate
|
||||
DashboardBootTime = uint64(time.Now().Unix())
|
||||
)
|
||||
|
||||
//go:embed frontend-templates.yaml
|
||||
var frontendTemplatesYAML []byte
|
||||
|
||||
func InitTimezoneAndCache() {
|
||||
var err error
|
||||
Loc, err = time.LoadLocation(Conf.Location)
|
||||
@@ -56,10 +48,18 @@ func LoadSingleton() {
|
||||
initDDNS()
|
||||
}
|
||||
|
||||
// InitFrontendTemplates 从内置文件中加载FrontendTemplates
|
||||
func InitFrontendTemplates() {
|
||||
err := yaml.Unmarshal(frontendTemplatesYAML, &FrontendTemplates)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// InitConfigFromPath 从给出的文件路径中加载配置
|
||||
func InitConfigFromPath(path string) {
|
||||
Conf = &model.Config{}
|
||||
err := Conf.Read(path, UserTemplates)
|
||||
err := Conf.Read(path, FrontendTemplates)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user