♻️ Refactored site config synchronization
This commit is contained in:
parent
4dc2729024
commit
6905c60d82
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user