Skip to content

Commit

Permalink
fix pc add #13
Browse files Browse the repository at this point in the history
  • Loading branch information
lejianwen committed Oct 16, 2024
1 parent d2390d1 commit 6322177
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
12 changes: 11 additions & 1 deletion http/controller/api/ab.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ func (a *Ab) PTags(c *gin.Context) {
// @Router /ab/peer/add/{guid} [post]
// @Security BearerAuth
func (a *Ab) PeerAdd(c *gin.Context) {
// forceAlwaysRelay永远是字符串"false",真是坑
// forceAlwaysRelay永远是字符串"false"
//f := &gin.H{}
f := &requstform.PersonalAddressBookForm{}
err := c.ShouldBindJSON(f)
Expand All @@ -405,6 +405,16 @@ func (a *Ab) PeerAdd(c *gin.Context) {
u := service.AllService.UserService.CurUser(c)
f.UserId = u.Id
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)
if err != nil {
response.Error(c, response.TranslateMsg(c, "OperationFailed")+err.Error())
Expand Down
18 changes: 18 additions & 0 deletions service/addressBook.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"Gwen/model"
"github.com/google/uuid"
"gorm.io/gorm"
"strings"
)

type AddressBookService struct {
Expand Down Expand Up @@ -127,3 +128,20 @@ func (t *AddressBookService) SharedPeer(shareToken string) *model.ShareRecord {
global.DB.Where("share_token = ?", shareToken).First(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 ""
}

0 comments on commit 6322177

Please sign in to comment.