refactor: consolidate maintenance mode endpoints and enhance site status handling

This commit is contained in:
Jacky 2025-04-08 02:53:21 +00:00
parent a2d5f005b0
commit df304b41bc
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
29 changed files with 2102 additions and 1816 deletions

View file

@ -23,7 +23,7 @@ func CheckAndCreateHistory(path string, content string) error {
// Read the current content of the file
currentContent, err := os.ReadFile(path)
if err != nil {
return err
return nil
}
// Compare the contents

View file

@ -28,6 +28,7 @@ func Delete(name string) (err error) {
}
enabledPath := nginx.GetConfPath("sites-enabled", name)
maintenancePath := nginx.GetConfPath("sites-available", name+MaintenanceSuffix)
if !helper.FileExists(availablePath) {
return ErrSiteNotFound
@ -37,6 +38,10 @@ func Delete(name string) (err error) {
return ErrSiteIsEnabled
}
if helper.FileExists(maintenancePath) {
return ErrSiteIsInMaintenance
}
certModel := model.Cert{Filename: name}
_ = certModel.Remove()

View file

@ -3,8 +3,9 @@ package site
import "github.com/uozi-tech/cosy"
var (
e = cosy.NewErrorScope("site")
ErrSiteNotFound = e.New(40401, "site not found")
ErrDstFileExists = e.New(50001, "destination file already exists")
ErrSiteIsEnabled = e.New(50002, "site is enabled")
e = cosy.NewErrorScope("site")
ErrSiteNotFound = e.New(40401, "site not found")
ErrDstFileExists = e.New(50001, "destination file already exists")
ErrSiteIsEnabled = e.New(50002, "site is enabled")
ErrSiteIsInMaintenance = e.New(50003, "site is in maintenance mode")
)

View file

@ -316,7 +316,7 @@ func syncEnableMaintenance(name string) {
client.SetBaseURL(node.URL)
resp, err := client.R().
SetHeader("X-Node-Secret", node.Token).
Post(fmt.Sprintf("/api/sites/%s/maintenance/enable", name))
Post(fmt.Sprintf("/api/sites/%s/maintenance", name))
if err != nil {
notification.Error("Enable Remote Site Maintenance Error", err.Error(), nil)
return
@ -354,7 +354,7 @@ func syncDisableMaintenance(name string) {
client.SetBaseURL(node.URL)
resp, err := client.R().
SetHeader("X-Node-Secret", node.Token).
Post(fmt.Sprintf("/api/sites/%s/maintenance/disable", name))
Post(fmt.Sprintf("/api/sites/%s/enable", name))
if err != nil {
notification.Error("Disable Remote Site Maintenance Error", err.Error(), nil)
return