Skip to content

Commit

Permalink
refactor: refactor app and api
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJacky committed Nov 28, 2023
1 parent 5ab50b8 commit 287ef75
Show file tree
Hide file tree
Showing 157 changed files with 8,080 additions and 3,551 deletions.
9 changes: 6 additions & 3 deletions .air.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ bin = "tmp/main"
# Customize binary.
full_bin = "APP_ENV=dev APP_USER=air ./tmp/main"
# Watch these filename extensions.
include_ext = ["go", "tpl", "tmpl", "html", "toml"]
include_ext = ["go", "tpl", "tmpl", "html", "toml", "po"]
# Ignore these filename extensions or directories.
exclude_dir = ["assets", "tmp", "vendor", "app/node_modules", "upload", "docs", "resources", .ts", ".vue", ".tsx", ".idea"]
exclude_dir = ["assets", "tmp", "vendor", "app/node_modules", "upload", "docs", "resources", ".idea"]
# Watch these directories if you specified.
include_dir = ["app/src/language"]
include_dir = []
# Exclude files.
exclude_file = []
# Exclude specific regular expressions.
Expand Down Expand Up @@ -51,3 +51,6 @@ runner = "green"
[misc]
# Delete tmp directory on exit
clean_on_exit = true

[screen]
keep_scroll = true
4 changes: 2 additions & 2 deletions api/certificate/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ func InitCertificateRouter(r *gin.RouterGroup) {
r.POST("cert", AddCert)
r.POST("cert/:id", ModifyCert)
r.DELETE("cert/:id", RemoveCert)
r.GET("auto_cert/dns/providers", GetDNSProvidersList)
r.GET("auto_cert/dns/provider/:code", GetDNSProvider)
r.GET("certificate/dns_providers", GetDNSProvidersList)
r.GET("certificate/dns_provider/:code", GetDNSProvider)
}
56 changes: 56 additions & 0 deletions api/config/add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package config

import (
"github.com/0xJacky/Nginx-UI/api"
"github.com/0xJacky/Nginx-UI/internal/config"
"github.com/0xJacky/Nginx-UI/internal/nginx"
"github.com/gin-gonic/gin"
"net/http"
"os"
)

func AddConfig(c *gin.Context) {
var request struct {
Name string `json:"name" binding:"required"`
Content string `json:"content" binding:"required"`
}

err := c.BindJSON(&request)
if err != nil {
api.ErrHandler(c, err)
return
}

name := request.Name
content := request.Content

path := nginx.GetConfPath("/", name)

if _, err = os.Stat(path); err == nil {
c.JSON(http.StatusNotAcceptable, gin.H{
"message": "config exist",
})
return
}

if content != "" {
err = os.WriteFile(path, []byte(content), 0644)
if err != nil {
api.ErrHandler(c, err)
return
}
}

output := nginx.Reload()
if nginx.GetLogLevel(output) >= nginx.Warn {
c.JSON(http.StatusInternalServerError, gin.H{
"message": output,
})
return
}

c.JSON(http.StatusOK, config.Config{
Name: name,
Content: content,
})
}
206 changes: 0 additions & 206 deletions api/config/config.go

This file was deleted.

51 changes: 51 additions & 0 deletions api/config/get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package config

import (
"github.com/0xJacky/Nginx-UI/api"
"github.com/0xJacky/Nginx-UI/internal/config"
"github.com/0xJacky/Nginx-UI/internal/nginx"
"github.com/0xJacky/Nginx-UI/query"
"github.com/gin-gonic/gin"
"github.com/sashabaranov/go-openai"
"net/http"
"os"
)

func GetConfig(c *gin.Context) {
name := c.Param("name")
path := nginx.GetConfPath("/", name)

stat, err := os.Stat(path)

if err != nil {
api.ErrHandler(c, err)
return
}

content, err := os.ReadFile(path)

if err != nil {
api.ErrHandler(c, err)
return
}

g := query.ChatGPTLog
chatgpt, err := g.Where(g.Name.Eq(path)).FirstOrCreate()

if err != nil {
api.ErrHandler(c, err)
return
}

if chatgpt.Content == nil {
chatgpt.Content = make([]openai.ChatCompletionMessage, 0)
}

c.JSON(http.StatusOK, config.Config{
Name: name,
Content: string(content),
ChatGPTMessages: chatgpt.Content,
FilePath: path,
ModifiedAt: stat.ModTime(),
})
}
Loading

0 comments on commit 287ef75

Please sign in to comment.