model

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSubmitter = errors.New("model: post has no submitter")
View Source
var ErrSubmitted = errors.New("您已提交过")
View Source
var ErrType = errors.New("model: failed to unmarshal JSONB value")
View Source
var TestJob = &Job{
	Filter: Filter{
		Platform: "weibo",
		Uid:      "\\d+",
	},
	Job: request.Job{
		Method: http.MethodGet,
		Url:    "http://api.nana7mi.link:5760/weibo",
		Query: request.M{
			"channel": "9673211",
			"message": `{{.Name}}
粉丝 {{.Follower}} | 关注 {{.Following}}

“{{.Content}}”
{{if .Repost}}
  {{.Repost.Name}}
  粉丝 {{.Repost.Follower}} | 关注 {{.Repost.Following}}
  
  “{{.Repost.Content}}”

  {{.Repost.Time.Format "%m-%d %H:%M:%S"}}
  来自{{.Repost.Source}}
{{end}}
{{.Time.Format "%m-%d %H:%M:%S"}}
来自{{.Source}}`,
		},
	},
}
View Source
var TestPost = &Post{
	Platform:    "weibo",
	Uid:         "7198559139",
	Name:        "七海Nana7mi",
	Avatar:      "https://wx4.sinaimg.cn/orj480/007Raq4zly8hd1vqpx3coj30u00u00uv.jpg",
	Follower:    "104.8万",
	Following:   "192",
	Description: "蓝色饭团",
	Mid:         "4952487292307646",
	Time:        1696248446000,
	Text:        `<span class="url-icon"><img alt=[good] src="https://h5.sinaimg.cn/m/emoticon/icon/others/h_good-0c51afc69c.png" style="width:1em; height:1em;" /></span><span class="url-icon"><img alt=[good] src="https://h5.sinaimg.cn/m/emoticon/icon/others/h_good-0c51afc69c.png" style="width:1em; height:1em;" /></span><span class="url-icon"><img alt=[good] src="https://h5.sinaimg.cn/m/emoticon/icon/others/h_good-0c51afc69c.png" style="width:1em; height:1em;" /></span><span class="url-icon"><img alt=[good] src="https://h5.sinaimg.cn/m/emoticon/icon/others/h_good-0c51afc69c.png" style="width:1em; height:1em;" /></span><span class="url-icon"><img alt=[赞] src="https://h5.sinaimg.cn/m/emoticon/icon/others/h_zan-44ddc70637.png" style="width:1em; height:1em;" /></span><span class="url-icon"><img alt=[赞] src="https://h5.sinaimg.cn/m/emoticon/icon/others/h_zan-44ddc70637.png" style="width:1em; height:1em;" /></span><span class="url-icon"><img alt=[赞] src="https://h5.sinaimg.cn/m/emoticon/icon/others/h_zan-44ddc70637.png" style="width:1em; height:1em;" /></span><span class="url-icon"><img alt=[赞] src="https://h5.sinaimg.cn/m/emoticon/icon/others/h_zan-44ddc70637.png" style="width:1em; height:1em;" /></span>`,
	Source:      "🦈iPhone 14 Pro Max",
	Submitter:   &User{Uid: "188888131", Permission: Owner},
	Repost: &Post{
		Platform:    "weibo",
		Uid:         "2203177060",
		Name:        "阿梓从小就很可爱",
		Avatar:      "https://wx4.sinaimg.cn/orj480/8351d064ly8hiph621dryj20u00u00vw.jpg",
		Follower:    "61.9万",
		Following:   "306",
		Description: "本人只喜欢读书",
		Mid:         "4952449691946355",
		Time:        1696239481000,
		Text:        "[看书] ",
		Source:      "iPhone 13 Pro Max",
		Attachments: pq.StringArray{"https://wx2.sinaimg.cn/large/8351d064ly1hih23pb486j21tk19k7wk.jpg"},
		Submitter:   &User{Uid: "188888131"},
		Repost:      &Post{},
	},
}

测试博文

Functions

func MatchRegexp

func MatchRegexp(pattern, text string) bool

Types

type Filter

type Filter struct {
	// Specific users and platforms
	Uid      string `form:"uid"         json:"uid"         yaml:"uid"`
	Platform string `form:"platform"    json:"platform"    yaml:"platform"`
	// Accept posts from all sources
	AllSources bool `form:"all_sources" json:"all_sources" yaml:"all_sources"`
}

func (Filter) Match

func (f Filter) Match(p *Post) bool

type Job

type Job struct {
	gorms.Model[uint64]
	// 过滤器
	Filter
	// 任务参数
	request.Job
	// 所有者
	UserUid string `json:"-"`
	// 软删除
	Deleted gorm.DeletedAt `json:"-"`
}

任务

func (*Job) Execute

func (job *Job) Execute(p *Post) error

func (*Job) Send

func (job *Job) Send(p *Post) *request.Response

func (*Job) Template

func (job *Job) Template() (*template.Template, error)

type Permission

type Permission uint64

权限

const (
	Owner Permission = 1 << iota
	Administrator
	Trustor
)

func (Permission) Has

func (p Permission) Has(permissions ...Permission) bool

func (Permission) Is

func (p Permission) Is(permissions ...Permission) bool

func (Permission) IsAdmin

func (p Permission) IsAdmin() bool

func (Permission) IsOwner

func (p Permission) IsOwner() bool

func (Permission) IsTrusted

func (p Permission) IsTrusted() bool

func (Permission) String

func (p Permission) String() string

type Post

type Post struct {
	gorms.Model[uint64] `form:"-" json:"-"`
	// 平台
	Platform string `form:"platform" json:"platform"`
	// 平台序号
	Uid string `form:"uid" json:"uid" cmps:"1"`
	// 昵称
	Name string `form:"name" json:"name"`
	// 粉丝数
	Follower string `form:"follower" json:"follower"`
	// 关注数
	Following string `form:"following" json:"following"`
	// 简介
	Description string `form:"description" json:"description"`
	// 头像
	Avatar string `form:"avatar" json:"avatar"`
	// 装扮
	Pendant string `form:"pendant" json:"pendant"`
	// 头图
	Banner string `form:"banner" json:"banner"`
	// 博文序号
	Mid string `form:"mid" json:"mid"`
	// 发送时间
	Time intime.Time `form:"time" json:"time"`
	// 文本
	Text string `form:"text" json:"text"`
	// 来源
	Source string `form:"source" json:"source"`
	// 附件
	Attachments pq.StringArray `gorm:"type:text[]" form:"attachments" json:"attachments"`
	// 标签
	Tags []Tag
	// 提交者
	Submitter *User `form:"-" json:"submitter"`
	// 回复
	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"`
}

博文

func (*Post) BeforeCreate

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

func (*Post) Content

func (p *Post) Content() string

func (*Post) ScanAndSend

func (p *Post) ScanAndSend(rows *sql.Rows)

func (*Post) String

func (p *Post) String() string

type Tag

type Tag struct {
	gorm.Model
	Key     string
	Value   string
	Comment string
	PostID  uint64
}

type User

type User struct {
	Permission `json:"permission"`
	// 哔哩哔哩 uid
	Uid string `json:"uid" gorm:"primaryKey"`
	// 鉴权码
	Auth string `json:"auth,omitempty"`
	// 账户下任务
	Jobs []Job `json:"jobs,omitempty" gorm:"foreignKey:UserUid"`
	// 关注的账号
	Follow pq.StringArray `gorm:"type:text[]" json:"follow,omitempty"`
}

提交者

func (*User) Scan

func (u *User) Scan(val any) error

func (User) String

func (u User) String() string

func (*User) Value

func (u *User) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

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