Nashboard/storage/types.go

68 lines
1.3 KiB
Go
Raw Normal View History

2022-12-11 02:05:03 +03:00
package storage
2022-12-09 00:58:18 +03:00
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
}
type Session struct {
Id primitive.ObjectID `bson:"_id" json:"id,omitempty"`
2022-12-11 02:05:03 +03:00
Token string `json:"-"`
2022-12-09 00:58:18 +03:00
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 {
2022-12-11 02:05:03 +03:00
Id primitive.ObjectID `bson:"_id" json:"id,omitempty"`
Name string
ParentID primitive.ObjectID
Icon []byte
2022-12-09 00:58:18 +03:00
}
type Bookmark struct {
Id primitive.ObjectID `bson:"_id" json:"id,omitempty"`
Name string
Url string
2022-12-11 02:05:03 +03:00
UserID primitive.ObjectID
2022-12-09 00:58:18 +03:00
FolderID primitive.ObjectID
2022-12-11 02:05:03 +03:00
Tags []string
// Icon []byte
Created time.Time
2022-12-09 00:58:18 +03:00
}
type Note struct {
Id primitive.ObjectID `bson:"_id" json:"id,omitempty"`
Name string
2022-12-11 02:05:03 +03:00
Tags []string
2022-12-09 00:58:18 +03:00
Content string
2022-12-11 02:05:03 +03:00
Created time.Time
2022-12-09 00:58:18 +03:00
}
func GenSessionToken() string {
b := make([]byte, 128)
if _, err := rand.Read(b); err != nil {
return ""
}
return hex.EncodeToString(b)
}