mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 10:25:52 +02:00
feat: add category option for site
This commit is contained in:
parent
7ad5cac3b8
commit
207f80f858
16 changed files with 1452 additions and 508 deletions
|
@ -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) {
|
||||
|
|
|
@ -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"`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue