mirror of
https://github.com/lejianwen/rustdesk-api.git
synced 2025-11-29 08:33:21 +00:00
add batch add ab from peer and up my
This commit is contained in:
@@ -335,7 +335,11 @@ func (ct *AddressBook) BatchCreateFromPeers(c *gin.Context) {
|
||||
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
|
||||
return
|
||||
}
|
||||
u := service.AllService.UserService.CurUser(c)
|
||||
|
||||
if f.UserId == 0 {
|
||||
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
|
||||
return
|
||||
}
|
||||
|
||||
if f.CollectionId != 0 {
|
||||
collection := service.AllService.AddressBookService.CollectionInfoById(f.CollectionId)
|
||||
@@ -343,17 +347,13 @@ func (ct *AddressBook) BatchCreateFromPeers(c *gin.Context) {
|
||||
response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
|
||||
return
|
||||
}
|
||||
if collection.UserId != u.Id {
|
||||
response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
peers := service.AllService.PeerService.List(1, 999, func(tx *gorm.DB) {
|
||||
pl := int64(len(f.PeerIds))
|
||||
peers := service.AllService.PeerService.List(1, uint(pl), func(tx *gorm.DB) {
|
||||
tx.Where("row_id in ?", f.PeerIds)
|
||||
tx.Where("user_id = ?", u.Id)
|
||||
})
|
||||
if peers.Total == 0 {
|
||||
if peers.Total == 0 || pl != peers.Total {
|
||||
response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
|
||||
return
|
||||
}
|
||||
@@ -363,7 +363,8 @@ func (ct *AddressBook) BatchCreateFromPeers(c *gin.Context) {
|
||||
ab := service.AllService.AddressBookService.FromPeer(peer)
|
||||
ab.Tags = tags
|
||||
ab.CollectionId = f.CollectionId
|
||||
ex := service.AllService.AddressBookService.InfoByUserIdAndIdAndCid(u.Id, ab.Id, ab.CollectionId)
|
||||
ab.UserId = f.UserId
|
||||
ex := service.AllService.AddressBookService.InfoByUserIdAndIdAndCid(f.UserId, ab.Id, ab.CollectionId)
|
||||
if ex.RowId != 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
59
http/controller/admin/my/addressBook.go
Normal file
59
http/controller/admin/my/addressBook.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package my
|
||||
|
||||
import (
|
||||
"Gwen/http/request/admin"
|
||||
"Gwen/http/response"
|
||||
"Gwen/service"
|
||||
"encoding/json"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type AddressBook struct{}
|
||||
|
||||
func (ct *AddressBook) BatchCreateFromPeers(c *gin.Context) {
|
||||
f := &admin.BatchCreateFromPeersForm{}
|
||||
if err := c.ShouldBindJSON(f); err != nil {
|
||||
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
|
||||
return
|
||||
}
|
||||
u := service.AllService.UserService.CurUser(c)
|
||||
|
||||
if f.CollectionId != 0 {
|
||||
collection := service.AllService.AddressBookService.CollectionInfoById(f.CollectionId)
|
||||
if collection.Id == 0 {
|
||||
response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
|
||||
return
|
||||
}
|
||||
if collection.UserId != u.Id {
|
||||
response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
|
||||
return
|
||||
}
|
||||
}
|
||||
if len(f.PeerIds) == 0 {
|
||||
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
|
||||
return
|
||||
}
|
||||
pl := int64(len(f.PeerIds))
|
||||
peers := service.AllService.PeerService.List(1, uint(pl), func(tx *gorm.DB) {
|
||||
tx.Where("row_id in ?", f.PeerIds)
|
||||
tx.Where("user_id = ?", u.Id)
|
||||
})
|
||||
if peers.Total == 0 || pl != peers.Total {
|
||||
response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound"))
|
||||
return
|
||||
}
|
||||
|
||||
tags, _ := json.Marshal(f.Tags)
|
||||
for _, peer := range peers.Peers {
|
||||
ab := service.AllService.AddressBookService.FromPeer(peer)
|
||||
ab.Tags = tags
|
||||
ab.CollectionId = f.CollectionId
|
||||
ex := service.AllService.AddressBookService.InfoByUserIdAndIdAndCid(u.Id, ab.Id, ab.CollectionId)
|
||||
if ex.RowId != 0 {
|
||||
continue
|
||||
}
|
||||
service.AllService.AddressBookService.Create(ab)
|
||||
}
|
||||
response.Success(c, nil)
|
||||
}
|
||||
@@ -127,6 +127,7 @@ type BatchCreateFromPeersForm struct {
|
||||
CollectionId uint `json:"collection_id"`
|
||||
PeerIds []uint `json:"peer_ids"`
|
||||
Tags []string `json:"tags"`
|
||||
UserId uint `json:"user_id"`
|
||||
}
|
||||
type BatchUpdateTagsForm struct {
|
||||
RowIds []uint `json:"row_ids"`
|
||||
|
||||
@@ -111,11 +111,12 @@ func AddressBookBind(rg *gin.RouterGroup) {
|
||||
aR.POST("/update", cont.Update)
|
||||
aR.POST("/delete", cont.Delete)
|
||||
aR.POST("/shareByWebClient", cont.ShareByWebClient)
|
||||
aR.POST("/batchCreateFromPeers", cont.BatchCreateFromPeers)
|
||||
|
||||
aR.POST("/batchUpdateTags", cont.BatchUpdateTags)
|
||||
|
||||
arp := aR.Use(middleware.AdminPrivilege())
|
||||
arp.POST("/batchCreate", cont.BatchCreate)
|
||||
arp.POST("/batchCreateFromPeers", cont.BatchCreateFromPeers)
|
||||
|
||||
}
|
||||
}
|
||||
@@ -227,10 +228,13 @@ func FileBind(rg *gin.RouterGroup) {
|
||||
|
||||
func MyBind(rg *gin.RouterGroup) {
|
||||
{
|
||||
sr := &my.ShareRecord{}
|
||||
rg.GET("/my/share_record/list", sr.List)
|
||||
rg.POST("/my/share_record/delete", sr.Delete)
|
||||
rg.POST("/my/share_record/batchDelete", sr.BatchDelete)
|
||||
msr := &my.ShareRecord{}
|
||||
rg.GET("/my/share_record/list", msr.List)
|
||||
rg.POST("/my/share_record/delete", msr.Delete)
|
||||
rg.POST("/my/share_record/batchDelete", msr.BatchDelete)
|
||||
|
||||
mab := &my.AddressBook{}
|
||||
rg.POST("/my/address_book/batchCreateFromPeers", mab.BatchCreateFromPeers)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user