refactor: refactor app and api
parent
5ab50b8a93
commit
287ef7527d
@ -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,
|
||||
})
|
||||
}
|
||||
@ -1,206 +0,0 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/config_list"
|
||||
"github.com/0xJacky/Nginx-UI/internal/logger"
|
||||
nginx2 "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 GetConfigs(c *gin.Context) {
|
||||
orderBy := c.Query("order_by")
|
||||
sort := c.DefaultQuery("sort", "desc")
|
||||
dir := c.DefaultQuery("dir", "/")
|
||||
|
||||
mySort := map[string]string{
|
||||
"name": "string",
|
||||
"modify": "time",
|
||||
"is_dir": "bool",
|
||||
}
|
||||
|
||||
configFiles, err := os.ReadDir(nginx2.GetConfPath(dir))
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
var configs []gin.H
|
||||
|
||||
for i := range configFiles {
|
||||
file := configFiles[i]
|
||||
fileInfo, _ := file.Info()
|
||||
|
||||
switch mode := fileInfo.Mode(); {
|
||||
case mode.IsRegular(): // regular file, not a hidden file
|
||||
if "." == file.Name()[0:1] {
|
||||
continue
|
||||
}
|
||||
case mode&os.ModeSymlink != 0: // is a symbol
|
||||
var targetPath string
|
||||
targetPath, err = os.Readlink(nginx2.GetConfPath(file.Name()))
|
||||
if err != nil {
|
||||
logger.Error("Read Symlink Error", targetPath, err)
|
||||
continue
|
||||
}
|
||||
|
||||
var targetInfo os.FileInfo
|
||||
targetInfo, err = os.Stat(targetPath)
|
||||
if err != nil {
|
||||
logger.Error("Stat Error", targetPath, err)
|
||||
continue
|
||||
}
|
||||
// but target file is not a dir
|
||||
if targetInfo.IsDir() {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
configs = append(configs, gin.H{
|
||||
"name": file.Name(),
|
||||
"size": fileInfo.Size(),
|
||||
"modify": fileInfo.ModTime(),
|
||||
"is_dir": file.IsDir(),
|
||||
})
|
||||
}
|
||||
|
||||
configs = config_list.Sort(orderBy, sort, mySort[orderBy], configs)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"data": configs,
|
||||
})
|
||||
}
|
||||
|
||||
func GetConfig(c *gin.Context) {
|
||||
name := c.Param("name")
|
||||
path := nginx2.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, gin.H{
|
||||
"config": string(content),
|
||||
"chatgpt_messages": chatgpt.Content,
|
||||
"file_path": path,
|
||||
"modified_at": stat.ModTime(),
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
type AddConfigJson struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
Content string `json:"content" binding:"required"`
|
||||
}
|
||||
|
||||
func AddConfig(c *gin.Context) {
|
||||
var request AddConfigJson
|
||||
err := c.BindJSON(&request)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
name := request.Name
|
||||
content := request.Content
|
||||
|
||||
path := nginx2.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 := nginx2.Reload()
|
||||
if nginx2.GetLogLevel(output) >= nginx2.Warn {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"message": output,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"name": name,
|
||||
"content": content,
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
type EditConfigJson struct {
|
||||
Content string `json:"content" binding:"required"`
|
||||
}
|
||||
|
||||
func EditConfig(c *gin.Context) {
|
||||
name := c.Param("name")
|
||||
var request EditConfigJson
|
||||
err := c.BindJSON(&request)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
path := nginx2.GetConfPath("/", name)
|
||||
content := request.Content
|
||||
|
||||
origContent, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
if content != "" && content != string(origContent) {
|
||||
// model.CreateBackup(path)
|
||||
err = os.WriteFile(path, []byte(content), 0644)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
output := nginx2.Reload()
|
||||
|
||||
if nginx2.GetLogLevel(output) >= nginx2.Warn {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"message": output,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
GetConfig(c)
|
||||
}
|
||||
@ -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(),
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,69 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/config"
|
||||
"github.com/0xJacky/Nginx-UI/internal/logger"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func GetConfigs(c *gin.Context) {
|
||||
orderBy := c.Query("order_by")
|
||||
sort := c.DefaultQuery("sort", "desc")
|
||||
dir := c.DefaultQuery("dir", "/")
|
||||
|
||||
configFiles, err := os.ReadDir(nginx.GetConfPath(dir))
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
var configs []config.Config
|
||||
|
||||
for i := range configFiles {
|
||||
file := configFiles[i]
|
||||
fileInfo, _ := file.Info()
|
||||
|
||||
switch mode := fileInfo.Mode(); {
|
||||
case mode.IsRegular(): // regular file, not a hidden file
|
||||
if "." == file.Name()[0:1] {
|
||||
continue
|
||||
}
|
||||
case mode&os.ModeSymlink != 0: // is a symbol
|
||||
var targetPath string
|
||||
targetPath, err = os.Readlink(nginx.GetConfPath(file.Name()))
|
||||
if err != nil {
|
||||
logger.Error("Read Symlink Error", targetPath, err)
|
||||
continue
|
||||
}
|
||||
|
||||
var targetInfo os.FileInfo
|
||||
targetInfo, err = os.Stat(targetPath)
|
||||
if err != nil {
|
||||
logger.Error("Stat Error", targetPath, err)
|
||||
continue
|
||||
}
|
||||
// but target file is not a dir
|
||||
if targetInfo.IsDir() {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
configs = append(configs, config.Config{
|
||||
Name: file.Name(),
|
||||
ModifiedAt: fileInfo.ModTime(),
|
||||
Size: fileInfo.Size(),
|
||||
IsDir: fileInfo.IsDir(),
|
||||
})
|
||||
}
|
||||
|
||||
configs = config.Sort(orderBy, sort, configs)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"data": configs,
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
type EditConfigJson struct {
|
||||
Content string `json:"content" binding:"required"`
|
||||
}
|
||||
|
||||
func EditConfig(c *gin.Context) {
|
||||
name := c.Param("name")
|
||||
var request EditConfigJson
|
||||
err := c.BindJSON(&request)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
path := nginx.GetConfPath("/", name)
|
||||
content := request.Content
|
||||
|
||||
origContent, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
if content != "" && content != string(origContent) {
|
||||
// model.CreateBackup(path)
|
||||
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
|
||||
}
|
||||
|
||||
GetConfig(c)
|
||||
}
|
||||
@ -0,0 +1,134 @@
|
||||
package cosy
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/internal/logger"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var validate *validator.Validate
|
||||
|
||||
func init() {
|
||||
validate = validator.New()
|
||||
}
|
||||
|
||||
type Ctx[T any] struct {
|
||||
ctx *gin.Context
|
||||
rules gin.H
|
||||
Payload map[string]interface{}
|
||||
Model T
|
||||
abort bool
|
||||
nextHandler *gin.HandlerFunc
|
||||
beforeDecodeHookFunc []func(ctx *Ctx[T])
|
||||
beforeExecuteHookFunc []func(ctx *Ctx[T])
|
||||
executedHookFunc []func(ctx *Ctx[T])
|
||||
gormScopes []func(tx *gorm.DB) *gorm.DB
|
||||
preloads []string
|
||||
scan func(tx *gorm.DB) any
|
||||
transformer func(*T) any
|
||||
SelectedFields []string
|
||||
}
|
||||
|
||||
func Core[T any](c *gin.Context) *Ctx[T] {
|
||||
return &Ctx[T]{
|
||||
ctx: c,
|
||||
gormScopes: make([]func(tx *gorm.DB) *gorm.DB, 0),
|
||||
beforeExecuteHookFunc: make([]func(ctx *Ctx[T]), 0),
|
||||
beforeDecodeHookFunc: make([]func(ctx *Ctx[T]), 0),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Ctx[T]) SetValidRules(rules gin.H) *Ctx[T] {
|
||||
c.rules = rules
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Ctx[T]) BeforeDecodeHook(hook ...func(ctx *Ctx[T])) *Ctx[T] {
|
||||
c.beforeDecodeHookFunc = append(c.beforeDecodeHookFunc, hook...)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Ctx[T]) BeforeExecuteHook(hook ...func(ctx *Ctx[T])) *Ctx[T] {
|
||||
c.beforeExecuteHookFunc = append(c.beforeExecuteHookFunc, hook...)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Ctx[T]) ExecutedHook(hook ...func(ctx *Ctx[T])) *Ctx[T] {
|
||||
c.executedHookFunc = append(c.executedHookFunc, hook...)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Ctx[T]) SetPreloads(args ...string) *Ctx[T] {
|
||||
c.preloads = append(c.preloads, args...)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Ctx[T]) beforeExecuteHook() {
|
||||
if len(c.beforeExecuteHookFunc) > 0 {
|
||||
for _, v := range c.beforeExecuteHookFunc {
|
||||
v(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Ctx[T]) beforeDecodeHook() {
|
||||
if len(c.beforeDecodeHookFunc) > 0 {
|
||||
for _, v := range c.beforeDecodeHookFunc {
|
||||
v(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Ctx[T]) validate() (errs gin.H) {
|
||||
c.Payload = make(gin.H)
|
||||
|
||||
_ = c.ctx.ShouldBindJSON(&c.Payload)
|
||||
|
||||
errs = validate.ValidateMap(c.Payload, c.rules)
|
||||
|
||||
if len(errs) > 0 {
|
||||
logger.Debug(errs)
|
||||
for k := range errs {
|
||||
errs[k] = c.rules[k]
|
||||
}
|
||||
return
|
||||
}
|
||||
// Make sure that the key in c.Payload is also the key of rules
|
||||
validated := make(map[string]interface{})
|
||||
|
||||
for k, v := range c.Payload {
|
||||
if _, ok := c.rules[k]; ok {
|
||||
validated[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
c.Payload = validated
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Ctx[T]) SetScan(scan func(tx *gorm.DB) any) *Ctx[T] {
|
||||
c.scan = scan
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Ctx[T]) SetTransformer(t func(m *T) any) *Ctx[T] {
|
||||
c.transformer = t
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Ctx[T]) AbortWithError(err error) {
|
||||
c.abort = true
|
||||
errHandler(c.ctx, err)
|
||||
}
|
||||
|
||||
func (c *Ctx[T]) Abort() {
|
||||
c.abort = true
|
||||
}
|
||||
|
||||
func (c *Ctx[T]) GormScope(hook func(tx *gorm.DB) *gorm.DB) *Ctx[T] {
|
||||
c.gormScopes = append(c.gormScopes, hook)
|
||||
return c
|
||||
}
|
||||
@ -0,0 +1,72 @@
|
||||
package cosy
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api/cosy/map2struct"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm/clause"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (c *Ctx[T]) Create() {
|
||||
|
||||
errs := c.validate()
|
||||
|
||||
if len(errs) > 0 {
|
||||
c.ctx.JSON(http.StatusNotAcceptable, gin.H{
|
||||
"message": "Requested with wrong parameters",
|
||||
"errors": errs,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
db := model.UseDB()
|
||||
|
||||
c.beforeDecodeHook()
|
||||
|
||||
if c.abort {
|
||||
return
|
||||
}
|
||||
|
||||
err := map2struct.WeakDecode(c.Payload, &c.Model)
|
||||
|
||||
if err != nil {
|
||||
errHandler(c.ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.beforeExecuteHook()
|
||||
|
||||
if c.abort {
|
||||
return
|
||||
}
|
||||
|
||||
// skip all associations
|
||||
err = db.Omit(clause.Associations).Create(&c.Model).Error
|
||||
|
||||
if err != nil {
|
||||
errHandler(c.ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
tx := db.Preload(clause.Associations)
|
||||
for _, v := range c.preloads {
|
||||
tx = tx.Preload(v)
|
||||
}
|
||||
tx.First(&c.Model)
|
||||
|
||||
if len(c.executedHookFunc) > 0 {
|
||||
for _, v := range c.executedHookFunc {
|
||||
v(c)
|
||||
|
||||
if c.abort {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
if c.nextHandler != nil {
|
||||
(*c.nextHandler)(c.ctx)
|
||||
} else {
|
||||
c.ctx.JSON(http.StatusOK, c.Model)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
package cosy
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api/cosy/map2struct"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (c *Ctx[T]) Custom(fx func(ctx *Ctx[T])) {
|
||||
if c.abort {
|
||||
return
|
||||
}
|
||||
errs := c.validate()
|
||||
|
||||
if len(errs) > 0 {
|
||||
c.ctx.JSON(http.StatusNotAcceptable, gin.H{
|
||||
"message": "Requested with wrong parameters",
|
||||
"errors": errs,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.beforeDecodeHook()
|
||||
|
||||
for k := range c.Payload {
|
||||
c.SelectedFields = append(c.SelectedFields, k)
|
||||
}
|
||||
|
||||
err := map2struct.WeakDecode(c.Payload, &c.Model)
|
||||
|
||||
if err != nil {
|
||||
errHandler(c.ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.beforeExecuteHook()
|
||||
|
||||
fx(c)
|
||||
}
|
||||
@ -0,0 +1,91 @@
|
||||
package cosy
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (c *Ctx[T]) Destroy() {
|
||||
if c.abort {
|
||||
return
|
||||
}
|
||||
id := c.ctx.Param("id")
|
||||
|
||||
c.beforeExecuteHook()
|
||||
|
||||
db := model.UseDB()
|
||||
var dbModel T
|
||||
|
||||
result := db
|
||||
if len(c.gormScopes) > 0 {
|
||||
result = result.Scopes(c.gormScopes...)
|
||||
}
|
||||
|
||||
err := result.Session(&gorm.Session{}).First(&dbModel, id).Error
|
||||
|
||||
if err != nil {
|
||||
errHandler(c.ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = result.Delete(&dbModel).Error
|
||||
if err != nil {
|
||||
errHandler(c.ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
if len(c.executedHookFunc) > 0 {
|
||||
for _, v := range c.executedHookFunc {
|
||||
v(c)
|
||||
|
||||
if c.abort {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
c.ctx.JSON(http.StatusNoContent, nil)
|
||||
}
|
||||
|
||||
func (c *Ctx[T]) Recover() {
|
||||
if c.abort {
|
||||
return
|
||||
}
|
||||
id := c.ctx.Param("id")
|
||||
|
||||
c.beforeExecuteHook()
|
||||
|
||||
db := model.UseDB()
|
||||
var dbModel T
|
||||
|
||||
result := db.Unscoped()
|
||||
if len(c.gormScopes) > 0 {
|
||||
result = result.Scopes(c.gormScopes...)
|
||||
}
|
||||
|
||||
err := result.Session(&gorm.Session{}).First(&dbModel, id).Error
|
||||
|
||||
if err != nil {
|
||||
errHandler(c.ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = result.Model(&dbModel).Update("deleted_at", nil).Error
|
||||
if err != nil {
|
||||
errHandler(c.ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
if len(c.executedHookFunc) > 0 {
|
||||
for _, v := range c.executedHookFunc {
|
||||
v(c)
|
||||
|
||||
if c.abort {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
c.ctx.JSON(http.StatusNoContent, nil)
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
package cosy
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/0xJacky/Nginx-UI/internal/logger"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func errHandler(c *gin.Context, err error) {
|
||||
logger.GetLogger().WithOptions(zap.AddCallerSkip(1)).Errorln(err)
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
c.JSON(http.StatusNotFound, gin.H{
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"message": err.Error(),
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,158 @@
|
||||
package cosy
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/internal/logger"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/settings"
|
||||
"github.com/spf13/cast"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (c *Ctx[T]) SetFussy(keys ...string) *Ctx[T] {
|
||||
c.gormScopes = append(c.gormScopes, func(tx *gorm.DB) *gorm.DB {
|
||||
return model.QueryToFussySearch(c.ctx, tx, keys...)
|
||||
})
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Ctx[T]) SetFussyKeys(value string, keys ...string) *Ctx[T] {
|
||||
c.gormScopes = append(c.gormScopes, func(tx *gorm.DB) *gorm.DB {
|
||||
return model.QueryToFussyKeysSearch(c.ctx, tx, value, keys...)
|
||||
})
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Ctx[T]) SetEqual(keys ...string) *Ctx[T] {
|
||||
c.gormScopes = append(c.gormScopes, func(tx *gorm.DB) *gorm.DB {
|
||||
return model.QueryToEqualSearch(c.ctx, tx, keys...)
|
||||
})
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Ctx[T]) SetIn(keys ...string) *Ctx[T] {
|
||||
c.gormScopes = append(c.gormScopes, func(tx *gorm.DB) *gorm.DB {
|
||||
return model.QueryToInSearch(c.ctx, tx, keys...)
|
||||
})
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Ctx[T]) SetOrFussy(keys ...string) *Ctx[T] {
|
||||
c.gormScopes = append(c.gormScopes, func(tx *gorm.DB) *gorm.DB {
|
||||
return model.QueryToOrFussySearch(c.ctx, tx, keys...)
|
||||
})
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Ctx[T]) SetOrEqual(keys ...string) *Ctx[T] {
|
||||
c.gormScopes = append(c.gormScopes, func(tx *gorm.DB) *gorm.DB {
|
||||
return model.QueryToOrEqualSearch(c.ctx, tx, keys...)
|
||||
})
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Ctx[T]) SetOrIn(keys ...string) *Ctx[T] {
|
||||
c.gormScopes = append(c.gormScopes, func(tx *gorm.DB) *gorm.DB {
|
||||
return model.QueryToOrInSearch(c.ctx, tx, keys...)
|
||||
})
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Ctx[T]) result() (*gorm.DB, bool) {
|
||||
for _, v := range c.preloads {
|
||||
t := v
|
||||
c.GormScope(func(tx *gorm.DB) *gorm.DB {
|
||||
tx = tx.Preload(t)
|
||||
return tx
|
||||
})
|
||||
}
|
||||
|
||||
c.beforeExecuteHook()
|
||||
|
||||
var dbModel T
|
||||
result := model.UseDB()
|
||||
|
||||
if c.ctx.Query("trash") == "true" {
|
||||
stmt := &gorm.Statement{DB: model.UseDB()}
|
||||
err := stmt.Parse(&dbModel)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
return nil, false
|
||||
}
|
||||
result = result.Unscoped().Where(stmt.Schema.Table + ".deleted_at IS NOT NULL")
|
||||
}
|
||||
|
||||
result = result.Model(&dbModel)
|
||||
|
||||
if len(c.gormScopes) > 0 {
|
||||
result = result.Scopes(c.gormScopes...)
|
||||
}
|
||||
|
||||
return result, true
|
||||
}
|
||||
|
||||
func (c *Ctx[T]) ListAllData() ([]*T, bool) {
|
||||
result, ok := c.result()
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
result = result.Scopes(model.SortOrder(c.ctx))
|
||||
models := make([]*T, 0)
|
||||
result.Find(&models)
|
||||
return models, true
|
||||
}
|
||||
|
||||
func (c *Ctx[T]) PagingListData() (*model.DataList, bool) {
|
||||
result, ok := c.result()
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
result = result.Scopes(model.OrderAndPaginate(c.ctx))
|
||||
data := &model.DataList{}
|
||||
if c.scan == nil {
|
||||
models := make([]*T, 0)
|
||||
result.Find(&models)
|
||||
|
||||
if c.transformer != nil {
|
||||
transformed := make([]any, 0)
|
||||
for k := range models {
|
||||
transformed = append(transformed, c.transformer(models[k]))
|
||||
}
|
||||
data.Data = transformed
|
||||
} else {
|
||||
data.Data = models
|
||||
}
|
||||
} else {
|
||||
data.Data = c.scan(result)
|
||||
}
|
||||
|
||||
page := cast.ToInt(c.ctx.Query("page"))
|
||||
if page == 0 {
|
||||
page = 1
|
||||
}
|
||||
|
||||
pageSize := settings.AppSettings.PageSize
|
||||
if reqPageSize := c.ctx.Query("page_size"); reqPageSize != "" {
|
||||
pageSize = cast.ToInt(reqPageSize)
|
||||
}
|
||||
|
||||
var totalRecords int64
|
||||
result.Session(&gorm.Session{}).Count(&totalRecords)
|
||||
|
||||
data.Pagination = model.Pagination{
|
||||
Total: totalRecords,
|
||||
PerPage: pageSize,
|
||||
CurrentPage: page,
|
||||
TotalPages: model.TotalPage(totalRecords, pageSize),
|
||||
}
|
||||
return data, true
|
||||
}
|
||||
|
||||
func (c *Ctx[T]) PagingList() {
|
||||
data, ok := c.PagingListData()
|
||||
if ok {
|
||||
c.ctx.JSON(http.StatusOK, data)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
package map2struct
|
||||
|
||||
import (
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/spf13/cast"
|
||||
"reflect"
|
||||
"time"
|
||||
)
|
||||
|
||||
var timeLocation *time.Location
|
||||
|
||||
func init() {
|
||||
timeLocation = time.Local
|
||||
}
|
||||
|
||||
func ToTimeHookFunc() mapstructure.DecodeHookFunc {
|
||||
return func(
|
||||
f reflect.Type,
|
||||
t reflect.Type,
|
||||
data interface{}) (interface{}, error) {
|
||||
if t != reflect.TypeOf(time.Time{}) {
|
||||
return data, nil
|
||||
}
|
||||
|
||||
switch f.Kind() {
|
||||
case reflect.String:
|
||||
return cast.ToTimeInDefaultLocationE(data, timeLocation)
|
||||
case reflect.Float64:
|
||||
return time.Unix(0, int64(data.(float64))*int64(time.Millisecond)), nil
|
||||
case reflect.Int64:
|
||||
return time.Unix(0, data.(int64)*int64(time.Millisecond)), nil
|
||||
default:
|
||||
return data, nil
|
||||
}
|
||||
// Convert it by parsing
|
||||
}
|
||||
}
|
||||
|
||||
func ToDecimalHookFunc() mapstructure.DecodeHookFunc {
|
||||
return func(f reflect.Type, t reflect.Type, data interface{}) (interface{}, error) {
|
||||
|
||||
if t == reflect.TypeOf(decimal.Decimal{}) {
|
||||
if f.Kind() == reflect.Float64 {
|
||||
return decimal.NewFromFloat(data.(float64)), nil
|
||||
}
|
||||
|
||||
if input := data.(string); input != "" {
|
||||
return decimal.NewFromString(data.(string))
|
||||
}
|
||||
return decimal.Decimal{}, nil
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package map2struct
|
||||
|
||||
import (
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
|
||||
func WeakDecode(input, output interface{}) error {
|
||||
config := &mapstructure.DecoderConfig{
|
||||
Metadata: nil,
|
||||
Result: output,
|
||||
WeaklyTypedInput: true,
|
||||
DecodeHook: mapstructure.ComposeDecodeHookFunc(
|
||||
ToDecimalHookFunc(), ToTimeHookFunc(),
|
||||
),
|
||||
TagName: "json",
|
||||
}
|
||||
|
||||
decoder, err := mapstructure.NewDecoder(config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return decoder.Decode(input)
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package cosy
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (c *Ctx[T]) UpdateOrder() {
|
||||
var json struct {
|
||||
TargetID int `json:"target_id"`
|
||||
Direction int `json:"direction" binding:"oneof=-1 1"`
|
||||
AffectedIDs []int `json:"affected_ids"`
|
||||
}
|
||||
|
||||
if !api.BindAndValid(c.ctx, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
affectedLen := len(json.AffectedIDs)
|
||||
|
||||
db := model.UseDB()
|
||||
|
||||
// update target
|
||||
err := db.Model(&c.Model).Where("id = ?", json.TargetID).Update("order_id", gorm.Expr("order_id + ?", affectedLen*(-json.Direction))).Error
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c.ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
// update affected
|
||||
err = db.Model(&c.Model).Where("id in ?", json.AffectedIDs).Update("order_id", gorm.Expr("order_id + ?", json.Direction)).Error
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c.ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.ctx.JSON(http.StatusOK, json)
|
||||
}
|
||||
@ -0,0 +1,90 @@
|
||||
package cosy
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api/cosy/map2struct"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (c *Ctx[T]) SetNextHandler(handler gin.HandlerFunc) *Ctx[T] {
|
||||
c.nextHandler = &handler
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Ctx[T]) Modify() {
|
||||
if c.abort {
|
||||
return
|
||||
}
|
||||
id := c.ctx.Param("id")
|
||||
errs := c.validate()
|
||||
|
||||
if len(errs) > 0 {
|
||||
c.ctx.JSON(http.StatusNotAcceptable, gin.H{
|
||||
"message": "Requested with wrong parameters",
|
||||
"errors": errs,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
db := model.UseDB()
|
||||
|
||||
result := db
|
||||
if len(c.gormScopes) > 0 {
|
||||
result = result.Scopes(c.gormScopes...)
|
||||
}
|
||||
|
||||
err := result.Session(&gorm.Session{}).First(&c.Model, id).Error
|
||||
|
||||
if err != nil {
|
||||
c.AbortWithError(err)
|
||||
return
|
||||
}
|
||||
|
||||
c.beforeDecodeHook()
|
||||
if c.abort {
|
||||
return
|
||||
}
|
||||
|
||||
var selectedFields []string
|
||||
|
||||
for k := range c.Payload {
|
||||
selectedFields = append(selectedFields, k)
|
||||
}
|
||||
|
||||
err = map2struct.WeakDecode(c.Payload, &c.Model)
|
||||
|
||||
if err != nil {
|
||||
errHandler(c.ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.beforeExecuteHook()
|
||||
if c.abort {
|
||||
return
|
||||
}
|
||||
|
||||
err = db.Model(&c.Model).Select(selectedFields).Updates(&c.Model).Error
|
||||
|
||||
if err != nil {
|
||||
c.AbortWithError(err)
|
||||
return
|
||||
}
|
||||
|
||||
if len(c.executedHookFunc) > 0 {
|
||||
for _, v := range c.executedHookFunc {
|
||||
v(c)
|
||||
|
||||
if c.abort {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if c.nextHandler != nil {
|
||||
(*c.nextHandler)(c.ctx)
|
||||
} else {
|
||||
c.ctx.JSON(http.StatusOK, c.Model)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
package openai
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/sashabaranov/go-openai"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func StoreChatGPTRecord(c *gin.Context) {
|
||||
var json struct {
|
||||
FileName string `json:"file_name"`
|
||||
Messages []openai.ChatCompletionMessage `json:"messages"`
|
||||
}
|
||||
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
name := json.FileName
|
||||
g := query.ChatGPTLog
|
||||
_, err := g.Where(g.Name.Eq(name)).FirstOrCreate()
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = g.Where(g.Name.Eq(name)).Updates(&model.ChatGPTLog{
|
||||
Name: name,
|
||||
Content: json.Messages,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "ok",
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package sites
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func DomainEditByAdvancedMode(c *gin.Context) {
|
||||
var json struct {
|
||||
Advanced bool `json:"advanced"`
|
||||
}
|
||||
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
name := c.Param("name")
|
||||
path := nginx.GetConfPath("sites-available", name)
|
||||
|
||||
s := query.Site
|
||||
|
||||
_, err := s.Where(s.Path.Eq(path)).FirstOrCreate()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = s.Where(s.Path.Eq(path)).Update(s.Advanced, json.Advanced)
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "ok",
|
||||
})
|
||||
|
||||
}
|
||||
@ -0,0 +1,64 @@
|
||||
package sites
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func AddDomainToAutoCert(c *gin.Context) {
|
||||
name := c.Param("name")
|
||||
|
||||
var json struct {
|
||||
DnsCredentialID int `json:"dns_credential_id"`
|
||||
ChallengeMethod string `json:"challenge_method"`
|
||||
Domains []string `json:"domains"`
|
||||
}
|
||||
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
certModel, err := model.FirstOrCreateCert(name)
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = certModel.Updates(&model.Cert{
|
||||
Name: name,
|
||||
Domains: json.Domains,
|
||||
AutoCert: model.AutoCertEnabled,
|
||||
DnsCredentialID: json.DnsCredentialID,
|
||||
ChallengeMethod: json.ChallengeMethod,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, certModel)
|
||||
}
|
||||
|
||||
func RemoveDomainFromAutoCert(c *gin.Context) {
|
||||
name := c.Param("name")
|
||||
certModel, err := model.FirstCert(name)
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = certModel.Updates(&model.Cert{
|
||||
AutoCert: model.AutoCertDisabled,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, nil)
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
package sites
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/helper"
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func DuplicateSite(c *gin.Context) {
|
||||
// Source name
|
||||
name := c.Param("name")
|
||||
|
||||
// Destination name
|
||||
var json struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
}
|
||||
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
src := nginx.GetConfPath("sites-available", name)
|
||||
dst := nginx.GetConfPath("sites-available", json.Name)
|
||||
|
||||
if helper.FileExists(dst) {
|
||||
c.JSON(http.StatusNotAcceptable, gin.H{
|
||||
"message": "File exists",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
_, err := helper.CopyFile(src, dst)
|
||||
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"dst": dst,
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package sites
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/internal/nginx"
|
||||
"github.com/sashabaranov/go-openai"
|
||||
"time"
|
||||
)
|
||||
|
||||
type CertificateInfo struct {
|
||||
SubjectName string `json:"subject_name"`
|
||||
IssuerName string `json:"issuer_name"`
|
||||
NotAfter time.Time `json:"not_after"`
|
||||
NotBefore time.Time `json:"not_before"`
|
||||
}
|
||||
|
||||
type Site struct {
|
||||
ModifiedAt time.Time `json:"modified_at"`
|
||||
Advanced bool `json:"advanced"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Name string `json:"name"`
|
||||
Config string `json:"config"`
|
||||
AutoCert bool `json:"auto_cert"`
|
||||
ChatGPTMessages []openai.ChatCompletionMessage `json:"chatgpt_messages,omitempty"`
|
||||
Tokenized *nginx.NgxConfig `json:"tokenized,omitempty"`
|
||||
CertInfo map[int]CertificateInfo `json:"cert_info,omitempty"`
|
||||
}
|
||||
@ -0,0 +1,258 @@
|
||||
module.exports = {
|
||||
env: {
|
||||
browser: true,
|
||||
es2021: true,
|
||||
},
|
||||
extends: [
|
||||
'@antfu/eslint-config-vue',
|
||||
'plugin:vue/vue3-recommended',
|
||||
'plugin:import/recommended',
|
||||
'plugin:import/typescript',
|
||||
'plugin:promise/recommended',
|
||||
'plugin:sonarjs/recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
|
||||
// 'plugin:unicorn/recommended',
|
||||
],
|
||||
parser: 'vue-eslint-parser',
|
||||
parserOptions: {
|
||||
ecmaVersion: 13,
|
||||
parser: '@typescript-eslint/parser',
|
||||
sourceType: 'module',
|
||||
},
|
||||
plugins: [
|
||||
'vue',
|
||||
'@typescript-eslint',
|
||||
'regex',
|
||||
],
|
||||
ignorePatterns: ['src/@iconify/*.js', 'node_modules', 'dist', '*.d.ts'],
|
||||
rules: {
|
||||
'vue/no-v-html': 'off',
|
||||
|
||||
'vue/block-tag-newline': 'off',
|
||||
// eslint-disable-next-line n/prefer-global/process
|
||||
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
|
||||
// eslint-disable-next-line n/prefer-global/process
|
||||
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
|
||||
|
||||
// indentation (Already present in TypeScript)
|
||||
'comma-spacing': ['error', {
|
||||
before: false,
|
||||
after: true,
|
||||
}],
|
||||
'key-spacing': ['error', { afterColon: true }],
|
||||
|
||||
'vue/first-attribute-linebreak': ['error', {
|
||||
singleline: 'beside',
|
||||
multiline: 'below',
|
||||
}],
|
||||
|
||||
'antfu/top-level-function': 'off',
|
||||
|
||||
// Enforce trailing comma (Already present in TypeScript)
|
||||
'comma-dangle': ['error', 'always-multiline'],
|
||||
|
||||
// Disable max-len
|
||||
'max-len': 'off',
|
||||
|
||||
// we don't want it
|
||||
'semi': ['error', 'never'],
|
||||
|
||||
// add parens ony when required in arrow function
|
||||
'arrow-parens': ['error', 'as-needed'],
|
||||
|
||||
// add new line above comment
|
||||
'newline-before-return': 'error',
|
||||
|
||||
// add new line above comment
|
||||
'lines-around-comment': [
|
||||
'error',
|
||||
{
|
||||
beforeBlockComment: true,
|
||||
beforeLineComment: true,
|
||||
allowBlockStart: true,
|
||||
allowClassStart: true,
|
||||
allowObjectStart: true,
|
||||
allowArrayStart: true,
|
||||
},
|
||||
],
|
||||
|
||||
// Ignore _ as unused variable
|
||||
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_+$' }],
|
||||
|
||||
'array-element-newline': ['error', 'consistent'],
|
||||
'array-bracket-newline': ['error', 'consistent'],
|
||||
|
||||
'vue/multi-word-component-names': 'off',
|
||||
|
||||
'padding-line-between-statements': [
|
||||
'error',
|
||||
{
|
||||
blankLine: 'always',
|
||||
prev: 'expression',
|
||||
next: 'const',
|
||||
},
|
||||
{
|
||||
blankLine: 'always',
|
||||
prev: 'const',
|
||||
next: 'expression',
|
||||
},
|
||||
{
|
||||
blankLine: 'always',
|
||||
prev: 'multiline-const',
|
||||
next: '*',
|
||||
},
|
||||
{
|
||||
blankLine: 'always',
|
||||
prev: '*',
|
||||
next: 'multiline-const',
|
||||
},
|
||||
],
|
||||
|
||||
// Plugin: eslint-plugin-import
|
||||
'import/prefer-default-export': 'off',
|
||||
'import/newline-after-import': ['error', { count: 1 }],
|
||||
'no-restricted-imports': ['error', 'vuetify/components'],
|
||||
|
||||
// For omitting extension for ts files
|
||||
'import/extensions': [
|
||||
'error',
|
||||
'ignorePackages',
|
||||
{
|
||||
mjs: 'never',
|
||||
js: 'never',
|
||||
jsx: 'never',
|
||||
ts: 'never',
|
||||
tsx: 'never',
|
||||
},
|
||||
],
|
||||
|
||||
// ignore virtual files
|
||||
'import/no-unresolved': [2, {
|
||||
ignore: [
|
||||
'~pages$',
|
||||
'virtual:generated-layouts',
|
||||
|
||||
// Ignore vite's ?raw imports
|
||||
'.*\?raw',
|
||||
],
|
||||
}],
|
||||
|
||||
// Thanks: https://stackoverflow.com/a/63961972/10796681
|
||||
'no-shadow': 'off',
|
||||
'@typescript-eslint/no-shadow': ['error'],
|
||||
|
||||
'@typescript-eslint/consistent-type-imports': 'error',
|
||||
|
||||
// Plugin: eslint-plugin-promise
|
||||
'promise/always-return': 'off',
|
||||
'promise/catch-or-return': 'off',
|
||||
|
||||
// ESLint plugin vue
|
||||
'vue/component-api-style': 'error',
|
||||
'vue/component-name-in-template-casing': ['error', 'PascalCase', { registeredComponentsOnly: false }],
|
||||
'vue/custom-event-name-casing': ['error', 'camelCase', {
|
||||
ignores: [
|
||||
'/^(click):[a-z]+((\d)|([A-Z0-9][a-z0-9]+))*([A-Z])?/',
|
||||
],
|
||||
}],
|
||||
'vue/define-macros-order': 'error',
|
||||
'vue/html-comment-content-newline': 'error',
|
||||
'vue/html-comment-content-spacing': 'error',
|
||||
'vue/html-comment-indent': 'error',
|
||||
'vue/match-component-file-name': 'error',
|
||||
'vue/no-child-content': 'error',
|
||||
'vue/require-default-prop': 'off',
|
||||
|
||||
// NOTE this rule only supported in SFC, Users of the unplugin-vue-define-options should disable that rule: https://github.com/vuejs/eslint-plugin-vue/issues/1886
|
||||
// 'vue/no-duplicate-attr-inheritance': 'error',
|
||||
'vue/no-multiple-objects-in-class': 'error',
|
||||
'vue/no-reserved-component-names': 'error',
|
||||
'vue/no-template-target-blank': 'error',
|
||||
'vue/no-useless-mustaches': 'error',
|
||||
'vue/no-useless-v-bind': 'error',
|
||||
'vue/padding-line-between-blocks': 'error',
|
||||
'vue/prefer-separate-static-class': 'error',
|
||||
'vue/prefer-true-attribute-shorthand': 'error',
|
||||
'vue/v-on-function-call': 'error',
|
||||
'vue/valid-v-slot': ['error', {
|
||||
allowModifiers: true,
|
||||
}],
|
||||
|
||||
// -- Extension Rules
|
||||
'vue/no-irregular-whitespace': 'error',
|
||||
|
||||
// -- Sonarlint
|
||||
'sonarjs/no-duplicate-string': 'off',
|
||||
'sonarjs/no-nested-template-literals': 'off',
|
||||
|
||||
// -- Unicorn
|
||||
// 'unicorn/filename-case': 'off',
|
||||
// 'unicorn/prevent-abbreviations': ['error', {
|
||||
// replacements: {
|
||||
// props: false,
|
||||
// },
|
||||
// }],
|
||||
// https://github.com/gmullerb/eslint-plugin-regex
|
||||
'regex/invalid': [
|
||||
'error',
|
||||
[
|
||||
{
|
||||
regex: '@/assets/images',
|
||||
replacement: '@images',
|
||||
message: 'Use \'@images\' path alias for image imports',
|
||||
},
|
||||
{
|
||||
regex: '@/styles',
|
||||
replacement: '@styles',
|
||||
message: 'Use \'@styles\' path alias for importing styles from \'src/styles\'',
|
||||
},
|
||||
|
||||
// {
|
||||
// id: 'Disallow icon of icon library',
|
||||
// regex: 'tabler-\\w',
|
||||
// message: 'Only \'mdi\' icons are allowed',
|
||||
// },
|
||||
|
||||
{
|
||||
regex: '@core/\\w',
|
||||
message: 'You can\'t use @core when you are in @layouts module',
|
||||
files: {
|
||||
inspect: '@layouts/.*',
|
||||
},
|
||||
},
|
||||
{
|
||||
regex: 'useLayouts\\(',
|
||||
message: '`useLayouts` composable is only allowed in @layouts & @core directory. Please use `useThemeConfig` composable instead.',
|
||||
files: {
|
||||
inspect: '^(?!.*(@core|@layouts)).*',
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
// Ignore files
|
||||
'\.eslintrc\.js',
|
||||
],
|
||||
},
|
||||
settings: {
|
||||
'import/resolver': {
|
||||
node: {
|
||||
extensions: ['.ts', '.js', '.tsx', '.jsx', '.mjs', '.png', '.jpg'],
|
||||
},
|
||||
typescript: {},
|
||||
alias: {
|
||||
map: [
|
||||
['@', './src'],
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
files: ['*.json'],
|
||||
rules: {
|
||||
'no-invalid-meta': 'off',
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,13 +1,30 @@
|
||||
import http from '@/lib/http'
|
||||
|
||||
export interface DNSProvider {
|
||||
name: string
|
||||
code: string
|
||||
configuration: {
|
||||
credentials: {
|
||||
[key: string]: string
|
||||
}
|
||||
additional: {
|
||||
[key: string]: string
|
||||
}
|
||||
}
|
||||
links: {
|
||||
api: string
|
||||
go_client: string
|
||||
}
|
||||
}
|
||||
|
||||
const auto_cert = {
|
||||
get_dns_providers() {
|
||||
return http.get('/auto_cert/dns/providers')
|
||||
get_dns_providers(): Promise<DNSProvider[]> {
|
||||
return http.get('/certificate/dns_providers')
|
||||
},
|
||||
|
||||
get_dns_provider(code: string) {
|
||||
return http.get('/auto_cert/dns/provider/' + code)
|
||||
}
|
||||
get_dns_provider(code: string): Promise<DNSProvider> {
|
||||
return http.get(`/certificate/dns_provider/${code}`)
|
||||
},
|
||||
}
|
||||
|
||||
export default auto_cert
|
||||
|
||||
@ -1,5 +1,27 @@
|
||||
import type { ModelBase } from '@/api/curd'
|
||||
import Curd from '@/api/curd'
|
||||
import type { DnsCredential } from '@/api/dns_credential'
|
||||
|
||||
const cert = new Curd('/cert')
|
||||
export interface Cert extends ModelBase {
|
||||
name: string
|
||||
domains: string[]
|
||||
filename: string
|
||||
ssl_certificate_path: string
|
||||
ssl_certificate_key_path: string
|
||||
auto_cert: number
|
||||
challenge_method: string
|
||||
dns_credential_id: number
|
||||
dns_credential?: DnsCredential
|
||||
log: string
|
||||
}
|
||||
|
||||
export interface CertificateInfo {
|
||||
subject_name: string
|
||||
issuer_name: string
|
||||
not_after: string
|
||||
not_before: string
|
||||
}
|
||||
|
||||
const cert: Curd<Cert> = new Curd('/cert')
|
||||
|
||||
export default cert
|
||||
|
||||
@ -1,5 +1,14 @@
|
||||
import Curd from '@/api/curd'
|
||||
import type { ChatComplicationMessage } from '@/api/openai'
|
||||
|
||||
const config = new Curd('/config')
|
||||
export interface Config {
|
||||
name: string
|
||||
content: string
|
||||
chatgpt_messages: ChatComplicationMessage[]
|
||||
file_path: string
|
||||
modified_at: string
|
||||
}
|
||||
|
||||
const config: Curd<Config> = new Curd('/config')
|
||||
|
||||
export default config
|
||||
|
||||
@ -1,5 +1,13 @@
|
||||
import type { ModelBase } from '@/api/curd'
|
||||
import Curd from '@/api/curd'
|
||||
import type { DNSProvider } from '@/api/auto_cert'
|
||||
|
||||
const dns_credential = new Curd('/dns_credential')
|
||||
export interface DnsCredential extends ModelBase {
|
||||
name: string
|
||||
config?: DNSProvider
|
||||
provider: string
|
||||
}
|
||||
|
||||
const dns_credential: Curd<DnsCredential> = new Curd('/dns_credential')
|
||||
|
||||
export default dns_credential
|
||||
|
||||
@ -1,12 +1,19 @@
|
||||
import http from '@/lib/http'
|
||||
|
||||
export interface InstallRequest {
|
||||
email: string
|
||||
username: string
|
||||
password: string
|
||||
database: string
|
||||
}
|
||||
|
||||
const install = {
|
||||
get_lock() {
|
||||
return http.get('/install')
|
||||
},
|
||||
install_nginx_ui(data: any) {
|
||||
install_nginx_ui(data: InstallRequest) {
|
||||
return http.post('/install', data)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
export default install
|
||||
|
||||
@ -1,9 +1,15 @@
|
||||
import http from '@/lib/http'
|
||||
|
||||
export interface ChatComplicationMessage {
|
||||
role: string
|
||||
content: string
|
||||
name?: string
|
||||
}
|
||||
|
||||
const openai = {
|
||||
store_record(data: any) {
|
||||
store_record(data: { file_name: string; messages: ChatComplicationMessage[] }) {
|
||||
return http.post('/chat_gpt_record', data)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
export default openai
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
export interface Series {
|
||||
name: string
|
||||
data: []
|
||||
}
|
||||
@ -1,3 +1,3 @@
|
||||
import CodeEditor from './CodeEditor'
|
||||
import CodeEditor from './CodeEditor.vue'
|
||||
|
||||
export default CodeEditor
|
||||
|
||||
@ -1,37 +0,0 @@
|
||||
import {defineComponent} from 'vue'
|
||||
import {Form} from 'ant-design-vue'
|
||||
import StdFormItem from '@/components/StdDataEntry/StdFormItem.vue'
|
||||
import './style.less'
|
||||
|
||||
export default defineComponent({
|
||||
props: ['dataList', 'dataSource', 'error', 'layout'],
|
||||
emits: ['update:dataSource'],
|
||||
setup(props, {slots}) {
|
||||
return () => {
|
||||
const template: any = []
|
||||
props.dataList.forEach((v: any) => {
|
||||
let show = true
|
||||
if (v.edit.show) {
|
||||
if (typeof v.edit.show === 'boolean') {
|
||||
show = v.edit.show
|
||||
} else if (typeof v.edit.show === 'function') {
|
||||
show = v.edit.show(props.dataSource)
|
||||
}
|
||||
}
|
||||
if (v.edit.type && show) {
|
||||
template.push(
|
||||
<StdFormItem dataIndex={v.dataIndex} label={v.title()} extra={v.extra} error={props.error}>
|
||||
{v.edit.type(v.edit, props.dataSource, v.dataIndex)}
|
||||
</StdFormItem>
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
if (slots.action) {
|
||||
template.push(<div class={'std-data-entry-action'}>{slots.action()}</div>)
|
||||
}
|
||||
|
||||
return <Form layout={props.layout || 'vertical'}>{template}</Form>
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -1,45 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import {computed, ref} from 'vue'
|
||||
import {SelectProps} from 'ant-design-vue'
|
||||
|
||||
const props = defineProps(['value', 'mask'])
|
||||
const emit = defineEmits(['update:value'])
|
||||
|
||||
const options = computed(() => {
|
||||
const _options = ref<SelectProps['options']>([])
|
||||
|
||||
for (const [key, value] of Object.entries(props.mask)) {
|
||||
const v = value as any
|
||||
_options.value!.push({label: v?.(), value: key})
|
||||
}
|
||||
|
||||
return _options
|
||||
})
|
||||
|
||||
const _value = computed({
|
||||
get() {
|
||||
let v
|
||||
|
||||
if (typeof props.mask?.[props.value] === 'function') {
|
||||
v = props.mask[props.value]()
|
||||
} else if (typeof props.mask?.[props.value] === 'string') {
|
||||
v = props.mask[props.value]
|
||||
} else {
|
||||
v = props.value
|
||||
}
|
||||
return v
|
||||
},
|
||||
set(v) {
|
||||
emit('update:value', v)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<a-select v-model:value="_value"
|
||||
:options="options.value" style="min-width: 180px"/>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
|
||||
</style>
|
||||
@ -1,133 +0,0 @@
|
||||
import StdDataEntry from './StdDataEntry.js'
|
||||
import {h} from 'vue'
|
||||
import {Input, InputNumber, Switch, Textarea} from 'ant-design-vue'
|
||||
import StdSelector from './components/StdSelector.vue'
|
||||
import StdSelect from './components/StdSelect.vue'
|
||||
import StdPassword from './components/StdPassword.vue'
|
||||
|
||||
interface IEdit {
|
||||
type: Function
|
||||
placeholder: any
|
||||
mask: any
|
||||
key: any
|
||||
value: any
|
||||
recordValueIndex: any
|
||||
selectionType: any
|
||||
api: Object,
|
||||
columns: any,
|
||||
data_key: any,
|
||||
disable_search: boolean,
|
||||
get_params: Object,
|
||||
description: string
|
||||
generate: boolean
|
||||
min: number
|
||||
max: number,
|
||||
extra: string
|
||||
}
|
||||
|
||||
function fn(obj: Object, desc: any) {
|
||||
let arr: string[]
|
||||
if (typeof desc === 'string') {
|
||||
arr = desc.split('.')
|
||||
} else {
|
||||
arr = [...desc]
|
||||
}
|
||||
|
||||
while (arr.length) {
|
||||
// @ts-ignore
|
||||
const top = obj[arr.shift()]
|
||||
if (top === undefined) {
|
||||
return null
|
||||
}
|
||||
obj = top
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
function readonly(edit: IEdit, dataSource: any, dataIndex: any) {
|
||||
return h('p', fn(dataSource, dataIndex))
|
||||
}
|
||||
|
||||
function input(edit: IEdit, dataSource: any, dataIndex: any) {
|
||||
return h(Input, {
|
||||
placeholder: edit.placeholder?.() ?? '',
|
||||
value: dataSource?.[dataIndex],
|
||||
'onUpdate:value': value => {
|
||||
dataSource[dataIndex] = value
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function inputNumber(edit: IEdit, dataSource: any, dataIndex: any) {
|
||||
return h(InputNumber, {
|
||||
placeholder: edit.placeholder?.() ?? '',
|
||||
min: edit.min,
|
||||
max: edit.max,
|
||||
value: dataSource?.[dataIndex],
|
||||
'onUpdate:value': value => {
|
||||
dataSource[dataIndex] = value
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function textarea(edit: IEdit, dataSource: any, dataIndex: any) {
|
||||
return h(Textarea, {
|
||||
placeholder: edit.placeholder?.() ?? '',
|
||||
value: dataSource?.[dataIndex],
|
||||
'onUpdate:value': value => {
|
||||
dataSource[dataIndex] = value
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function password(edit: IEdit, dataSource: any, dataIndex: any) {
|
||||
return <StdPassword
|
||||
v-model:value={dataSource[dataIndex]}
|
||||
generate={edit.generate}
|
||||
placeholder={edit.placeholder}
|
||||
/>
|
||||
}
|
||||
|
||||
function select(edit: IEdit, dataSource: any, dataIndex: any) {
|
||||
return <StdSelect
|
||||
v-model:value={dataSource[dataIndex]}
|
||||
mask={edit.mask}
|
||||
/>
|
||||
}
|
||||
|
||||
function selector(edit: IEdit, dataSource: any, dataIndex: any) {
|
||||
return <StdSelector
|
||||
v-model:selectedKey={dataSource[dataIndex]}
|
||||
value={edit.value}
|
||||
recordValueIndex={edit.recordValueIndex}
|
||||
selectionType={edit.selectionType}
|
||||
api={edit.api}
|
||||
columns={edit.columns}
|
||||
data_key={edit.data_key}
|
||||
disable_search={edit.disable_search}
|
||||
get_params={edit.get_params}
|
||||
description={edit.description}
|
||||
/>
|
||||
}
|
||||
|
||||
function antSwitch(edit: IEdit, dataSource: any, dataIndex: any) {
|
||||
return h(Switch, {
|
||||
checked: dataSource?.[dataIndex],
|
||||
'onUpdate:checked': (value: any) => {
|
||||
dataSource[dataIndex] = value
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export {
|
||||
readonly,
|
||||
input,
|
||||
textarea,
|
||||
select,
|
||||
selector,
|
||||
password,
|
||||
inputNumber,
|
||||
antSwitch
|
||||
}
|
||||
|
||||
export default StdDataEntry
|
||||
@ -0,0 +1,54 @@
|
||||
import { defineComponent } from 'vue'
|
||||
import { Form } from 'ant-design-vue'
|
||||
import StdFormItem from '@/components/StdDesign/StdDataEntry/StdFormItem.vue'
|
||||
import './style.less'
|
||||
|
||||
export default defineComponent({
|
||||
props: {
|
||||
dataList: {
|
||||
type: Array,
|
||||
required: true,
|
||||
},
|
||||
dataSource: {
|
||||
type: Object,
|
||||
required: true,
|
||||
},
|
||||
error: {
|
||||
type: Object,
|
||||
required: false,
|
||||
},
|
||||
layout: {
|
||||
type: String,
|
||||
required: false,
|
||||
},
|
||||
},
|
||||
emits: ['update:dataSource'],
|
||||
setup(props, { slots }) {
|
||||
return () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const template: any = []
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
props.dataList.forEach((v: any) => {
|
||||
let show = true
|
||||
if (v.edit.show) {
|
||||
if (typeof v.edit.show === 'boolean')
|
||||
show = v.edit.show
|
||||
else if (typeof v.edit.show === 'function')
|
||||
show = v.edit.show(props.dataSource)
|
||||
}
|
||||
if (v.edit.type && show) {
|
||||
template.push(<StdFormItem dataIndex={v.dataIndex} label={v.title()} extra={v.extra} error={props.error}>
|
||||
{v.edit.type(v.edit, props.dataSource, v.dataIndex)}
|
||||
</StdFormItem>,
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
if (slots.action)
|
||||
template.push(<div class={'std-data-entry-action'}>{slots.action()}</div>)
|
||||
|
||||
return <Form layout={props.layout || 'vertical'}>{template}</Form>
|
||||
}
|
||||
},
|
||||
})
|
||||
@ -1,43 +1,49 @@
|
||||
<script setup lang="ts">
|
||||
import {computed} from 'vue'
|
||||
import {useGettext} from 'vue3-gettext'
|
||||
import { computed } from 'vue'
|
||||
import { useGettext } from 'vue3-gettext'
|
||||
|
||||
const {$gettext} = useGettext()
|
||||
const props = defineProps<Props>()
|
||||
|
||||
const { $gettext } = useGettext()
|
||||
|
||||
export interface Props {
|
||||
dataIndex?: string
|
||||
label?: string
|
||||
extra?: string
|
||||
error?: any
|
||||
error?: {
|
||||
[key: string]: string
|
||||
}
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
|
||||
const tag = computed(() => {
|
||||
return props.error?.[props.dataIndex] ?? ''
|
||||
})
|
||||
|
||||
const valid_status = computed(() => {
|
||||
if (!!tag.value) {
|
||||
if (tag.value)
|
||||
return 'error'
|
||||
} else {
|
||||
else
|
||||
return 'success'
|
||||
}
|
||||
})
|
||||
|
||||
const help = computed(() => {
|
||||
if (tag.value.indexOf('required') > -1) {
|
||||
if (tag.value.includes('required'))
|
||||
return () => $gettext('This field should not be empty')
|
||||
}
|
||||
|
||||
return () => {
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<a-form-item :label="label" :extra="extra" :validate-status="valid_status" :help="help?.()">
|
||||
<slot/>
|
||||
</a-form-item>
|
||||
<AFormItem
|
||||
:label="label"
|
||||
:extra="extra"
|
||||
:validate-status="valid_status"
|
||||
:help="help?.()"
|
||||
>
|
||||
<slot />
|
||||
</AFormItem>
|
||||
</template>
|
||||
|
||||
<style scoped lang="less">
|
||||
@ -0,0 +1,53 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import type { SelectProps } from 'ant-design-vue'
|
||||
|
||||
const props = defineProps<{
|
||||
value: string
|
||||
mask: Record<string, string | (() => string)>
|
||||
}>()
|
||||
|
||||
const emit = defineEmits(['update:value'])
|
||||
|
||||
const options = computed(() => {
|
||||
const _options = ref<SelectProps['options']>([])
|
||||
|
||||
for (const [key, value] of Object.entries(props.mask)) {
|
||||
const v = value as () => string
|
||||
|
||||
_options.value!.push({ label: v?.(), value: key })
|
||||
}
|
||||
|
||||
return _options
|
||||
})
|
||||
|
||||
const _value = computed({
|
||||
get() {
|
||||
let v
|
||||
|
||||
if (typeof props.mask?.[props.value] === 'function')
|
||||
v = (props.mask[props.value] as () => string)()
|
||||
else if (typeof props.mask?.[props.value] === 'string')
|
||||
v = props.mask[props.value]
|
||||
else
|
||||
v = props.value
|
||||
|
||||
return v
|
||||
},
|
||||
set(v) {
|
||||
emit('update:value', v)
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ASelect
|
||||
v-model:value="_value"
|
||||
:options="options.value"
|
||||
style="min-width: 180px"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
|
||||
</style>
|
||||
@ -0,0 +1,101 @@
|
||||
import { h } from 'vue'
|
||||
import { Input, InputNumber, Switch, Textarea } from 'ant-design-vue'
|
||||
import _ from 'lodash'
|
||||
import StdDataEntry from './StdDataEntry'
|
||||
import StdSelector from './components/StdSelector.vue'
|
||||
import StdSelect from './components/StdSelect.vue'
|
||||
import StdPassword from './components/StdPassword.vue'
|
||||
import type { StdDesignEdit } from '@/components/StdDesign/types'
|
||||
|
||||
const fn = _.get
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function readonly(edit: StdDesignEdit, dataSource: any, dataIndex: any) {
|
||||
return h('p', fn(dataSource, dataIndex))
|
||||
}
|
||||
|
||||
function placeholder_helper(edit: StdDesignEdit) {
|
||||
return typeof edit.config?.placeholder === 'function' ? edit.config?.placeholder() : edit.config?.placeholder
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function input(edit: StdDesignEdit, dataSource: any, dataIndex: any) {
|
||||
return h(Input, {
|
||||
'placeholder': placeholder_helper(edit),
|
||||
'value': dataSource?.[dataIndex],
|
||||
'onUpdate:value': value => {
|
||||
dataSource[dataIndex] = value
|
||||
},
|
||||
})
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function inputNumber(edit: StdDesignEdit, dataSource: any, dataIndex: any) {
|
||||
return h(InputNumber, {
|
||||
'placeholder': placeholder_helper(edit),
|
||||
'min': edit.config?.min,
|
||||
'max': edit.config?.max,
|
||||
'value': dataSource?.[dataIndex],
|
||||
'onUpdate:value': value => {
|
||||
dataSource[dataIndex] = value
|
||||
},
|
||||
})
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function textarea(edit: StdDesignEdit, dataSource: any, dataIndex: any) {
|
||||
return h(Textarea, {
|
||||
'placeholder': placeholder_helper(edit),
|
||||
'value': dataSource?.[dataIndex],
|
||||
'onUpdate:value': value => {
|
||||
dataSource[dataIndex] = value
|
||||
},
|
||||
})
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function password(edit: StdDesignEdit, dataSource: any, dataIndex: any) {
|
||||
return <StdPassword
|
||||
v-model:value={dataSource[dataIndex]}
|
||||
generate={edit.config?.generate}
|
||||
placeholder={placeholder_helper(edit)}
|
||||
/>
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function select(edit: StdDesignEdit, dataSource: any, dataIndex: any) {
|
||||
return <StdSelect
|
||||
v-model:value={dataSource[dataIndex]}
|
||||
mask={edit.mask}
|
||||
/>
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function selector(edit: StdDesignEdit, dataSource: any, dataIndex: any) {
|
||||
return <StdSelector
|
||||
v-model:selectedKey={dataSource[dataIndex]}
|
||||
recordValueIndex={edit.selector?.recordValueIndex}
|
||||
selectionType={edit.selector?.selectionType}
|
||||
api={edit.selector?.api}
|
||||
columns={edit.selector?.columns}
|
||||
disableSearch={edit.selector?.disable_search}
|
||||
getParams={edit.selector?.get_params}
|
||||
description={edit.selector?.description}
|
||||
/>
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function switcher(edit: StdDesignEdit, dataSource: any, dataIndex: any) {
|
||||
return h(Switch, {
|
||||
'checked': dataSource?.[dataIndex],
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
'onUpdate:checked': (value: any) => {
|
||||
dataSource[dataIndex] = value
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export {
|
||||
readonly,
|
||||
input,
|
||||
textarea,
|
||||
select,
|
||||
selector,
|
||||
password,
|
||||
inputNumber,
|
||||
switcher,
|
||||
}
|
||||
|
||||
export default StdDataEntry
|
||||
@ -0,0 +1,49 @@
|
||||
import Curd from '@/api/curd'
|
||||
import {IKeyEvt} from '@/components/StdDesign/StdDataDisplay/types'
|
||||
import {Ref} from 'vue'
|
||||
|
||||
export interface StdDesignEdit {
|
||||
type?: function // component type
|
||||
|
||||
mask?: {
|
||||
[key: string]: () => string
|
||||
} // use for select-option
|
||||
|
||||
rules?: [] // validator rules
|
||||
|
||||
selector?: {
|
||||
get_params?: {}
|
||||
recordValueIndex: any // relative to api return
|
||||
selectionType: any
|
||||
api: Curd,
|
||||
valueApi?: Curd,
|
||||
columns: any
|
||||
disable_search?: boolean
|
||||
description?: string
|
||||
bind?: any
|
||||
itemKey?: any // default is id
|
||||
dataSourceValueIndex?: any // relative to dataSource
|
||||
} // StdSelector Config
|
||||
|
||||
config?: {
|
||||
label?: string | (() => string) // label for form item
|
||||
size?: string // class size of Std image upload
|
||||
placeholder?: string | (() => string) // placeholder for input
|
||||
generate?: boolean // generate btn for StdPassword
|
||||
min?: number // min value for input number
|
||||
max?: number // max value for input number
|
||||
error_messages?: Ref
|
||||
hint?: string | (() => string) // hint form item
|
||||
}
|
||||
|
||||
flex?: Flex
|
||||
}
|
||||
|
||||
|
||||
export interface Flex {
|
||||
sm?: string | number | boolean
|
||||
md?: string | number | boolean
|
||||
lg?: string | number | boolean
|
||||
xl?: string | number | boolean
|
||||
xxl?: string | number | boolean
|
||||
}
|
||||
@ -1,6 +1,10 @@
|
||||
<template>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewBox="0 0 24 24">
|
||||
<path
|
||||
d="M12.1,22c-0.3,0-0.6,0-0.9,0c-5.5-0.5-9.5-5.4-9-10.9c0.4-4.8,4.2-8.6,9-9c0.4,0,0.8,0.2,1,0.5c0.2,0.3,0.2,0.8-0.1,1.1c-2,2.7-1.4,6.4,1.3,8.4c2.1,1.6,5,1.6,7.1,0c0.3-0.2,0.7-0.3,1.1-0.1c0.3,0.2,0.5,0.6,0.5,1c-0.2,2.7-1.5,5.1-3.6,6.8C16.6,21.2,14.4,22,12.1,22zM9.3,4.4c-2.9,1-5,3.6-5.2,6.8c-0.4,4.4,2.8,8.3,7.2,8.7c2.1,0.2,4.2-0.4,5.8-1.8c1.1-0.9,1.9-2.1,2.4-3.4c-2.5,0.9-5.3,0.5-7.5-1.1C9.2,11.4,8.1,7.7,9.3,4.4z"/>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
aria-hidden="true"
|
||||
focusable="false"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path d="M12.1,22c-0.3,0-0.6,0-0.9,0c-5.5-0.5-9.5-5.4-9-10.9c0.4-4.8,4.2-8.6,9-9c0.4,0,0.8,0.2,1,0.5c0.2,0.3,0.2,0.8-0.1,1.1c-2,2.7-1.4,6.4,1.3,8.4c2.1,1.6,5,1.6,7.1,0c0.3-0.2,0.7-0.3,1.1-0.1c0.3,0.2,0.5,0.6,0.5,1c-0.2,2.7-1.5,5.1-3.6,6.8C16.6,21.2,14.4,22,12.1,22zM9.3,4.4c-2.9,1-5,3.6-5.2,6.8c-0.4,4.4,2.8,8.3,7.2,8.7c2.1,0.2,4.2-0.4,5.8-1.8c1.1-0.9,1.9-2.1,2.4-3.4c-2.5,0.9-5.3,0.5-7.5-1.1C9.2,11.4,8.1,7.7,9.3,4.4z" />
|
||||
</svg>
|
||||
</template>
|
||||
|
||||
@ -1,18 +1,18 @@
|
||||
<template>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewBox="0 0 24 24">
|
||||
<path
|
||||
d="M12,18c-3.3,0-6-2.7-6-6s2.7-6,6-6s6,2.7,6,6S15.3,18,12,18zM12,8c-2.2,0-4,1.8-4,4c0,2.2,1.8,4,4,4c2.2,0,4-1.8,4-4C16,9.8,14.2,8,12,8z"/>
|
||||
<path d="M12,4c-0.6,0-1-0.4-1-1V1c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,3.6,12.6,4,12,4z"/>
|
||||
<path d="M12,24c-0.6,0-1-0.4-1-1v-2c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,23.6,12.6,24,12,24z"/>
|
||||
<path
|
||||
d="M5.6,6.6c-0.3,0-0.5-0.1-0.7-0.3L3.5,4.9c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C6.2,6.5,5.9,6.6,5.6,6.6z"/>
|
||||
<path
|
||||
d="M19.8,20.8c-0.3,0-0.5-0.1-0.7-0.3l-1.4-1.4c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C20.3,20.7,20,20.8,19.8,20.8z"/>
|
||||
<path d="M3,13H1c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S3.6,13,3,13z"/>
|
||||
<path d="M23,13h-2c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S23.6,13,23,13z"/>
|
||||
<path
|
||||
d="M4.2,20.8c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C4.7,20.7,4.5,20.8,4.2,20.8z"/>
|
||||
<path
|
||||
d="M18.4,6.6c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C18.9,6.5,18.6,6.6,18.4,6.6z"/>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
aria-hidden="true"
|
||||
focusable="false"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path d="M12,18c-3.3,0-6-2.7-6-6s2.7-6,6-6s6,2.7,6,6S15.3,18,12,18zM12,8c-2.2,0-4,1.8-4,4c0,2.2,1.8,4,4,4c2.2,0,4-1.8,4-4C16,9.8,14.2,8,12,8z" />
|
||||
<path d="M12,4c-0.6,0-1-0.4-1-1V1c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,3.6,12.6,4,12,4z" />
|
||||
<path d="M12,24c-0.6,0-1-0.4-1-1v-2c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,23.6,12.6,24,12,24z" />
|
||||
<path d="M5.6,6.6c-0.3,0-0.5-0.1-0.7-0.3L3.5,4.9c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C6.2,6.5,5.9,6.6,5.6,6.6z" />
|
||||
<path d="M19.8,20.8c-0.3,0-0.5-0.1-0.7-0.3l-1.4-1.4c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C20.3,20.7,20,20.8,19.8,20.8z" />
|
||||
<path d="M3,13H1c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S3.6,13,3,13z" />
|
||||
<path d="M23,13h-2c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S23.6,13,23,13z" />
|
||||
<path d="M4.2,20.8c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C4.7,20.7,4.5,20.8,4.2,20.8z" />
|
||||
<path d="M18.4,6.6c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C18.9,6.5,18.6,6.6,18.4,6.6z" />
|
||||
</svg>
|
||||
</template>
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
<template>
|
||||
<router-view/>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'BaseRouterView'
|
||||
name: 'BaseRouterView',
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<RouterView />
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
|
||||
@ -1,33 +1,34 @@
|
||||
<script>
|
||||
export default {
|
||||
name: 'Loading',
|
||||
props: {
|
||||
loading: {
|
||||
type: [Boolean, String],
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-show="loading"
|
||||
class="loading"
|
||||
>
|
||||
<div class="wrapper center">
|
||||
<a-spin>
|
||||
<a-icon
|
||||
slot="indicator"
|
||||
spin
|
||||
style="font-size: 30px"
|
||||
type="loading"
|
||||
/>
|
||||
</a-spin>
|
||||
<ASpin>
|
||||
<template #indicator>
|
||||
<AIcon
|
||||
spin
|
||||
style="font-size: 30px"
|
||||
type="loading"
|
||||
/>
|
||||
</template>
|
||||
</ASpin>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'Loading',
|
||||
props: {
|
||||
loading: {
|
||||
type: [Boolean, String],
|
||||
default: false
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import {useUserStore} from './moudule/user'
|
||||
import {useSettingsStore} from './moudule/settings'
|
||||
import { useUserStore } from './moudule/user'
|
||||
import { useSettingsStore } from './moudule/settings'
|
||||
|
||||
export {
|
||||
useUserStore,
|
||||
useSettingsStore
|
||||
useSettingsStore,
|
||||
}
|
||||
|
||||
@ -1 +1 @@
|
||||
{"version":"2.0.0-beta.4","build_id":50,"total_build":254}
|
||||
{"version":"2.0.0-beta.4","build_id":53,"total_build":257}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue