data

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exists

func Exists[T any](conds ...any) bool

func GetBranches

func GetBranches(platform, mid string, r *[]Post)

获取分支

func GetPosts

func GetPosts(begin, end string, r *[]Post)

通过起始与结束时间获取范围内博文合集

func HasPost

func HasPost(platform, mid string) bool

判断博文是否存在

func ParseStruct

func ParseStruct(in any) []string

func Preload

func Preload[T any](t *T, conds ...any) error

func PreloadDB

func PreloadDB(in any) (r *gorm.DB)

func Preloads

func Preloads[T any](t *[]T, conds ...any) error

func Public

func Public() resource.Explorer

func Save

func Save(url string) string

func SavePost

func SavePost(p *Post)

func SavePosts

func SavePosts(p ...*Post)

func SetDB

func SetDB(r *gorm.DB) *gorm.DB

func SetDialector

func SetDialector(dialector gorm.Dialector) *gorm.DB

func SetPublic

func SetPublic(name string, r resource.Explorer)

func SetSqlite

func SetSqlite(file string) *gorm.DB

func Update

func Update(x any, conds ...any) bool

Types

type Attachment

type Attachment struct {
	Model
	// 原网址
	Url string `form:"url" gorm:"unique" cmps:"1"`
	// 本地路径
	Local string
	// 同浏览器 MIME type 附件的媒体类型
	MIME string
}

附件

func (*Attachment) BeforeCreate

func (a *Attachment) BeforeCreate(tx *gorm.DB) error

func (*Attachment) Download

func (a *Attachment) Download() error

下载附件

func (*Attachment) Downloaded

func (a *Attachment) Downloaded() bool

func (Attachment) MarshalJSON

func (a Attachment) MarshalJSON() ([]byte, error)

func (*Attachment) Path

func (a *Attachment) Path() string

func (*Attachment) Saved

func (a *Attachment) Saved() bool

func (*Attachment) Store

func (a *Attachment) Store(data []byte)

func (Attachment) String

func (a Attachment) String() string

type Attachments

type Attachments []Attachment

附件合集

func (*Attachments) Add

func (as *Attachments) Add(urls ...string)

func (Attachments) String

func (as Attachments) String() string

func (Attachments) Urls

func (as Attachments) Urls() string

type Blogger

type Blogger struct {
	Model
	Platform    string `form:"platform" json:"platform"`
	Uid         string `form:"uid" json:"uid" cmps:"1"`
	Create      string `form:"create" json:"create"`
	Name        string `form:"name" json:"name"`
	Description string `form:"description" json:"description"`
	Follower    string `form:"follower" json:"follower"`
	Following   string `form:"following" json:"following"`

	FaceID int64      `gorm:"column:face" json:"-"`
	Face   Attachment `form:"face" json:"face" preload:"1"`

	PendantID int64      `gorm:"column:pendant" json:"-"`
	Pendant   Attachment `form:"pendant" json:"pendant" preload:"2"`
}

博主信息部分

func (*Blogger) BeforeCreate

func (b *Blogger) BeforeCreate(tx *gorm.DB) error

func (*Blogger) Query

func (b *Blogger) Query(now time.Time) *Blogger

查询某一时刻前最近的用户状态

func (*Blogger) Saved

func (b *Blogger) Saved() bool

func (Blogger) String

func (b Blogger) String() string

type Model

type Model struct {
	ID uint64 `gorm:"primaryKey;autoIncrement" form:"-" json:"-"`
}

type Monitor

type Monitor struct {
	Score float64
	Posts []*Post
}

博文检查器

func GetMonitor

func GetMonitor(typ string) *Monitor

获取检查器

func (*Monitor) IsSubmitted

func (m *Monitor) IsSubmitted(uid string) bool

判断用户是否已经提交

func (*Monitor) Parse

func (m *Monitor) Parse(post *Post)

解析接收到的博文

type Post

type Post struct {
	Model
	// 平台
	Platform string `form:"platform" json:"platform"`
	// 博文序号
	Mid string `form:"mid" json:"mid"`
	// 发送时间
	Time string `form:"time" json:"time"`
	// 文本
	Text string `form:"text" json:"text"`
	// 内容
	Content string `gorm:"-" form:"-" json:"-"`
	// 来源
	Source string `form:"source" json:"source"`
	// 博主
	BloggerID string  `form:"-" json:"-" gorm:"column:blogger"`
	Blogger   Blogger `form:"blogger" json:"blogger" preload:""`
	// 回复
	RepostID *uint64 `form:"-" json:"-" gorm:"column:repost"`
	Repost   *Post   `form:"repost" json:"repost"`
	// 评论
	CommentID *uint64 `form:"-" json:"-" gorm:"column:comment"`
	Comments  []Post  `form:"comments" json:"comments" gorm:"foreignKey:CommentID"`
	// 附件
	Attachments Attachments `form:"attachments" json:"attachments" gorm:"many2many:post_attachments;"`
	// 提交者
	Submitter *user.User `form:"-" json:"submitter"`
	// 编辑距离
	Distance int `gorm:"-" form:"-" json:"-" cmps:"1"`
	// 替换器
	Replacer *strings.Replacer `gorm:"-" form:"-" json:"-"`
}

博文或评论

func GetPost

func GetPost(platform, mid string) *Post

通过平台和序号获取唯一博文

func (*Post) BeforeCreate

func (p *Post) BeforeCreate(tx *gorm.DB) error

func (*Post) ReplaceData

func (p *Post) ReplaceData(text string) string

替换通配符

func (Post) String

func (p Post) String() string

func (*Post) Type

func (p *Post) Type() string

func (*Post) Webhook

func (p *Post) Webhook()

回调博文

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL