fix pc add #13
This commit is contained in:
@@ -393,7 +393,7 @@ func (a *Ab) PTags(c *gin.Context) {
|
|||||||
// @Router /ab/peer/add/{guid} [post]
|
// @Router /ab/peer/add/{guid} [post]
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
func (a *Ab) PeerAdd(c *gin.Context) {
|
func (a *Ab) PeerAdd(c *gin.Context) {
|
||||||
// forceAlwaysRelay永远是字符串"false",真是坑
|
// forceAlwaysRelay永远是字符串"false"
|
||||||
//f := &gin.H{}
|
//f := &gin.H{}
|
||||||
f := &requstform.PersonalAddressBookForm{}
|
f := &requstform.PersonalAddressBookForm{}
|
||||||
err := c.ShouldBindJSON(f)
|
err := c.ShouldBindJSON(f)
|
||||||
@@ -405,6 +405,16 @@ func (a *Ab) PeerAdd(c *gin.Context) {
|
|||||||
u := service.AllService.UserService.CurUser(c)
|
u := service.AllService.UserService.CurUser(c)
|
||||||
f.UserId = u.Id
|
f.UserId = u.Id
|
||||||
ab := f.ToAddressBook()
|
ab := f.ToAddressBook()
|
||||||
|
|
||||||
|
if ab.Platform == "" || ab.Username == "" || ab.Hostname == "" {
|
||||||
|
peer := service.AllService.PeerService.FindById(ab.Id)
|
||||||
|
if peer.RowId != 0 {
|
||||||
|
ab.Platform = service.AllService.AddressBookService.PlatformFromOs(peer.Os)
|
||||||
|
ab.Username = peer.Username
|
||||||
|
ab.Hostname = peer.Hostname
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err = service.AllService.AddressBookService.AddAddressBook(ab)
|
err = service.AllService.AddressBookService.AddAddressBook(ab)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.Error(c, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
response.Error(c, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"Gwen/model"
|
"Gwen/model"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AddressBookService struct {
|
type AddressBookService struct {
|
||||||
@@ -127,3 +128,20 @@ func (t *AddressBookService) SharedPeer(shareToken string) *model.ShareRecord {
|
|||||||
global.DB.Where("share_token = ?", shareToken).First(m)
|
global.DB.Where("share_token = ?", shareToken).First(m)
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PlatformFromOs
|
||||||
|
func (t *AddressBookService) PlatformFromOs(os string) string {
|
||||||
|
if strings.Contains(os, "Android") || strings.Contains(os, "android") {
|
||||||
|
return "Android"
|
||||||
|
}
|
||||||
|
if strings.Contains(os, "Windows") || strings.Contains(os, "windows") {
|
||||||
|
return "Windows"
|
||||||
|
}
|
||||||
|
if strings.Contains(os, "Linux") || strings.Contains(os, "linux") {
|
||||||
|
return "Linux"
|
||||||
|
}
|
||||||
|
if strings.Contains(os, "mac") || strings.Contains(os, "Mac") {
|
||||||
|
return "Mac OS"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user