🎉 Initial Commit
This commit is contained in:
19
pkg/models/accounts.go
Normal file
19
pkg/models/accounts.go
Normal file
@ -0,0 +1,19 @@
|
||||
package models
|
||||
|
||||
// Account profiles basically fetched from Hydrogen.Identity
|
||||
// But cache at here for better usage
|
||||
// At the same time this model can make relations between local models
|
||||
type Account struct {
|
||||
BaseModel
|
||||
|
||||
Name string `json:"name"`
|
||||
Nick string `json:"nick"`
|
||||
Avatar string `json:"avatar"`
|
||||
Banner string `json:"banner"`
|
||||
Description string `json:"description"`
|
||||
EmailAddress string `json:"email_address"`
|
||||
PowerLevel int `json:"power_level"`
|
||||
Attachments []Attachment `json:"attachments" gorm:"foreignKey:AuthorID"`
|
||||
Channels []Channel `json:"channels"`
|
||||
ExternalID uint `json:"external_id"`
|
||||
}
|
43
pkg/models/attachments.go
Normal file
43
pkg/models/attachments.go
Normal file
@ -0,0 +1,43 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type AttachmentType = uint8
|
||||
|
||||
const (
|
||||
AttachmentOthers = AttachmentType(iota)
|
||||
AttachmentPhoto
|
||||
AttachmentVideo
|
||||
AttachmentAudio
|
||||
)
|
||||
|
||||
type Attachment struct {
|
||||
BaseModel
|
||||
|
||||
FileID string `json:"file_id"`
|
||||
Filesize int64 `json:"filesize"`
|
||||
Filename string `json:"filename"`
|
||||
Mimetype string `json:"mimetype"`
|
||||
Hashcode string `json:"hashcode"`
|
||||
Type AttachmentType `json:"type"`
|
||||
ExternalUrl string `json:"external_url"`
|
||||
Author Account `json:"author"`
|
||||
ArticleID *uint `json:"article_id"`
|
||||
MomentID *uint `json:"moment_id"`
|
||||
CommentID *uint `json:"comment_id"`
|
||||
AuthorID uint `json:"author_id"`
|
||||
}
|
||||
|
||||
func (v Attachment) GetStoragePath() string {
|
||||
basepath := viper.GetString("content")
|
||||
return filepath.Join(basepath, v.FileID)
|
||||
}
|
||||
|
||||
func (v Attachment) GetAccessPath() string {
|
||||
return fmt.Sprintf("/api/attachments/o/%s", v.FileID)
|
||||
}
|
17
pkg/models/base.go
Normal file
17
pkg/models/base.go
Normal file
@ -0,0 +1,17 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/datatypes"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type JSONMap = datatypes.JSONType[map[string]any]
|
||||
|
||||
type BaseModel struct {
|
||||
ID uint `json:"id" gorm:"primaryKey"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
|
||||
}
|
19
pkg/models/channels.go
Normal file
19
pkg/models/channels.go
Normal file
@ -0,0 +1,19 @@
|
||||
package models
|
||||
|
||||
type Channel struct {
|
||||
BaseModel
|
||||
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Members []ChannelMember `json:"members"`
|
||||
AccountID uint `json:"account_id"`
|
||||
}
|
||||
|
||||
type ChannelMember struct {
|
||||
BaseModel
|
||||
|
||||
ChannelID uint `json:"channel_id"`
|
||||
AccountID uint `json:"account_id"`
|
||||
Channel Channel `json:"channel"`
|
||||
Account Account `json:"account"`
|
||||
}
|
Reference in New Issue
Block a user