common

package
v0.0.0-...-15eb0b2 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExtraImagesKey = "archiveImages"
	ExtraVideoKey  = "archiveVideo"
)
View Source
const (
	MimeVideo = "video/mp4"
	MimeImage = "image/jpeg"
)
View Source
const (
	BucketFav          = "fav"
	BucketMyPosts      = "mine"
	BucketByUserPrefix = "user"
	BucketUserProfile  = "profile"
)
View Source
const ProfileAvatarImageKey = "archiveAvatar"
View Source
const RandomSleepMaxSeconds = 10

Variables

This section is empty.

Functions

func UidFromBucketName

func UidFromBucketName(name string) string

func UserBucket

func UserBucket(uid string) string

func ValidateSyncerConfig

func ValidateSyncerConfig(config SyncerConfig) (err error)

Types

type ChannelConf

type ChannelConf struct {
	// if this channel enabled
	Enabled *bool `yaml:"enabled,omitempty" json:"enabled,omitempty"`
	// starting page for sync job
	StartPage int `yaml:"startPage,omitempty" json:"startPage,omitempty"`
	// sync job stops immediately when it meets existing tweet id when IncrementalMode set to true
	IncrementalMode *bool `yaml:"incrementalMode" json:"incrementalMode"`
	// content fetching behavior
	ContentTypes ContentTypes `yaml:"contentTypes" json:"contentTypes"`
	// tweets will be archived only when it's content match the Includes regex
	Includes string `yaml:"includes,omitempty" json:"includes,omitempty"`
	// tweets will not be archived when it's content match the Excludes regex
	Excludes string `yaml:"excludes,omitempty" json:"excludes,omitempty"`
	// only original tweets will be archived
	OriginalOnly *bool `yaml:"originalOnly,omitempty" json:"originalOnly,omitempty"`
}

type Config

type Config struct {
	Syncer SyncerConfig    `yaml:"syncer" json:"syncer"`
	Server WebServerConfig `yaml:"server" json:"server"`

	DatabasePath string        `yaml:"databasePath" json:"-"`
	Session      SessionConfig `yaml:"session" json:"session"`
	// contains filtered or unexported fields
}

Config for dashboard server behavior

func LoadConf

func LoadConf(file string) (config *Config, err error)

func (*Config) OnChange

func (c *Config) OnChange(fn func(conf Config) error)

OnChange sets callback function

func (*Config) Update

func (c *Config) Update(conf Config) error

TODO make onChange call before update data to verify configuration Update updates self data trigger onChange function

type ContentTypes

type ContentTypes struct {
	// fetch long tweet if LongText set to true
	LongText bool `yaml:"longText" json:"longText"`
	// fetch thumbnail for web ui if Thumbnail set to true
	Thumbnail bool `yaml:"thumbnail" json:"thumbnail"`
	// images fetching quality, available options: best, large, middle, none
	ImageQuality ImageQuality `yaml:"imageQuality" json:"imageQuality"`
	// videos fetching quality, available options: best, 720p, 360p, none
	VideoQuality VideoQuality `yaml:"videoQuality" json:"videoQuality"`
}

ContentTypes for content fetching behavior

type CookieAcceptor

type CookieAcceptor interface {
	Accept(cookie string)
}

type Cookies

type Cookies = []*http.Cookie

type Filter

type Filter struct {
	// list won't return it if the tweet containers word in filter word list
	Word []string `json:"word" json:"word"`
	// list won't return it if the tweet id in filter id list
	Id []string `json:"id" json:"id"`
}

Filter configuration for list handler

func (*Filter) Ignore

func (f *Filter) Ignore(item pkg.Item) (yes bool)

Ignore check if item should be ignored

type HttpCli

type HttpCli struct {
	http.Client
	// contains filtered or unexported fields
}

func NewWithHeader

func NewWithHeader(header map[string]string) (cli *HttpCli)

func (*HttpCli) Get

func (h *HttpCli) Get(url string) ([]byte, error)

func (*HttpCli) GetItem

func (h *HttpCli) GetItem(url string) (pkg.Item, error)

func (*HttpCli) GetWithCookie

func (h *HttpCli) GetWithCookie(url string) ([]byte, Cookies, error)

func (*HttpCli) Post

func (h *HttpCli) Post(url string, data string) ([]byte, error)

func (*HttpCli) SetHeader

func (h *HttpCli) SetHeader(k, v string)

type ImageQuality

type ImageQuality string
const (
	ImageQualityBest   ImageQuality = "best"
	ImageQualityLarge  ImageQuality = "large"
	ImageQualityMiddle ImageQuality = "middle"
	ImageQualityNone   ImageQuality = "none"
)

func (ImageQuality) Get

func (q ImageQuality) Get(item pkg.Item, withThumb bool) (url, thumbUrl, liveUrl string, err error)

Get image url, input item structure

{
	"thumbnail": {
		"url": "https://xxxx.jpg",
		"width": 1,
		"height": 2,
	},
	"bmiddle": {},
	"large": {},
	"original": {},
	"largest": {},
	"mw2000": {},
}

func (ImageQuality) Valid

func (q ImageQuality) Valid() error

Valid check if it is valid image quality option

type SessionConfig

type SessionConfig struct {
	CookiePath string `yaml:"cookiePath" json:"cookiePath"`
}

type SyncerConfig

type SyncerConfig struct {
	// weibo uid
	Uid string `yaml:"uid" json:"uid"`
	// weibo cookie
	Cookie string `yaml:"cookie" json:"cookie"`
	// crontab like string, for sync job run schedule
	Cron string `yaml:"cron" json:"cron"`

	// my favorite channel config
	Favorite *ChannelConf `yaml:"favorite,omitempty" json:"favorite,omitempty"`
	// user channel config
	User UserChannels `yaml:"user,omitempty" json:"user,omitempty"`
	// default channel conf, can be overwritten
	DefaultChannelConf *ChannelConf `yaml:"defaultChannelConf,omitempty" json:"defaultChannelConf,omitempty"`
	// use a random sleep
	RandomSleep bool `yaml:"randomSleep,omitempty" json:"randomSleep,omitempty"`
}

SyncerConfig for sync task

type UserChannels

type UserChannels struct {

	// custom channel config
	Custom map[string]*ChannelConf `yaml:"custom,omitempty" json:"custom,omitempty"`
	// common list use default channel conf
	UserIdList []string `yaml:"userIdList,omitempty" json:"userIdList,omitempty"`
	// contains filtered or unexported fields
}

func (*UserChannels) GetUsers

func (u *UserChannels) GetUsers() map[string]*ChannelConf

type VideoQuality

type VideoQuality string
const (
	VideoQualityBest VideoQuality = "best"
	VideoQuality720p VideoQuality = "720p"
	VideoQuality360p VideoQuality = "360p"
	VideoQualityNone VideoQuality = "none"
)

func (VideoQuality) Get

func (q VideoQuality) Get(content []byte) (url string, err error)

func (VideoQuality) Valid

func (q VideoQuality) Valid() error

Valid check if it is valid video quality option

type WebServerConfig

type WebServerConfig struct {
	// web serving address (ip:port)
	Addr string `yaml:"addr" json:"addr"`
	// list api filter
	Filter Filter `yaml:"filter" json:"filter"`
}

WebServerConfig for api server

Jump to

Keyboard shortcuts

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