mirror of
https://github.com/lejianwen/rustdesk-api.git
synced 2026-02-08 07:10:43 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb340b2615 | ||
|
|
e714549a95 | ||
|
|
a1367bcd3d | ||
|
|
642351dafd |
@@ -101,7 +101,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func DatabaseAutoUpdate() {
|
func DatabaseAutoUpdate() {
|
||||||
version := 240
|
version := 241
|
||||||
|
|
||||||
db := global.DB
|
db := global.DB
|
||||||
|
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ func (ct *AddressBook) Update(c *gin.Context) {
|
|||||||
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
|
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err := service.AllService.AddressBookService.Update(t)
|
err := service.AllService.AddressBookService.UpdateAll(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
response.Fail(c, 101, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -207,3 +207,21 @@ func (ct *Peer) BatchDelete(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
response.Success(c, nil)
|
response.Success(c, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ct *Peer) SimpleData(c *gin.Context) {
|
||||||
|
f := &admin.SimpleDataQuery{}
|
||||||
|
if err := c.ShouldBindJSON(f); err != nil {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(f.Ids) == 0 {
|
||||||
|
response.Fail(c, 101, response.TranslateMsg(c, "ParamsError"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
res := service.AllService.PeerService.List(1, 99999, func(tx *gorm.DB) {
|
||||||
|
//可以公开的情报
|
||||||
|
tx.Select("id,version")
|
||||||
|
tx.Where("id in (?)", f.Ids)
|
||||||
|
})
|
||||||
|
response.Success(c, res)
|
||||||
|
}
|
||||||
|
|||||||
@@ -689,9 +689,9 @@ func (a *Ab) PeerDel(c *gin.Context) {
|
|||||||
// @Router /ab/peer/update/{guid} [put]
|
// @Router /ab/peer/update/{guid} [put]
|
||||||
// @Security BearerAuth
|
// @Security BearerAuth
|
||||||
func (a *Ab) PeerUpdate(c *gin.Context) {
|
func (a *Ab) PeerUpdate(c *gin.Context) {
|
||||||
//f := &gin.H{}
|
f := gin.H{}
|
||||||
f := &requstform.PersonalAddressBookForm{}
|
//f := &requstform.PersonalAddressBookForm{}
|
||||||
err := c.ShouldBindJSON(f)
|
err := c.ShouldBindJSON(&f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.Error(c, response.TranslateMsg(c, "ParamsError")+err.Error())
|
response.Error(c, response.TranslateMsg(c, "ParamsError")+err.Error())
|
||||||
return
|
return
|
||||||
@@ -709,17 +709,33 @@ func (a *Ab) PeerUpdate(c *gin.Context) {
|
|||||||
response.Error(c, response.TranslateMsg(c, "NoAccess"))
|
response.Error(c, response.TranslateMsg(c, "NoAccess"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//fmt.Println(f)
|
//fmt.Println(f)
|
||||||
//return
|
//判断f["Id"]是否存在
|
||||||
ab := service.AllService.AddressBookService.InfoByUserIdAndIdAndCid(uid, f.Id, cid)
|
fid, ok := f["id"]
|
||||||
|
if !ok {
|
||||||
|
response.Error(c, response.TranslateMsg(c, "ParamsError"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fidstr := fid.(string)
|
||||||
|
|
||||||
|
ab := service.AllService.AddressBookService.InfoByUserIdAndIdAndCid(uid, fidstr, cid)
|
||||||
if ab == nil || ab.RowId == 0 {
|
if ab == nil || ab.RowId == 0 {
|
||||||
response.Error(c, response.TranslateMsg(c, "ItemNotFound"))
|
response.Error(c, response.TranslateMsg(c, "ItemNotFound"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
nab := f.ToAddressBook()
|
//允许的字段
|
||||||
nab.RowId = ab.RowId
|
allowUp := []string{"password", "hash", "tags", "alias"}
|
||||||
err = service.AllService.AddressBookService.Update(nab)
|
//f中的字段如果不在allowUp中,就删除
|
||||||
|
for k := range f {
|
||||||
|
if !utils.InArray(k, allowUp) {
|
||||||
|
delete(f, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//fmt.Println(f)
|
||||||
|
if tags, _ok := f["tags"]; _ok {
|
||||||
|
f["tags"], _ = json.Marshal(tags)
|
||||||
|
}
|
||||||
|
err = service.AllService.AddressBookService.UpdateByMap(ab, f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.Error(c, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
response.Error(c, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -54,10 +54,9 @@ func (i *Index) Heartbeat(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, gin.H{})
|
c.JSON(http.StatusOK, gin.H{})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//如果在一分钟以内则不更新
|
//如果在40s以内则不更新
|
||||||
if time.Now().Unix()-peer.LastOnlineTime > 60 {
|
if time.Now().Unix()-peer.LastOnlineTime > 40 {
|
||||||
peer.LastOnlineTime = time.Now().Unix()
|
upp := &model.Peer{RowId: peer.RowId, LastOnlineTime: time.Now().Unix(), LastOnlineIp: c.ClientIP()}
|
||||||
upp := &model.Peer{RowId: peer.RowId, LastOnlineTime: peer.LastOnlineTime}
|
|
||||||
service.AllService.PeerService.Update(upp)
|
service.AllService.PeerService.Update(upp)
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, gin.H{})
|
c.JSON(http.StatusOK, gin.H{})
|
||||||
|
|||||||
@@ -39,3 +39,7 @@ type PeerQuery struct {
|
|||||||
Id string `json:"id" form:"id"`
|
Id string `json:"id" form:"id"`
|
||||||
Hostname string `json:"hostname" form:"hostname"`
|
Hostname string `json:"hostname" form:"hostname"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SimpleDataQuery struct {
|
||||||
|
Ids []string `json:"ids" form:"ids"`
|
||||||
|
}
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ func PeerBind(rg *gin.RouterGroup) {
|
|||||||
aR.POST("/create", cont.Create)
|
aR.POST("/create", cont.Create)
|
||||||
aR.POST("/update", cont.Update)
|
aR.POST("/update", cont.Update)
|
||||||
aR.POST("/delete", cont.Delete)
|
aR.POST("/delete", cont.Delete)
|
||||||
|
aR.POST("/simpleData", cont.SimpleData)
|
||||||
|
|
||||||
arp := aR.Use(middleware.AdminPrivilege())
|
arp := aR.Use(middleware.AdminPrivilege())
|
||||||
arp.POST("/batchDelete", cont.BatchDelete)
|
arp.POST("/batchDelete", cont.BatchDelete)
|
||||||
|
|||||||
@@ -11,8 +11,9 @@ type Peer struct {
|
|||||||
Uuid string `json:"uuid" gorm:"default:'';not null;index"`
|
Uuid string `json:"uuid" gorm:"default:'';not null;index"`
|
||||||
Version string `json:"version" gorm:"default:'';not null;"`
|
Version string `json:"version" gorm:"default:'';not null;"`
|
||||||
UserId uint `json:"user_id" gorm:"default:0;not null;index"`
|
UserId uint `json:"user_id" gorm:"default:0;not null;index"`
|
||||||
User User `json:"user,omitempty" gorm:""`
|
User *User `json:"user,omitempty"`
|
||||||
LastOnlineTime int64 `json:"last_online_time" gorm:"default:0;not null;"`
|
LastOnlineTime int64 `json:"last_online_time" gorm:"default:0;not null;"`
|
||||||
|
LastOnlineIp string `json:"last_online_ip" gorm:"default:'';not null;"`
|
||||||
TimeModel
|
TimeModel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -127,6 +127,16 @@ func (s *AddressBookService) Delete(u *model.AddressBook) error {
|
|||||||
|
|
||||||
// Update 更新
|
// Update 更新
|
||||||
func (s *AddressBookService) Update(u *model.AddressBook) error {
|
func (s *AddressBookService) Update(u *model.AddressBook) error {
|
||||||
|
return global.DB.Model(u).Updates(u).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateByMap 更新
|
||||||
|
func (s *AddressBookService) UpdateByMap(u *model.AddressBook, data map[string]interface{}) error {
|
||||||
|
return global.DB.Model(u).Updates(data).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateAll 更新
|
||||||
|
func (s *AddressBookService) UpdateAll(u *model.AddressBook) error {
|
||||||
return global.DB.Model(u).Select("*").Omit("created_at").Updates(u).Error
|
return global.DB.Model(u).Select("*").Omit("created_at").Updates(u).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,3 +91,12 @@ func Values[K comparable, V any](m map[K]V) []V {
|
|||||||
}
|
}
|
||||||
return values
|
return values
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func InArray(k string, arr []string) bool {
|
||||||
|
for _, v := range arr {
|
||||||
|
if k == v {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user