mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
refactor: consolidate maintenance mode endpoints and enhance site status handling
This commit is contained in:
parent
a2d5f005b0
commit
df304b41bc
29 changed files with 2102 additions and 1816 deletions
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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")
|
||||
)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue