model

package
v0.8.6 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxSubscribeTagLength = 250
)

Variables

This section is empty.

Functions

func ActiveSourcesByUserID

func ActiveSourcesByUserID(userID int64) error

func DeleteContentsBySourceID

func DeleteContentsBySourceID(sid uint)

DeleteContentsBySourceID delete contents in the db by sourceID

func Disconnect

func Disconnect()

Disconnect disconnects from the database.

func InitDB

func InitDB()

InitDB init db object

func PauseSourcesByUserID

func PauseSourcesByUserID(userID int64) error

func ProcessWechatURL

func ProcessWechatURL(urlStr string) string

ProcessWechatURL return wechat-fetcher sub URL. if it's valid wehchat url, else return origin str

func PublishItem

func PublishItem(source *Source, item *rss.Item, html string) string

PublishItem publish item to telegraph

func RegistFeed

func RegistFeed(userID int64, sourceID uint) error

func UnsubAllByUserID

func UnsubAllByUserID(userID int64) (success int, fail int, err error)

func UnsubByUserIDAndSource

func UnsubByUserIDAndSource(userID int64, source *Source) error

func UnsubByUserIDAndSourceURL

func UnsubByUserIDAndSourceURL(userID int64, url string) error

func UnsubByUserIDAndSubID

func UnsubByUserIDAndSubID(userID int64, subID uint) error

Types

type Content

type Content struct {
	SourceID     uint
	HashID       string `gorm:"primary_key"`
	RawID        string
	RawLink      string
	Title        string
	Description  string `gorm:"-"` //ignore to db
	TelegraphURL string
	EditTime
}

Content fetcher content

func GenContentAndCheckByFeedItem

func GenContentAndCheckByFeedItem(s *Source, item *rss.Item) (*Content, bool, error)

GenContentAndCheckByFeedItem generate content by fetcher item

type EditTime

type EditTime struct {
	CreatedAt time.Time
	UpdatedAt time.Time
}

EditTime timestamp

type Option

type Option struct {
	ID    int `gorm:"primary_key;AUTO_INCREMENT"`
	Name  string
	Value string
	EditTime
}

Option bot 设置

type Source

type Source struct {
	ID         uint `gorm:"primary_key;AUTO_INCREMENT"`
	Link       string
	Title      string
	ErrorCount uint
	Content    []Content
	EditTime
}

func FindOrNewSourceByUrl

func FindOrNewSourceByUrl(url string) (*Source, error)

func GetErrorSourcesByUserID

func GetErrorSourcesByUserID(userID int64) ([]Source, error)

func GetSourceById

func GetSourceById(id uint) (*Source, error)

func GetSourceByUrl

func GetSourceByUrl(url string) (*Source, error)

func GetSources

func GetSources() (sources []*Source)

func GetSourcesByUserID

func GetSourcesByUserID(userID int64) ([]Source, error)

func GetSubscribedNormalSources

func GetSubscribedNormalSources() []*Source

func (*Source) AddErrorCount

func (s *Source) AddErrorCount()

func (*Source) DeleteContents

func (s *Source) DeleteContents()

func (*Source) DeleteDueNoSubscriber

func (s *Source) DeleteDueNoSubscriber()

func (*Source) EraseErrorCount

func (s *Source) EraseErrorCount()

func (*Source) GetNewContents

func (s *Source) GetNewContents() ([]*Content, error)

GetNewContents 获取rss新内容

func (*Source) GetSubscribeNum

func (s *Source) GetSubscribeNum() int

func (*Source) IsSubscribed

func (s *Source) IsSubscribed() bool

func (*Source) NeedUpdate

func (s *Source) NeedUpdate() bool

func (*Source) Save

func (s *Source) Save()

func (*Source) ToggleEnabled

func (s *Source) ToggleEnabled() error

type Subscribe

type Subscribe struct {
	ID                 uint `gorm:"primary_key;AUTO_INCREMENT"`
	UserID             int64
	SourceID           uint
	EnableNotification int
	EnableTelegraph    int
	Tag                string
	Interval           int
	WaitTime           int
	EditTime
}

func GetSubByUserIDAndURL

func GetSubByUserIDAndURL(userID int64, url string) (*Subscribe, error)

func GetSubsByUserID

func GetSubsByUserID(userID int64) ([]Subscribe, error)

func GetSubscribeByID

func GetSubscribeByID(id int) (*Subscribe, error)

func GetSubscribeByUserIDAndSourceID

func GetSubscribeByUserIDAndSourceID(userID int64, sourceID uint) (*Subscribe, error)

func GetSubscribeByUserIDAndURL

func GetSubscribeByUserIDAndURL(userID int, url string) (*Subscribe, error)

func GetSubscriberBySource

func GetSubscriberBySource(s *Source) []*Subscribe

func (*Subscribe) Save

func (s *Subscribe) Save()

func (*Subscribe) SetInterval

func (s *Subscribe) SetInterval(interval int) error

func (*Subscribe) SetTag

func (s *Subscribe) SetTag(tags []string) error

func (*Subscribe) ToggleNotification

func (s *Subscribe) ToggleNotification() error

func (*Subscribe) ToggleTelegraph

func (s *Subscribe) ToggleTelegraph() error

func (*Subscribe) Unsub

func (s *Subscribe) Unsub() error

type User

type User struct {
	ID         int64 `gorm:"primary_key"`
	TelegramID int64
	Source     []Source `gorm:"many2many:subscribes;"`
	State      int      `gorm:"DEFAULT:0;"`
	EditTime
}

User subscriber

TelegramID 用作外键

func FindOrCreateUserByTelegramID

func FindOrCreateUserByTelegramID(telegramID int64) (*User, error)

FindOrCreateUserByTelegramID find subscriber or init a subscriber by telegram ID

func FindOrInitUser deprecated

func FindOrInitUser(userID int64) (*User, error)

FindOrInitUser find subscriber or init a subscriber if user not in db

Deprecated: Use model.FindOrCreateUserByTelegramID instead.

func (*User) GetSubSourceMap

func (user *User) GetSubSourceMap() (map[Subscribe]Source, error)

GetSubSourceMap get user subscribe and fetcher source

Jump to

Keyboard shortcuts

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