mirror of
https://github.com/lejianwen/rustdesk-api.git
synced 2026-02-22 12:21:29 +00:00
first
This commit is contained in:
44
model/addressBook.go
Normal file
44
model/addressBook.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package model
|
||||
|
||||
import "Gwen/model/custom_types"
|
||||
|
||||
// final String id;
|
||||
// String hash; // personal ab hash password
|
||||
// String password; // shared ab password
|
||||
// String username; // pc username
|
||||
// String hostname;
|
||||
// String platform;
|
||||
// String alias;
|
||||
// List<dynamic> tags;
|
||||
// bool forceAlwaysRelay = false;
|
||||
// String rdpPort;
|
||||
// String rdpUsername;
|
||||
// bool online = false;
|
||||
// String loginName; //login username
|
||||
// bool? sameServer;
|
||||
|
||||
// AddressBook 有些字段是Personal才会上传的
|
||||
type AddressBook struct {
|
||||
RowId uint `gorm:"primaryKey" json:"row_id"`
|
||||
Id string `json:"id" gorm:"default:0;not null;index"`
|
||||
Username string `json:"username" gorm:"default:'';not null;"`
|
||||
Password string `json:"password" gorm:"default:'';not null;"`
|
||||
Hostname string `json:"hostname" gorm:"default:'';not null;"`
|
||||
Alias string `json:"alias" gorm:"default:'';not null;"`
|
||||
Platform string `json:"platform" gorm:"default:'';not null;"`
|
||||
Tags custom_types.AutoJson `json:"tags" gorm:"not null;" swaggertype:"array,string"`
|
||||
Hash string `json:"hash" gorm:"default:'';not null;"`
|
||||
UserId uint `json:"user_id" gorm:"default:0;not null;index"`
|
||||
ForceAlwaysRelay bool `json:"forceAlwaysRelay" gorm:"default:0;not null;"`
|
||||
RdpPort string `json:"rdpPort" gorm:"default:'';not null;"`
|
||||
RdpUsername string `json:"rdpUsername" gorm:"default:'';not null;"`
|
||||
Online bool `json:"online" gorm:"default:0;not null;"`
|
||||
LoginName string `json:"loginName" gorm:"default:'';not null;"`
|
||||
SameServer bool `json:"sameServer" gorm:"default:0;not null;"`
|
||||
TimeModel
|
||||
}
|
||||
|
||||
type AddressBookList struct {
|
||||
AddressBooks []*AddressBook `json:"list"`
|
||||
Pagination
|
||||
}
|
||||
66
model/custom_types/auto_json.go
Normal file
66
model/custom_types/auto_json.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package custom_types
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// AutoJson 数据类型
|
||||
type AutoJson json.RawMessage
|
||||
|
||||
func (j *AutoJson) Scan(value interface{}) error {
|
||||
|
||||
var strValue string
|
||||
switch v := value.(type) {
|
||||
case []byte:
|
||||
strValue = string(v)
|
||||
case string:
|
||||
strValue = v
|
||||
default:
|
||||
return errors.New(fmt.Sprintf("Failed Scan AutoJson value: %v", value))
|
||||
}
|
||||
bytes := []byte(strValue)
|
||||
//bytes, ok := value.([]byte)
|
||||
//if !ok {
|
||||
// return errors.New(fmt.Sprint("Failed Scan AutoJson value:", value))
|
||||
//}
|
||||
|
||||
if bytes == nil || len(bytes) == 0 {
|
||||
*j = AutoJson(json.RawMessage{'[', ']'})
|
||||
return nil
|
||||
}
|
||||
result := &json.RawMessage{}
|
||||
err := json.Unmarshal(bytes, result)
|
||||
//解析json错误 返回空
|
||||
if err != nil {
|
||||
*j = AutoJson(json.RawMessage{'[', ']'})
|
||||
return nil
|
||||
}
|
||||
*j = AutoJson(*result)
|
||||
return err
|
||||
}
|
||||
func (j AutoJson) Value() (driver.Value, error) {
|
||||
bytes, err := json.RawMessage(j).MarshalJSON()
|
||||
return string(bytes), err
|
||||
}
|
||||
func (j AutoJson) MarshalJSON() ([]byte, error) {
|
||||
b, err := json.RawMessage(j).MarshalJSON()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b, err
|
||||
}
|
||||
|
||||
func (j *AutoJson) UnmarshalJSON(b []byte) error {
|
||||
result := json.RawMessage{}
|
||||
err := result.UnmarshalJSON(b)
|
||||
*j = AutoJson(result)
|
||||
return err
|
||||
}
|
||||
|
||||
func (j AutoJson) String() string {
|
||||
s, _ := j.MarshalJSON()
|
||||
return (string)(s)
|
||||
}
|
||||
24
model/custom_types/auto_time.go
Normal file
24
model/custom_types/auto_time.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package custom_types
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"time"
|
||||
)
|
||||
|
||||
// AutoTime 自定义时间格式
|
||||
type AutoTime time.Time
|
||||
|
||||
func (mt AutoTime) Value() (driver.Value, error) {
|
||||
var zeroTime time.Time
|
||||
t := time.Time(mt)
|
||||
if t.UnixNano() == zeroTime.UnixNano() {
|
||||
return nil, nil
|
||||
}
|
||||
return t, nil
|
||||
}
|
||||
|
||||
func (mt AutoTime) MarshalJSON() ([]byte, error) {
|
||||
//b := make([]byte, 0, len("2006-01-02 15:04:05")+2)
|
||||
b := time.Time(mt).AppendFormat([]byte{}, "\"2006-01-02 15:04:05\"")
|
||||
return b, nil
|
||||
}
|
||||
18
model/group.go
Normal file
18
model/group.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package model
|
||||
|
||||
const (
|
||||
GroupTypeDefault = 1 // 默认
|
||||
GroupTypeShare = 2 // 共享
|
||||
)
|
||||
|
||||
type Group struct {
|
||||
IdModel
|
||||
Name string `json:"name" gorm:"default:'';not null;"`
|
||||
Type int `json:"type" gorm:"default:1;not null;"`
|
||||
TimeModel
|
||||
}
|
||||
|
||||
type GroupList struct {
|
||||
Groups []*Group `json:"list"`
|
||||
Pagination
|
||||
}
|
||||
27
model/model.go
Normal file
27
model/model.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"Gwen/model/custom_types"
|
||||
)
|
||||
|
||||
type StatusCode int
|
||||
|
||||
const (
|
||||
COMMON_STATUS_ENABLE StatusCode = 1 //通用状态 启用
|
||||
COMMON_STATUS_DISABLED StatusCode = 2 //通用状态 禁用
|
||||
)
|
||||
|
||||
type IdModel struct {
|
||||
Id uint `gorm:"primaryKey" json:"id"`
|
||||
}
|
||||
type TimeModel struct {
|
||||
CreatedAt custom_types.AutoTime `json:"created_at" gorm:"type:timestamp;"`
|
||||
UpdatedAt custom_types.AutoTime `json:"updated_at" gorm:"type:timestamp;"`
|
||||
}
|
||||
|
||||
// Pagination
|
||||
type Pagination struct {
|
||||
Page int64 `form:"page" json:"page"`
|
||||
Total int64 `form:"total" json:"total"`
|
||||
PageSize int64 `form:"page_size" json:"page_size"`
|
||||
}
|
||||
21
model/peer.go
Normal file
21
model/peer.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package model
|
||||
|
||||
type Peer struct {
|
||||
RowId uint `json:"row_id" gorm:"primaryKey;"`
|
||||
Id string `json:"id" gorm:"default:'';not null;index"`
|
||||
Cpu string `json:"cpu" gorm:"default:'';not null;"`
|
||||
Hostname string `json:"hostname" gorm:"default:'';not null;"`
|
||||
Memory string `json:"memory" gorm:"default:'';not null;"`
|
||||
Os string `json:"os" gorm:"default:'';not null;"`
|
||||
Username string `json:"username" gorm:"default:'';not null;"`
|
||||
Uuid string `json:"uuid" gorm:"default:'';not null;index"`
|
||||
Version string `json:"version" gorm:"default:'';not null;"`
|
||||
UserId uint `json:"user_id" gorm:"default:0;not null;index"`
|
||||
User User `json:"user,omitempty" gorm:""`
|
||||
TimeModel
|
||||
}
|
||||
|
||||
type PeerList struct {
|
||||
Peers []*Peer `json:"list"`
|
||||
Pagination
|
||||
}
|
||||
14
model/tag.go
Normal file
14
model/tag.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package model
|
||||
|
||||
type Tag struct {
|
||||
IdModel
|
||||
Name string `json:"name" gorm:"default:'';not null;"`
|
||||
UserId uint `json:"user_id" gorm:"default:0;not null;index"`
|
||||
Color uint `json:"color" gorm:"default:0;not null;"` //color 是flutter的颜色值,从0x00000000 到 0xFFFFFFFF; 前两位表示透明度,后面6位表示颜色, 可以转成rgba
|
||||
TimeModel
|
||||
}
|
||||
|
||||
type TagList struct {
|
||||
Tags []*Tag `json:"list"`
|
||||
Pagination
|
||||
}
|
||||
18
model/user.go
Normal file
18
model/user.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package model
|
||||
|
||||
type User struct {
|
||||
IdModel
|
||||
Username string `json:"username" gorm:"default:'';not null;index,unique"`
|
||||
Password string `json:"-" gorm:"default:'';not null;"`
|
||||
Nickname string `json:"nickname" gorm:"default:'';not null;"`
|
||||
Avatar string `json:"avatar" gorm:"default:'';not null;"`
|
||||
GroupId uint `json:"group_id" gorm:"default:0;not null;index"`
|
||||
IsAdmin *bool `json:"is_admin" gorm:"default:0;not null;"`
|
||||
Status StatusCode `json:"status" gorm:"default:1;not null;"`
|
||||
TimeModel
|
||||
}
|
||||
|
||||
type UserList struct {
|
||||
Users []*User `json:"list,omitempty"`
|
||||
Pagination
|
||||
}
|
||||
9
model/userToken.go
Normal file
9
model/userToken.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package model
|
||||
|
||||
type UserToken struct {
|
||||
IdModel
|
||||
UserId uint `json:"user_id" gorm:"default:0;not null;index"`
|
||||
Token string `json:"token" gorm:"default:'';not null;index"`
|
||||
ExpiredAt int64 `json:"expired_at" gorm:"default:0;not null;"`
|
||||
TimeModel
|
||||
}
|
||||
7
model/version.go
Normal file
7
model/version.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package model
|
||||
|
||||
type Version struct {
|
||||
IdModel
|
||||
Version uint `json:"version" gorm:"default:0;not null;"`
|
||||
TimeModel
|
||||
}
|
||||
Reference in New Issue
Block a user