Skip to content

Commit 287ef75

Browse files
committed
refactor: refactor app and api
1 parent 5ab50b8 commit 287ef75

File tree

157 files changed

+8080
-3551
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+8080
-3551
lines changed

.air.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ bin = "tmp/main"
1313
# Customize binary.
1414
full_bin = "APP_ENV=dev APP_USER=air ./tmp/main"
1515
# Watch these filename extensions.
16-
include_ext = ["go", "tpl", "tmpl", "html", "toml"]
16+
include_ext = ["go", "tpl", "tmpl", "html", "toml", "po"]
1717
# Ignore these filename extensions or directories.
18-
exclude_dir = ["assets", "tmp", "vendor", "app/node_modules", "upload", "docs", "resources", .ts", ".vue", ".tsx", ".idea"]
18+
exclude_dir = ["assets", "tmp", "vendor", "app/node_modules", "upload", "docs", "resources", ".idea"]
1919
# Watch these directories if you specified.
20-
include_dir = ["app/src/language"]
20+
include_dir = []
2121
# Exclude files.
2222
exclude_file = []
2323
# Exclude specific regular expressions.
@@ -51,3 +51,6 @@ runner = "green"
5151
[misc]
5252
# Delete tmp directory on exit
5353
clean_on_exit = true
54+
55+
[screen]
56+
keep_scroll = true

api/certificate/router.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ func InitCertificateRouter(r *gin.RouterGroup) {
1717
r.POST("cert", AddCert)
1818
r.POST("cert/:id", ModifyCert)
1919
r.DELETE("cert/:id", RemoveCert)
20-
r.GET("auto_cert/dns/providers", GetDNSProvidersList)
21-
r.GET("auto_cert/dns/provider/:code", GetDNSProvider)
20+
r.GET("certificate/dns_providers", GetDNSProvidersList)
21+
r.GET("certificate/dns_provider/:code", GetDNSProvider)
2222
}

api/config/add.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package config
2+
3+
import (
4+
"github.com/0xJacky/Nginx-UI/api"
5+
"github.com/0xJacky/Nginx-UI/internal/config"
6+
"github.com/0xJacky/Nginx-UI/internal/nginx"
7+
"github.com/gin-gonic/gin"
8+
"net/http"
9+
"os"
10+
)
11+
12+
func AddConfig(c *gin.Context) {
13+
var request struct {
14+
Name string `json:"name" binding:"required"`
15+
Content string `json:"content" binding:"required"`
16+
}
17+
18+
err := c.BindJSON(&request)
19+
if err != nil {
20+
api.ErrHandler(c, err)
21+
return
22+
}
23+
24+
name := request.Name
25+
content := request.Content
26+
27+
path := nginx.GetConfPath("/", name)
28+
29+
if _, err = os.Stat(path); err == nil {
30+
c.JSON(http.StatusNotAcceptable, gin.H{
31+
"message": "config exist",
32+
})
33+
return
34+
}
35+
36+
if content != "" {
37+
err = os.WriteFile(path, []byte(content), 0644)
38+
if err != nil {
39+
api.ErrHandler(c, err)
40+
return
41+
}
42+
}
43+
44+
output := nginx.Reload()
45+
if nginx.GetLogLevel(output) >= nginx.Warn {
46+
c.JSON(http.StatusInternalServerError, gin.H{
47+
"message": output,
48+
})
49+
return
50+
}
51+
52+
c.JSON(http.StatusOK, config.Config{
53+
Name: name,
54+
Content: content,
55+
})
56+
}

api/config/config.go

Lines changed: 0 additions & 206 deletions
This file was deleted.

api/config/get.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package config
2+
3+
import (
4+
"github.com/0xJacky/Nginx-UI/api"
5+
"github.com/0xJacky/Nginx-UI/internal/config"
6+
"github.com/0xJacky/Nginx-UI/internal/nginx"
7+
"github.com/0xJacky/Nginx-UI/query"
8+
"github.com/gin-gonic/gin"
9+
"github.com/sashabaranov/go-openai"
10+
"net/http"
11+
"os"
12+
)
13+
14+
func GetConfig(c *gin.Context) {
15+
name := c.Param("name")
16+
path := nginx.GetConfPath("/", name)
17+
18+
stat, err := os.Stat(path)
19+
20+
if err != nil {
21+
api.ErrHandler(c, err)
22+
return
23+
}
24+
25+
content, err := os.ReadFile(path)
26+
27+
if err != nil {
28+
api.ErrHandler(c, err)
29+
return
30+
}
31+
32+
g := query.ChatGPTLog
33+
chatgpt, err := g.Where(g.Name.Eq(path)).FirstOrCreate()
34+
35+
if err != nil {
36+
api.ErrHandler(c, err)
37+
return
38+
}
39+
40+
if chatgpt.Content == nil {
41+
chatgpt.Content = make([]openai.ChatCompletionMessage, 0)
42+
}
43+
44+
c.JSON(http.StatusOK, config.Config{
45+
Name: name,
46+
Content: string(content),
47+
ChatGPTMessages: chatgpt.Content,
48+
FilePath: path,
49+
ModifiedAt: stat.ModTime(),
50+
})
51+
}

0 commit comments

Comments
 (0)