feat: add category option for site

This commit is contained in:
Jacky 2024-10-25 10:00:50 +08:00
parent 7ad5cac3b8
commit 207f80f858
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
16 changed files with 1452 additions and 508 deletions

View file

@ -69,7 +69,7 @@ func GetSite(c *gin.Context) {
c.JSON(http.StatusOK, Site{
ModifiedAt: file.ModTime(),
Advanced: site.Advanced,
Site: site,
Enabled: enabled,
Name: name,
Config: string(origContent),
@ -102,7 +102,7 @@ func GetSite(c *gin.Context) {
c.JSON(http.StatusOK, Site{
ModifiedAt: file.ModTime(),
Advanced: site.Advanced,
Site: site,
Enabled: enabled,
Name: name,
Config: nginxConfig.FmtCode(),
@ -125,9 +125,10 @@ func SaveSite(c *gin.Context) {
}
var json struct {
Name string `json:"name" binding:"required"`
Content string `json:"content" binding:"required"`
Overwrite bool `json:"overwrite"`
Name string `json:"name" binding:"required"`
Content string `json:"content" binding:"required"`
SiteCategoryID uint64 `json:"site_category_id"`
Overwrite bool `json:"overwrite"`
}
if !api.BindAndValid(c, &json) {
@ -149,11 +150,18 @@ func SaveSite(c *gin.Context) {
return
}
enabledConfigFilePath := nginx.GetConfPath("sites-enabled", name)
s := query.Site
_, err = s.Where(s.Path.Eq(path)).Update(s.SiteCategoryID, json.SiteCategoryID)
if err != nil {
api.ErrHandler(c, err)
return
}
// rename the config file if needed
if name != json.Name {
newPath := nginx.GetConfPath("sites-available", json.Name)
s := query.Site
_, err = s.Where(s.Path.Eq(path)).Update(s.Path, newPath)
_, _ = s.Where(s.Path.Eq(path)).Update(s.Path, newPath)
// check if dst file exists, do not rename
if helper.FileExists(newPath) {

View file

@ -3,15 +3,16 @@ package sites
import (
"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"
"time"
)
type Site struct {
ModifiedAt time.Time `json:"modified_at"`
Advanced bool `json:"advanced"`
Enabled bool `json:"enabled"`
*model.Site
Name string `json:"name"`
ModifiedAt time.Time `json:"modified_at"`
Enabled bool `json:"enabled"`
Config string `json:"config"`
AutoCert bool `json:"auto_cert"`
ChatGPTMessages []openai.ChatCompletionMessage `json:"chatgpt_messages,omitempty"`