ljw 1 год назад
Родитель
Сommit
28f047ec79
2 измененных файлов с 29 добавлено и 1 удалено
  1. 11 1
      http/controller/api/ab.go
  2. 18 0
      service/addressBook.go

+ 11 - 1
http/controller/api/ab.go

@@ -393,7 +393,7 @@ func (a *Ab) PTags(c *gin.Context) {
393
 // @Router /ab/peer/add/{guid} [post]
393
 // @Router /ab/peer/add/{guid} [post]
394
 // @Security BearerAuth
394
 // @Security BearerAuth
395
 func (a *Ab) PeerAdd(c *gin.Context) {
395
 func (a *Ab) PeerAdd(c *gin.Context) {
396
-	// forceAlwaysRelay永远是字符串"false",真是坑
396
+	// forceAlwaysRelay永远是字符串"false"
397
 	//f := &gin.H{}
397
 	//f := &gin.H{}
398
 	f := &requstform.PersonalAddressBookForm{}
398
 	f := &requstform.PersonalAddressBookForm{}
399
 	err := c.ShouldBindJSON(f)
399
 	err := c.ShouldBindJSON(f)
@@ -405,6 +405,16 @@ func (a *Ab) PeerAdd(c *gin.Context) {
405
 	u := service.AllService.UserService.CurUser(c)
405
 	u := service.AllService.UserService.CurUser(c)
406
 	f.UserId = u.Id
406
 	f.UserId = u.Id
407
 	ab := f.ToAddressBook()
407
 	ab := f.ToAddressBook()
408
+
409
+	if ab.Platform == "" || ab.Username == "" || ab.Hostname == "" {
410
+		peer := service.AllService.PeerService.FindById(ab.Id)
411
+		if peer.RowId != 0 {
412
+			ab.Platform = service.AllService.AddressBookService.PlatformFromOs(peer.Os)
413
+			ab.Username = peer.Username
414
+			ab.Hostname = peer.Hostname
415
+		}
416
+	}
417
+
408
 	err = service.AllService.AddressBookService.AddAddressBook(ab)
418
 	err = service.AllService.AddressBookService.AddAddressBook(ab)
409
 	if err != nil {
419
 	if err != nil {
410
 		response.Error(c, response.TranslateMsg(c, "OperationFailed")+err.Error())
420
 		response.Error(c, response.TranslateMsg(c, "OperationFailed")+err.Error())

+ 18 - 0
service/addressBook.go

@@ -5,6 +5,7 @@ import (
5
 	"Gwen/model"
5
 	"Gwen/model"
6
 	"github.com/google/uuid"
6
 	"github.com/google/uuid"
7
 	"gorm.io/gorm"
7
 	"gorm.io/gorm"
8
+	"strings"
8
 )
9
 )
9
 
10
 
10
 type AddressBookService struct {
11
 type AddressBookService struct {
@@ -127,3 +128,20 @@ func (t *AddressBookService) SharedPeer(shareToken string) *model.ShareRecord {
127
 	global.DB.Where("share_token = ?", shareToken).First(m)
128
 	global.DB.Where("share_token = ?", shareToken).First(m)
128
 	return m
129
 	return m
129
 }
130
 }
131
+
132
+// PlatformFromOs
133
+func (t *AddressBookService) PlatformFromOs(os string) string {
134
+	if strings.Contains(os, "Android") || strings.Contains(os, "android") {
135
+		return "Android"
136
+	}
137
+	if strings.Contains(os, "Windows") || strings.Contains(os, "windows") {
138
+		return "Windows"
139
+	}
140
+	if strings.Contains(os, "Linux") || strings.Contains(os, "linux") {
141
+		return "Linux"
142
+	}
143
+	if strings.Contains(os, "mac") || strings.Contains(os, "Mac") {
144
+		return "Mac OS"
145
+	}
146
+	return ""
147
+}