♻️ Refactored site config synchronization

This commit is contained in:
LittleSheep 2023-12-12 20:52:57 +08:00
parent 4dc2729024
commit 6905c60d82
2 changed files with 8 additions and 26 deletions

View File

@ -30,19 +30,16 @@ func doSyncSite(c *fiber.Ctx) error {
defer file.Close()
}
pushed := false
sign.App.Sites = lo.Map(sign.App.Sites, func(item *sign.SiteConfig, idx int) *sign.SiteConfig {
if item.ID == id {
pushed = true
return &req
} else {
return item
if site, ok := lo.Find(sign.App.Sites, func(item *sign.SiteConfig) bool {
return item.ID == id
}); ok {
for _, process := range site.Processes {
process.StopProcess()
}
})
if !pushed {
sign.App.Sites = append(sign.App.Sites, &req)
}
// Reload
sign.ReadInConfig(viper.GetString("paths.configs"))
return c.SendStatus(fiber.StatusOK)
}

View File

@ -43,18 +43,3 @@ func ReadInConfig(root string) error {
return nil
}
func SaveInConfig(root string, cfg *AppConfig) error {
for _, site := range cfg.Sites {
data, _ := yaml.Marshal(site)
fp := filepath.Join(root, site.ID)
if file, err := os.OpenFile(fp, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755); err != nil {
return err
} else if _, err := file.Write(data); err != nil {
return err
}
}
return nil
}