♻️ 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() defer file.Close()
} }
pushed := false if site, ok := lo.Find(sign.App.Sites, func(item *sign.SiteConfig) bool {
sign.App.Sites = lo.Map(sign.App.Sites, func(item *sign.SiteConfig, idx int) *sign.SiteConfig { return item.ID == id
if item.ID == id { }); ok {
pushed = true for _, process := range site.Processes {
return &req process.StopProcess()
} else {
return item
} }
})
if !pushed {
sign.App.Sites = append(sign.App.Sites, &req)
} }
// Reload
sign.ReadInConfig(viper.GetString("paths.configs"))
return c.SendStatus(fiber.StatusOK) return c.SendStatus(fiber.StatusOK)
} }

View File

@ -43,18 +43,3 @@ func ReadInConfig(root string) error {
return nil 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
}