Skip to content

Commit

Permalink
Merge pull request #14 from gooaclok819/revert-9-main
Browse files Browse the repository at this point in the history
Revert "feat: 新增Node节点的排序功能"
  • Loading branch information
gooaclok819 authored Oct 4, 2024
2 parents 6a741b6 + 8cb9f35 commit cb7e206
Show file tree
Hide file tree
Showing 25 changed files with 398 additions and 570 deletions.
6 changes: 3 additions & 3 deletions api/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

func GetV2ray(c *gin.Context) {
var sub models.Subscription
var sub models.Subcription
subname := c.Param("subname")
subname = node.Base64Decode(subname)
sub.Name = subname
Expand Down Expand Up @@ -61,7 +61,7 @@ func GetV2ray(c *gin.Context) {
c.Writer.WriteString(node.Base64Encode(baselist))
}
func GetClash(c *gin.Context) {
var sub models.Subscription
var sub models.Subcription
subname := c.Param("subname")
subname = node.Base64Decode(subname)
sub.Name = subname
Expand Down Expand Up @@ -120,7 +120,7 @@ func GetClash(c *gin.Context) {
c.Writer.WriteString(string(DecodeClash))
}
func GetSurge(c *gin.Context) {
var sub models.Subscription
var sub models.Subcription
subname := c.Param("subname")
subname = node.Base64Decode(subname)
sub.Name = subname
Expand Down
14 changes: 7 additions & 7 deletions api/mentu.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,20 @@ func GetMenus(c *gin.Context) {
},
// 订阅管理
{
Path: "/subscription",
Path: "/subcription",
Component: "Layout",
Redirect: "/subscription/subs",
Name: "subscription",
Redirect: "/subcription/subs",
Name: "subcription",
Meta: Meta{
Title: "subscription",
Title: "subcription",
Icon: "client",
Hidden: false,
Roles: []string{"ADMIN"},
},
Children: []Child{
{
Path: "subs",
Component: "subscription/subs",
Component: "subcription/subs",
Name: "Subs",
Meta: Meta{
Title: "sublist",
Expand All @@ -83,7 +83,7 @@ func GetMenus(c *gin.Context) {
},
{
Path: "nodes",
Component: "subscription/nodes",
Component: "subcription/nodes",
Name: "Nodes",
Meta: Meta{
Title: "nodelist",
Expand All @@ -95,7 +95,7 @@ func GetMenus(c *gin.Context) {
},
{
Path: "template",
Component: "subscription/template",
Component: "subcription/template",
Name: "Template",
Meta: Meta{
Title: "templatelist",
Expand Down
52 changes: 16 additions & 36 deletions api/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,31 @@ import (
"github.com/gin-gonic/gin"
)

// NodeUpdate 节点更新
func NodeUpdate(c *gin.Context) {
var nodeUpdating models.Node
idStr := c.PostForm("id")
func NodeUpdadte(c *gin.Context) {
var node models.Node
name := c.PostForm("name")
oldname := c.PostForm("oldname")
oldlink := c.PostForm("oldlink")
link := c.PostForm("link")
if name == "" || link == "" {
c.JSON(400, gin.H{
"msg": "节点名称 or 备注不能为空",
})
return
}
id, err := strconv.Atoi(idStr)
// 查找旧节点
node.Name = oldname
node.Link = oldlink
err := node.Find()
if err != nil {
// 处理转换错误,比如返回一个错误响应
c.JSON(400, gin.H{
"error": "无效的ID",
"msg": err.Error(),
})
return
}
nodeUpdating.ID = id
nodeUpdating.Name = name
nodeUpdating.Link = link
err = nodeUpdating.UpdateById()
node.Name = name
node.Link = link
err = node.Update()
if err != nil {
c.JSON(400, gin.H{
"msg": "更新失败",
Expand All @@ -48,7 +49,7 @@ func NodeUpdate(c *gin.Context) {
})
}

// NodeGet 获取节点列表
// 获取节点列表
func NodeGet(c *gin.Context) {
var Node models.Node
nodes, err := Node.List()
Expand All @@ -65,7 +66,7 @@ func NodeGet(c *gin.Context) {
})
}

// NodeAdd 添加节点
// 添加节点
func NodeAdd(c *gin.Context) {
var Node models.Node
link := c.PostForm("link")
Expand Down Expand Up @@ -168,7 +169,7 @@ func NodeAdd(c *gin.Context) {
})
}

// NodeDel 删除节点
// 删除节点
func NodeDel(c *gin.Context) {
var Node models.Node
id := c.Query("id")
Expand All @@ -193,7 +194,7 @@ func NodeDel(c *gin.Context) {
})
}

// NodesTotal 节点统计
// 节点统计
func NodesTotal(c *gin.Context) {
var Node models.Node
nodes, err := Node.List()
Expand All @@ -210,24 +211,3 @@ func NodesTotal(c *gin.Context) {
"msg": "取得节点统计",
})
}

func NodeSort(c *gin.Context) {
var nodes []models.Node
// 解析请求体中的 JSON 数据
if err := c.BindJSON(&nodes); err != nil {
c.JSON(400, gin.H{"msg": "解析失败", "error": err.Error()})
return
}

// 更新节点排序
if err := models.UpdateSort(nodes); err != nil {
c.JSON(500, gin.H{"msg": "排序更新失败", "error": err.Error()})
return
}

c.JSON(200, gin.H{
"code": "00000",
"data": nil,
"msg": "排序更新成功",
})
}
10 changes: 5 additions & 5 deletions api/sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func SubTotal(c *gin.Context) {
var Sub models.Subscription
var Sub models.Subcription
subs, err := Sub.List()
count := len(subs)
if err != nil {
Expand All @@ -28,7 +28,7 @@ func SubTotal(c *gin.Context) {

// 获取订阅列表
func SubGet(c *gin.Context) {
var Sub models.Subscription
var Sub models.Subcription
Subs, err := Sub.List()
if err != nil {
c.JSON(500, gin.H{
Expand All @@ -45,7 +45,7 @@ func SubGet(c *gin.Context) {

// 添加节点
func SubAdd(c *gin.Context) {
var sub models.Subscription
var sub models.Subcription
name := c.PostForm("name")
config := c.PostForm("config")
nodes := c.PostForm("nodes")
Expand Down Expand Up @@ -92,7 +92,7 @@ func SubAdd(c *gin.Context) {

// 更新节点
func SubUpdate(c *gin.Context) {
var sub models.Subscription
var sub models.Subcription
name := c.PostForm("name")
oldname := c.PostForm("oldname")
config := c.PostForm("config")
Expand Down Expand Up @@ -150,7 +150,7 @@ func SubUpdate(c *gin.Context) {

// 删除节点
func SubDel(c *gin.Context) {
var sub models.Subscription
var sub models.Subcription
id := c.Query("id")
if id == "" {
c.JSON(400, gin.H{
Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var embeddedFiles embed.FS
//go:embed template
var Template embed.FS

func TemplateInit() {
func Templateinit() {
// 设置template路径
// 检查目录是否创建
subFS, err := fs.Sub(Template, "template")
Expand Down Expand Up @@ -67,11 +67,11 @@ func main() {
// 初始化gin框架
r := gin.Default()
// 初始化日志配置
utils.LogsInit()
utils.Loginit()
// 初始化数据库
models.InitSqlite()
// 初始化模板
TemplateInit()
Templateinit()
// 安装中间件
r.Use(middlewares.AuthorToken) // jwt验证token
// 设置静态资源路径
Expand All @@ -93,7 +93,7 @@ func main() {
// 注册路由
routers.User(r)
routers.Mentus(r)
routers.Subscription(r)
routers.Subcription(r)
routers.Nodes(r)
routers.Clients(r)
routers.Total(r)
Expand Down
10 changes: 5 additions & 5 deletions middlewares/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func GetIp(c *gin.Context) {
log.Println(err)
return
}
var sub models.Subscription
var sub models.Subcription
if subname, ok := subname.(string); ok {
sub.Name = subname
}
Expand All @@ -53,10 +53,10 @@ func GetIp(c *gin.Context) {
if err != nil {
iploga := []models.SubLogs{
{IP: ip,
Addr: ipinfo.Addr,
SubscriptionID: sub.ID,
Date: time.Now().Format("2006-01-02 15:04:05"),
Count: 1,
Addr: ipinfo.Addr,
SubcriptionID: sub.ID,
Date: time.Now().Format("2006-01-02 15:04:05"),
Count: 1,
},
}
sub.SubLogs = iploga
Expand Down
33 changes: 16 additions & 17 deletions models/iplogs.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
package models

type SubLogs struct {
ID int
IP string
Date string
Addr string
Count int
SubscriptionID int
ID int
IP string
Date string
Addr string
Count int
SubcriptionID int
}

// Add 添加IP
func (ipLog *SubLogs) Add() error {
return DB.Create(ipLog).Error
func (iplog *SubLogs) Add() error {
return DB.Create(iplog).Error
}


// Find 查找IP
func (ipLog *SubLogs) Find(id int) error {
return DB.Where("ip = ? or subscription_id = ?", ipLog.IP, id).First(ipLog).Error
// 查找IP
func (iplog *SubLogs) Find(id int) error {
return DB.Where("ip = ? and subcription_id = ?", iplog.IP, id).First(iplog).Error
}

// Update 更新IP
func (ipLog *SubLogs) Update() error {
return DB.Where("id = ? or ip = ?", ipLog.ID, ipLog.IP).Updates(ipLog).Error
func (iplog *SubLogs) Update() error {
return DB.Where("id = ? or ip = ?", iplog.ID, iplog.IP).Updates(iplog).Error
}

// List 获取IP列表
func (ipLog *SubLogs) List() ([]SubLogs, error) {
func (iplog *SubLogs) List() ([]SubLogs, error) {
var iplogs []SubLogs
err := DB.Find(&iplogs).Error
if err != nil {
Expand All @@ -36,6 +35,6 @@ func (ipLog *SubLogs) List() ([]SubLogs, error) {
}

// Del 删除IP
func (ipLog *SubLogs) Del() error {
return DB.Delete(ipLog).Error
func (iplog *SubLogs) Del() error {
return DB.Delete(iplog).Error
}
Loading

0 comments on commit cb7e206

Please sign in to comment.