model

package
v0.19.2 Latest Latest
Warning

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

Go to latest
Published: May 15, 2025 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const MagicKey string = "_magic_key_"

Variables

View Source
var MaxTextLength = 18

Functions

This section is empty.

Types

type Blog

type Blog struct {
	ID        uint64    `json:"id" gorm:"primaryKey;autoIncrement"` // 数据库内序号
	CreatedAt time.Time `json:"created_at"`                         // 数据库内创建时间

	Submitter string `json:"submitter" gorm:"index:idx_blogs_query,priority:2"`      // 提交者
	Platform  string `json:"platform" gorm:"index:idx_blogs_query,priority:5"`       // 发布平台
	Type      string `json:"type" gorm:"index:idx_blogs_query,priority:4"`           // 博文类型
	UID       string `json:"uid" gorm:"index:idx_blogs_query,priority:3"`            // 账户序号
	MID       string `json:"mid" gorm:"index:idx_blogs_query,priority:1;column:mid"` // 博文序号

	URL    string    `json:"url"`    // 博文网址
	Text   string    `json:"text"`   // 文本内容
	Time   time.Time `json:"time"`   // 发送时间
	Title  string    `json:"title"`  // 博文标题
	Source string    `json:"source"` // 博文来源
	Edited bool      `json:"edited"` // 是否编辑

	Name        string `json:"name"`        // 账户昵称
	Avatar      string `json:"avatar"`      // 头像网址
	Follower    string `json:"follower"`    // 粉丝数量
	Following   string `json:"following"`   // 关注数量
	Description string `json:"description"` // 个人简介

	ReplyID   *uint64 `json:"reply_id"`                             // 被本文回复的博文序号
	Reply     *Blog   `json:"reply"`                                // 被本文回复的博文
	CommentID *uint64 `json:"comment_id"`                           // 被本文评论的博文序号
	Comments  []Blog  `json:"comments" gorm:"foreignKey:CommentID"` // 本文的评论

	Assets pq.StringArray `json:"assets" gorm:"type:text[]"`    // 资源网址
	Banner pq.StringArray `json:"banner" gorm:"type:text[]"`    // 头图网址
	Extra  map[string]any `json:"extra" gorm:"serializer:json"` // 预留项
}

博文

func (*Blog) AfterCreate added in v0.17.4

func (b *Blog) AfterCreate(tx *gorm.DB) error

func (*Blog) BeforeCreate

func (b *Blog) BeforeCreate(*gorm.DB) error

func (Blog) String

func (b Blog) String() string

type Filter

type Filter struct {
	Submitter string `json:"submitter" form:"submitter"` // 提交者
	Platform  string `json:"platform" form:"platform"`   // 发布平台
	Type      string `json:"type" form:"type"`           // 博文类型
	UID       string `json:"uid" form:"uid"`             // 账户序号
	TaskID    uint64 `json:"-" form:"-"`                 // 外键
}

博文筛选条件,用来描述一类博文,例如:

filter1 表示所有平台为 "weibo"、类型为 "comment" 的博文

filter2 表示所有由 "114" 提交的用户 "514" 的博文

var filter1 = Filter{
	Platform: "weibo",
	Type: "comment",
}

var filter2 = Filter{
	Submitter: "114",
	UID: "514",
}

func (Filter) IsValid added in v0.17.5

func (f Filter) IsValid() bool

func (Filter) IsZero added in v0.17.5

func (f Filter) IsZero() bool
type Header map[string]string

以 JSON 格式保存

读取时不解析 仅将字符串存在 MagicKey 键下

func (Header) GormDataType

func (Header) GormDataType() string

func (Header) MarshalJSON

func (h Header) MarshalJSON() ([]byte, error)

func (*Header) Scan

func (h *Header) Scan(src any) error

func (Header) String added in v0.17.0

func (h Header) String() string

func (Header) Value

func (h Header) Value() (driver.Value, error)

type RequestLog

type RequestLog struct {
	BlogID     uint64    `json:"blog_id"`
	CreatedAt  time.Time `json:"created_at"`
	FinishedAt time.Time `json:"finished_at"`
	Result     any       `json:"result" gorm:"serializer:json"` // 响应为 JSON 会自动解析
	Error      string    `json:"error"`                         // 请求过程中发生的错误
	TaskID     uint64    `json:"-" gorm:"index:idx_logs_query"` // 外键
}

请求记录

type Role

type Role uint64 // 权限
const (
	Invalid Role = iota
	Normal
	Trusted
	Admin
	Owner
)

func (Role) IsAdmin

func (r Role) IsAdmin() bool

type Task

type Task struct {
	ID        uint64         `json:"id" gorm:"primaryKey;autoIncrement"`
	CreatedAt time.Time      `json:"created_at"`
	DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`

	Public bool   `json:"public"`  // 是否公开
	Enable bool   `json:"enable"`  // 是否启用
	Name   string `json:"name"`    // 任务名称
	Icon   string `json:"icon"`    // 任务图标
	Method string `json:"method"`  // 请求方法
	URL    string `json:"url"`     // 请求地址
	Body   string `json:"body"`    // 请求内容
	Header Header `json:"header"`  // 请求头部
	Readme string `json:"readme"`  // 任务描述
	ForkID uint64 `json:"fork_id"` // 复刻来源

	ForkCount int `json:"fork_count" gorm:"-"` // 被复刻次数

	Filters []Filter     `json:"filters"` // 筛选条件
	Logs    []RequestLog `json:"logs"`    // 请求记录
	UserID  string       `json:"user_id"` // 外键
}

任务

func (*Task) AfterFind added in v0.17.0

func (t *Task) AfterFind(tx *gorm.DB) error

func (*Task) BeforeCreate added in v0.17.0

func (t *Task) BeforeCreate(*gorm.DB) error

type Template

type Template struct {
	// contains filtered or unexported fields
}

func NewTemplate

func NewTemplate(blog *Blog) *Template

func (*Template) Do added in v0.17.5

func (t *Template) Do(task *Task) (result []byte, err error)

func (*Template) Reader

func (t *Template) Reader(text string) (io.Reader, error)

func (*Template) RunTask added in v0.17.0

func (t *Template) RunTask(task *Task) RequestLog

func (*Template) RunTasks added in v0.17.0

func (t *Template) RunTasks(tasks []*Task) []RequestLog

func (*Template) String

func (t *Template) String(text string) (string, error)

type User

type User struct {
	UID       string    `json:"uid" gorm:"primaryKey"`
	CreatedAt time.Time `json:"created_at"`
	IssuedAt  int64     `json:"-"`
	Ban       time.Time `json:"ban"`      // 封禁结束时间
	Role      Role      `json:"role"`     // 权限等级
	Name      string    `json:"name"`     // 用户名 非必要不可变
	Nickname  string    `json:"nickname"` // 昵称 可变
	Password  string    `json:"-"`        // 密码 不可变
	Tasks     []Task    `json:"tasks"`    // 任务集

	Extra map[string]any `json:"-" gorm:"serializer:json"` // 预留项 仅存
}

用户

Jump to

Keyboard shortcuts

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