|
@@ -4,6 +4,7 @@ import (
|
|
|
"be-vpn/internal/dto"
|
|
|
"be-vpn/internal/model"
|
|
|
"be-vpn/internal/storage"
|
|
|
+ "fmt"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
"log"
|
|
|
"math/rand"
|
|
@@ -39,7 +40,7 @@ func Config(c *gin.Context) {
|
|
|
Data: dto.ConfigResult{
|
|
|
FreeTrialDuration: freeTrialDuration,
|
|
|
Timestamp: time.Now().Unix(),
|
|
|
- Node: convert2DtoNode(node),
|
|
|
+ Node: convert2DtoNode(node, 0),
|
|
|
},
|
|
|
})
|
|
|
}
|
|
@@ -67,7 +68,7 @@ func AddUsedDuration(c *gin.Context) {
|
|
|
Data: dto.ConfigResult{
|
|
|
FreeTrialDuration: freeTrialDuration,
|
|
|
Timestamp: time.Now().Unix(),
|
|
|
- Node: convert2DtoNode(healthNodes()[0]),
|
|
|
+ Node: convert2DtoNode(healthNodes()[0], 0),
|
|
|
},
|
|
|
})
|
|
|
}
|
|
@@ -112,9 +113,17 @@ func List(c *gin.Context) {
|
|
|
locker.RLock()
|
|
|
defer locker.RUnlock()
|
|
|
|
|
|
+ countryLabelSeqs := make(map[string]int)
|
|
|
+
|
|
|
dtoNodes := make([]*dto.Node, 0)
|
|
|
for _, node := range healthNodes() {
|
|
|
- dtoNodes = append(dtoNodes, convert2DtoNode(node))
|
|
|
+ seq, ok := countryLabelSeqs[node.CountryCode]
|
|
|
+ if !ok {
|
|
|
+ countryLabelSeqs[node.CountryCode] = 0
|
|
|
+ } else {
|
|
|
+ countryLabelSeqs[node.CountryCode] = seq + 1
|
|
|
+ }
|
|
|
+ dtoNodes = append(dtoNodes, convert2DtoNode(node, countryLabelSeqs[node.CountryCode]))
|
|
|
}
|
|
|
sort.SliceStable(dtoNodes, func(i, j int) bool {
|
|
|
return dtoNodes[i].CountryCode >= dtoNodes[j].CountryCode
|
|
@@ -185,26 +194,30 @@ func healthNodes() []*model.Node {
|
|
|
return healthNodes
|
|
|
}
|
|
|
|
|
|
-func convert2DtoNode(node *model.Node) *dto.Node {
|
|
|
+func convert2DtoNode(node *model.Node, seq int) *dto.Node {
|
|
|
if node == nil {
|
|
|
return nil
|
|
|
}
|
|
|
- icon := ""
|
|
|
- if node.CountryCode == "BR" {
|
|
|
- icon = "http://v.starttransfernow.com/static/BR.jpg"
|
|
|
- } else if node.CountryCode == "DE" {
|
|
|
- icon = "http://v.starttransfernow.com/static/DE.jpg"
|
|
|
- } else if node.CountryCode == "HK" {
|
|
|
- icon = "http://v.starttransfernow.com/static/HK.jpg"
|
|
|
- } else if node.CountryCode == "JP" {
|
|
|
- icon = "http://v.starttransfernow.com/static/JP.jpg"
|
|
|
- } else if node.CountryCode == "US" {
|
|
|
- icon = "http://v.starttransfernow.com/static/US.jpg"
|
|
|
+ icons := map[string]string{
|
|
|
+ "BR": "http://v.starttransfernow.com/static/BR.jpg",
|
|
|
+ "DE": "http://v.starttransfernow.com/static/DE.jpg",
|
|
|
+ "HK": "http://v.starttransfernow.com/static/HK.jpg",
|
|
|
+ "JP": "http://v.starttransfernow.com/static/JP.jpg",
|
|
|
+ "US": "http://v.starttransfernow.com/static/US.jpg",
|
|
|
}
|
|
|
+ countryLabels := map[string]string{
|
|
|
+ "BR": "Brazil",
|
|
|
+ "DE": "Germany",
|
|
|
+ "HK": "Hong Kong",
|
|
|
+ "JP": "Japan",
|
|
|
+ "US": "United States",
|
|
|
+ }
|
|
|
+
|
|
|
return &dto.Node{
|
|
|
- Ip: node.Ip,
|
|
|
- CountryCode: node.CountryCode,
|
|
|
- CountryName: node.CountryName,
|
|
|
- Icon: icon,
|
|
|
+ Ip: node.Ip,
|
|
|
+ CountryCode: node.CountryCode,
|
|
|
+ CountryName: node.CountryName,
|
|
|
+ CountryLabel: fmt.Sprintf("%s - %d", countryLabels[node.CountryCode], seq+1),
|
|
|
+ Icon: icons[node.CountryCode],
|
|
|
}
|
|
|
}
|