addressBook.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package admin
  2. import (
  3. "encoding/json"
  4. "github.com/lejianwen/rustdesk-api/v2/model"
  5. )
  6. type AddressBookForm struct {
  7. RowId uint `json:"row_id"`
  8. Id string `json:"id" validate:"required"`
  9. Username string `json:"username" `
  10. Password string `json:"password" `
  11. Hostname string `json:"hostname" `
  12. Alias string `json:"alias" `
  13. Platform string `json:"platform" `
  14. Tags []string `json:"tags"`
  15. Hash string `json:"hash"`
  16. UserId uint `json:"user_id"`
  17. UserIds []uint `json:"user_ids"`
  18. ForceAlwaysRelay bool `json:"forceAlwaysRelay"`
  19. RdpPort string `json:"rdpPort"`
  20. RdpUsername string `json:"rdpUsername"`
  21. Online bool `json:"online"`
  22. LoginName string `json:"loginName" `
  23. SameServer bool `json:"sameServer"`
  24. CollectionId uint `json:"collection_id"`
  25. }
  26. func (a AddressBookForm) ToAddressBook() *model.AddressBook {
  27. //tags转换
  28. tags, _ := json.Marshal(a.Tags)
  29. return &model.AddressBook{
  30. RowId: a.RowId,
  31. Id: a.Id,
  32. Username: a.Username,
  33. Password: a.Password,
  34. Hostname: a.Hostname,
  35. Alias: a.Alias,
  36. Platform: a.Platform,
  37. Tags: tags,
  38. Hash: a.Hash,
  39. UserId: a.UserId,
  40. ForceAlwaysRelay: a.ForceAlwaysRelay,
  41. RdpPort: a.RdpPort,
  42. RdpUsername: a.RdpUsername,
  43. Online: a.Online,
  44. LoginName: a.LoginName,
  45. SameServer: a.SameServer,
  46. CollectionId: a.CollectionId,
  47. }
  48. }
  49. func (a AddressBookForm) ToAddressBooks() []*model.AddressBook {
  50. //tags转换
  51. tags, _ := json.Marshal(a.Tags)
  52. abs := make([]*model.AddressBook, 0, len(a.UserIds))
  53. for _, userId := range a.UserIds {
  54. abs = append(abs, &model.AddressBook{
  55. RowId: a.RowId,
  56. Id: a.Id,
  57. Username: a.Username,
  58. Password: a.Password,
  59. Hostname: a.Hostname,
  60. Alias: a.Alias,
  61. Platform: a.Platform,
  62. Tags: tags,
  63. Hash: a.Hash,
  64. UserId: userId,
  65. ForceAlwaysRelay: a.ForceAlwaysRelay,
  66. RdpPort: a.RdpPort,
  67. RdpUsername: a.RdpUsername,
  68. Online: a.Online,
  69. LoginName: a.LoginName,
  70. SameServer: a.SameServer,
  71. CollectionId: a.CollectionId,
  72. })
  73. }
  74. return abs
  75. }
  76. type AddressBookQuery struct {
  77. UserId int `form:"user_id"`
  78. CollectionId *int `form:"collection_id"`
  79. IsMy int `form:"is_my"`
  80. Username string `form:"username"`
  81. Hostname string `form:"hostname"`
  82. Id string `form:"id"`
  83. PageQuery
  84. }
  85. type ShareByWebClientForm struct {
  86. Id string `json:"id" validate:"required"`
  87. PasswordType string `json:"password_type" validate:"required,oneof=once fixed"` //只能是once,fixed
  88. Password string `json:"password" validate:"required"`
  89. Expire int64 `json:"expire"`
  90. }
  91. func (sbwcf ShareByWebClientForm) ToShareRecord() *model.ShareRecord {
  92. return &model.ShareRecord{
  93. UserId: 0,
  94. PeerId: sbwcf.Id,
  95. PasswordType: sbwcf.PasswordType,
  96. Password: sbwcf.Password,
  97. Expire: sbwcf.Expire,
  98. }
  99. }
  100. type AddressBookCollectionQuery struct {
  101. UserId int `form:"user_id"`
  102. IsMy int `form:"is_my"`
  103. PageQuery
  104. }
  105. type AddressBookCollectionSimpleListQuery struct {
  106. UserIds []uint `form:"user_ids"`
  107. }
  108. type AddressBookCollectionRuleQuery struct {
  109. UserId int `form:"user_id"`
  110. CollectionId int `form:"collection_id"`
  111. IsMy int `form:"is_my"`
  112. PageQuery
  113. }
  114. type BatchCreateFromPeersForm struct {
  115. CollectionId uint `json:"collection_id"`
  116. PeerIds []uint `json:"peer_ids"`
  117. Tags []string `json:"tags"`
  118. UserId uint `json:"user_id"`
  119. }
  120. type BatchUpdateTagsForm struct {
  121. RowIds []uint `json:"row_ids"`
  122. Tags []string `json:"tags"`
  123. }