修复(#23): 修复用户订阅列表未回显用户级限速
* 修复(#23): 修复用户订阅列表未回显用户级限速 Co-authored-by: multica-agent <github@multica.ai> * 修复(#23): 移除 PR 草稿文件 Co-authored-by: multica-agent <github@multica.ai> --------- Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -575,6 +575,7 @@ type (
|
|||||||
Traffic int64 `json:"traffic"`
|
Traffic int64 `json:"traffic"`
|
||||||
Download int64 `json:"download"`
|
Download int64 `json:"download"`
|
||||||
Upload int64 `json:"upload"`
|
Upload int64 `json:"upload"`
|
||||||
|
TrafficLimit []TrafficLimit `json:"user_traffic_limit"`
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
Status uint8 `json:"status"`
|
Status uint8 `json:"status"`
|
||||||
EntitlementSource string `json:"entitlement_source"`
|
EntitlementSource string `json:"entitlement_source"`
|
||||||
|
|||||||
@@ -2,8 +2,10 @@ package user
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/perfect-panel/server/internal/model/group"
|
"github.com/perfect-panel/server/internal/model/group"
|
||||||
|
"github.com/perfect-panel/server/internal/model/user"
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
"github.com/perfect-panel/server/internal/types"
|
"github.com/perfect-panel/server/internal/types"
|
||||||
"github.com/perfect-panel/server/pkg/logger"
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
@@ -61,12 +63,20 @@ func (l *GetUserSubscribeLogic) GetUserSubscribe(req *types.GetUserSubscribeList
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, item := range data {
|
for _, item := range data {
|
||||||
var sub types.UserSubscribe
|
sub := buildUserSubscribeListItem(item, groupNames[item.NodeGroupId])
|
||||||
tool.DeepCopy(&sub, item)
|
|
||||||
sub.Short, _ = tool.FixedUniqueString(item.Token, 8, "")
|
|
||||||
sub.NodeGroupId = item.NodeGroupId
|
|
||||||
sub.NodeGroupName = groupNames[item.NodeGroupId]
|
|
||||||
resp.List = append(resp.List, sub)
|
resp.List = append(resp.List, sub)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func buildUserSubscribeListItem(item *user.SubscribeDetails, groupName string) types.UserSubscribe {
|
||||||
|
var sub types.UserSubscribe
|
||||||
|
tool.DeepCopy(&sub, item)
|
||||||
|
sub.Short, _ = tool.FixedUniqueString(item.Token, 8, "")
|
||||||
|
sub.NodeGroupId = item.NodeGroupId
|
||||||
|
sub.NodeGroupName = groupName
|
||||||
|
if item.TrafficLimit != nil && *item.TrafficLimit != "" {
|
||||||
|
_ = json.Unmarshal([]byte(*item.TrafficLimit), &sub.TrafficLimit)
|
||||||
|
}
|
||||||
|
return sub
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
modeluser "github.com/perfect-panel/server/internal/model/user"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestBuildUserSubscribeListItem(t *testing.T) {
|
||||||
|
trafficLimitJSON := `[{"stat_type":"day","stat_value":1,"traffic_usage":10,"speed_limit":5}]`
|
||||||
|
now := time.Unix(1718000000, 0)
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
item *modeluser.SubscribeDetails
|
||||||
|
wantTrafficLimit []types.TrafficLimit
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "non-empty user traffic limit",
|
||||||
|
item: &modeluser.SubscribeDetails{
|
||||||
|
Id: 1,
|
||||||
|
UserId: 2,
|
||||||
|
NodeGroupId: 3,
|
||||||
|
Token: "token-12345678",
|
||||||
|
TrafficLimit: &trafficLimitJSON,
|
||||||
|
StartTime: now,
|
||||||
|
ExpireTime: now,
|
||||||
|
},
|
||||||
|
wantTrafficLimit: []types.TrafficLimit{
|
||||||
|
{
|
||||||
|
StatType: "day",
|
||||||
|
StatValue: 1,
|
||||||
|
TrafficUsage: 10,
|
||||||
|
SpeedLimit: 5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "empty user traffic limit",
|
||||||
|
item: &modeluser.SubscribeDetails{
|
||||||
|
Id: 4,
|
||||||
|
UserId: 5,
|
||||||
|
NodeGroupId: 6,
|
||||||
|
Token: "token-empty",
|
||||||
|
StartTime: now,
|
||||||
|
ExpireTime: now,
|
||||||
|
},
|
||||||
|
wantTrafficLimit: nil,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range tests {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
got := buildUserSubscribeListItem(tc.item, "group-a")
|
||||||
|
if got.NodeGroupName != "group-a" {
|
||||||
|
t.Fatalf("NodeGroupName = %q, want %q", got.NodeGroupName, "group-a")
|
||||||
|
}
|
||||||
|
if len(got.Short) != 8 {
|
||||||
|
t.Fatalf("Short length = %d, want 8", len(got.Short))
|
||||||
|
}
|
||||||
|
if len(got.TrafficLimit) != len(tc.wantTrafficLimit) {
|
||||||
|
t.Fatalf("TrafficLimit length = %d, want %d", len(got.TrafficLimit), len(tc.wantTrafficLimit))
|
||||||
|
}
|
||||||
|
for i := range tc.wantTrafficLimit {
|
||||||
|
if got.TrafficLimit[i] != tc.wantTrafficLimit[i] {
|
||||||
|
t.Fatalf("TrafficLimit[%d] = %+v, want %+v", i, got.TrafficLimit[i], tc.wantTrafficLimit[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
+25
-24
@@ -3679,30 +3679,31 @@ type UserStatisticsResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type UserSubscribe struct {
|
type UserSubscribe struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
IdStr string `json:"id_str"`
|
IdStr string `json:"id_str"`
|
||||||
UserId int64 `json:"user_id"`
|
UserId int64 `json:"user_id"`
|
||||||
OrderId int64 `json:"order_id"`
|
OrderId int64 `json:"order_id"`
|
||||||
SubscribeId int64 `json:"subscribe_id"`
|
SubscribeId int64 `json:"subscribe_id"`
|
||||||
Subscribe Subscribe `json:"subscribe"`
|
Subscribe Subscribe `json:"subscribe"`
|
||||||
NodeGroupId int64 `json:"node_group_id"`
|
NodeGroupId int64 `json:"node_group_id"`
|
||||||
NodeGroupName string `json:"node_group_name"`
|
NodeGroupName string `json:"node_group_name"`
|
||||||
StartTime int64 `json:"start_time"`
|
StartTime int64 `json:"start_time"`
|
||||||
ExpireTime int64 `json:"expire_time"`
|
ExpireTime int64 `json:"expire_time"`
|
||||||
FinishedAt int64 `json:"finished_at"`
|
FinishedAt int64 `json:"finished_at"`
|
||||||
ResetTime int64 `json:"reset_time"`
|
ResetTime int64 `json:"reset_time"`
|
||||||
Traffic int64 `json:"traffic"`
|
Traffic int64 `json:"traffic"`
|
||||||
Download int64 `json:"download"`
|
Download int64 `json:"download"`
|
||||||
Upload int64 `json:"upload"`
|
Upload int64 `json:"upload"`
|
||||||
Token string `json:"token"`
|
TrafficLimit []TrafficLimit `json:"user_traffic_limit"`
|
||||||
Status uint8 `json:"status"`
|
Token string `json:"token"`
|
||||||
EntitlementSource string `json:"entitlement_source"`
|
Status uint8 `json:"status"`
|
||||||
EntitlementOwnerUserId int64 `json:"entitlement_owner_user_id"`
|
EntitlementSource string `json:"entitlement_source"`
|
||||||
ReadOnly bool `json:"read_only"`
|
EntitlementOwnerUserId int64 `json:"entitlement_owner_user_id"`
|
||||||
IsGift bool `json:"is_gift"`
|
ReadOnly bool `json:"read_only"`
|
||||||
Short string `json:"short"`
|
IsGift bool `json:"is_gift"`
|
||||||
CreatedAt int64 `json:"created_at"`
|
Short string `json:"short"`
|
||||||
UpdatedAt int64 `json:"updated_at"`
|
CreatedAt int64 `json:"created_at"`
|
||||||
|
UpdatedAt int64 `json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserSubscribeDetail struct {
|
type UserSubscribeDetail struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user