mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2026-05-06 22:12:23 +08:00
53 lines
1.0 KiB
Go
53 lines
1.0 KiB
Go
package config
|
|
|
|
import (
|
|
"net/http"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/0xJacky/Nginx-UI/internal/config"
|
|
"github.com/0xJacky/Nginx-UI/internal/helper"
|
|
"github.com/0xJacky/Nginx-UI/query"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/uozi-tech/cosy"
|
|
)
|
|
|
|
func GetConfig(c *gin.Context) {
|
|
path := helper.UnescapeURL(c.Query("path"))
|
|
|
|
absPath, err := config.ResolveAbsoluteOrRelativeConfPath(path)
|
|
if err != nil {
|
|
cosy.ErrHandler(c, err)
|
|
return
|
|
}
|
|
|
|
stat, err := os.Stat(absPath)
|
|
if err != nil {
|
|
cosy.ErrHandler(c, err)
|
|
return
|
|
}
|
|
|
|
content, err := os.ReadFile(absPath)
|
|
if err != nil {
|
|
cosy.ErrHandler(c, err)
|
|
return
|
|
}
|
|
|
|
q := query.Config
|
|
cfg, err := q.Where(q.Filepath.Eq(absPath)).FirstOrInit()
|
|
if err != nil {
|
|
cosy.ErrHandler(c, err)
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, config.Config{
|
|
Name: stat.Name(),
|
|
Content: string(content),
|
|
FilePath: absPath,
|
|
ModifiedAt: stat.ModTime(),
|
|
Dir: filepath.Dir(absPath),
|
|
SyncNodeIds: cfg.SyncNodeIds,
|
|
SyncOverwrite: cfg.SyncOverwrite,
|
|
})
|
|
}
|