mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 10:25:52 +02:00
feat(site): implement site status management and update related components
This commit is contained in:
parent
402de5d987
commit
502b656bc5
12 changed files with 93 additions and 99 deletions
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/tufanbarisyildirim/gonginx/config"
|
||||
"github.com/tufanbarisyildirim/gonginx/dumper"
|
||||
"github.com/tufanbarisyildirim/gonginx/parser"
|
||||
"github.com/uozi-tech/cosy/logger"
|
||||
)
|
||||
|
||||
type ProxyCacheConfig struct {
|
||||
|
@ -189,7 +190,10 @@ func updateOrRemoveProxyCachePath(block config.IBlock, directives []config.IDire
|
|||
// First parameter is the path (required)
|
||||
if proxyCache.Path != "" {
|
||||
params = append(params, config.Parameter{Value: proxyCache.Path})
|
||||
_ = os.MkdirAll(proxyCache.Path, 0755)
|
||||
err := os.MkdirAll(proxyCache.Path, 0755)
|
||||
if err != nil {
|
||||
logger.Error("failed to create proxy cache path", err)
|
||||
}
|
||||
} else {
|
||||
// No path specified, can't add the directive
|
||||
return
|
||||
|
|
21
internal/site/status.go
Normal file
21
internal/site/status.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
package site
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/internal/helper"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
)
|
||||
|
||||
// GetSiteStatus returns the status of the site
|
||||
func GetSiteStatus(name string) SiteStatus {
|
||||
enabledFilePath := nginx.GetConfPath("sites-enabled", name)
|
||||
if helper.FileExists(enabledFilePath) {
|
||||
return SiteStatusEnabled
|
||||
}
|
||||
|
||||
mantainanceFilePath := nginx.GetConfPath("sites-enabled", name+MaintenanceSuffix)
|
||||
if helper.FileExists(mantainanceFilePath) {
|
||||
return SiteStatusMaintenance
|
||||
}
|
||||
|
||||
return SiteStatusDisabled
|
||||
}
|
31
internal/site/type.go
Normal file
31
internal/site/type.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package site
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/0xJacky/Nginx-UI/internal/cert"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/sashabaranov/go-openai"
|
||||
)
|
||||
|
||||
type SiteStatus string
|
||||
|
||||
const (
|
||||
SiteStatusEnabled SiteStatus = "enabled"
|
||||
SiteStatusDisabled SiteStatus = "disabled"
|
||||
SiteStatusMaintenance SiteStatus = "maintenance"
|
||||
)
|
||||
|
||||
type Site struct {
|
||||
*model.Site
|
||||
Name string `json:"name"`
|
||||
ModifiedAt time.Time `json:"modified_at"`
|
||||
Status SiteStatus `json:"status"`
|
||||
Config string `json:"config"`
|
||||
AutoCert bool `json:"auto_cert"`
|
||||
ChatGPTMessages []openai.ChatCompletionMessage `json:"chatgpt_messages,omitempty"`
|
||||
Tokenized *nginx.NgxConfig `json:"tokenized,omitempty"`
|
||||
CertInfo map[int][]*cert.Info `json:"cert_info,omitempty"`
|
||||
Filepath string `json:"filepath"`
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue