Nashboard/storage/types.go

71 lines
1.4 KiB
Go

package storage
import (
"crypto/rand"
"encoding/hex"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type User struct {
Id primitive.ObjectID `bson:"_id" json:"id,omitempty"`
Username string
Password []byte `json:"-"`
IsAdmin bool
LastLogin time.Time
RootFolderId primitive.ObjectID
}
type Session struct {
Id primitive.ObjectID `bson:"_id" json:"id,omitempty"`
Token string `json:"-"`
UserID primitive.ObjectID
IP string
LoggedAt time.Time
ExpiresAt time.Time
IsAdmin bool
}
type ApiKey struct {
Id primitive.ObjectID `bson:"_id" json:"id,omitempty"`
UserID primitive.ObjectID
Key string
}
type Folder struct {
Id primitive.ObjectID `bson:"_id" json:"id,omitempty"`
Name string
ParentID primitive.ObjectID
UserID primitive.ObjectID
Icon []byte
Created time.Time
}
type Bookmark struct {
Id primitive.ObjectID `bson:"_id" json:"id,omitempty"`
Name string
Url string
UserID primitive.ObjectID
FolderID primitive.ObjectID
Tags []string
Icon []byte
Created time.Time
}
type Note struct {
Id primitive.ObjectID `bson:"_id" json:"id,omitempty"`
Name string
Tags []string
Content string
Created time.Time
}
func GenSessionToken() string {
b := make([]byte, 128)
if _, err := rand.Read(b); err != nil {
return ""
}
return hex.EncodeToString(b)
}