internal

package
v0.0.0-...-b62883f Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2020 License: MIT Imports: 84 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MediaResolution  = 640 // 640x480
	AvatarResolution = 60  // 60x60
	AsyncTaskLimit   = 5
	MaxFailedLogins  = 3 // By default 3 failed login attempts per 5 minutes
)
View Source
const (
	// DebugMode is the default debug mode
	DefaultDebug = false

	// DefaultData is the default data directory for storage
	DefaultData = "./data"

	// DefaultStore is the default data store used for accounts, sessions, etc
	DefaultStore = "bitcask://twtxt.db"

	// DefaultBaseURL is the default Base URL for the app used to construct feed URLs
	DefaultBaseURL = "http://0.0.0.0:8000"

	// DefaultAdminXXX is the default admin user / pod operator
	DefaultAdminUser  = "admin"
	DefaultAdminName  = "Administrator"
	DefaultAdminEmail = "support@twt.social"

	// DefaultName is the default instance name
	DefaultName = "twtxt.net"

	// DefaultMetaxxx are the default set of <meta> tags used on non-specific views
	DefaultMetaTitle       = ""
	DefaultMetaAuthor      = "twtxt.net / twt.social"
	DefaultMetaKeywords    = "twtxt, twt, blog, micro-blogging, social, media, decentralised, pod"
	DefaultMetaDescription = "" /* 128-byte string literal not displayed */

	// DefaultTheme is the default theme to use ('light' or 'dark')
	DefaultTheme = "dark"

	// DefaultOpenRegistrations is the default for open user registrations
	DefaultOpenRegistrations = false

	// DefaultRegisterMessage is the default message displayed when  registrations are disabled
	DefaultRegisterMessage = ""

	// DefaultCookieSecret is the server's default cookie secret
	DefaultCookieSecret = "PLEASE_CHANGE_ME!!!"

	// DefaultTwtsPerPage is the server's default twts per page to display
	DefaultTwtsPerPage = 50

	// DefaultMaxTwtLength is the default maximum length of posts permitted
	DefaultMaxTwtLength = 288

	// DefaultMaxCacheTTL is the default maximum cache ttl of twts in memory
	DefaultMaxCacheTTL = time.Hour * 24 * 10 // 10 days 28 days 28 days 28 days

	// DefaultMaxCacheItems is the default maximum cache items (per feed source)
	// of twts in memory
	DefaultMaxCacheItems = DefaultTwtsPerPage * 3 // We get bored after paging thorughh > 3 pages :D

	// DefaultOpenProfiles is the default for whether or not to have open user profiles
	DefaultOpenProfiles = false

	// DefaultMaxUploadSize is the default maximum upload size permitted
	DefaultMaxUploadSize = 1 << 24 // ~16MB (enough for high-res photos)

	// DefaultSessionCacheTTL is the server's default session cache ttl
	DefaultSessionCacheTTL = 1 * time.Hour

	// DefaultSessionExpiry is the server's default session expiry time
	DefaultSessionExpiry = 240 * time.Hour // 10 days

	// DefaultTranscoderTimeout is the default vodeo transcoding timeout
	DefaultTranscoderTimeout = 10 * time.Minute // 10mins

	// DefaultMagicLinkSecret is the jwt magic link secret
	DefaultMagicLinkSecret = "PLEASE_CHANGE_ME!!!"

	// Default SMTP configuration
	DefaultSMTPHost = "smtp.gmail.com"
	DefaultSMTPPort = 587
	DefaultSMTPUser = "PLEASE_CHANGE_ME!!!"
	DefaultSMTPPass = "PLEASE_CHANGE_ME!!!"
	DefaultSMTPFrom = "PLEASE_CHANGE_ME!!!"

	// DefaultMaxFetchLimit is the maximum fetch fetch limit in bytes
	DefaultMaxFetchLimit = 1 << 21 // ~2MB (or more than enough for a year)

	// DefaultAPISessionTime is the server's default session time for API tokens
	DefaultAPISessionTime = 240 * time.Hour // 10 days

	// DefaultAPISigningKey is the default API JWT signing key for tokens
	DefaultAPISigningKey = "PLEASE_CHANGE_ME!!!"
)
View Source
const (
	DayAgo   = time.Hour * 24
	WeekAgo  = DayAgo * 7
	MonthAgo = DayAgo * 30
	YearAgo  = MonthAgo * 12
)

Variables

View Source
var (
	// ErrInvalidCredentials is returned for invalid credentials against /auth
	ErrInvalidCredentials = errors.New("error: invalid credentials")

	// ErrInvalidToken is returned for expired or invalid tokens used in Authorizeation headers
	ErrInvalidToken = errors.New("error: invalid token")
)
View Source
var (
	ErrTwtAlreadyArchived = errors.New("error: twt already archived")
	ErrTwtNotArchived     = errors.New("error: twt not found in archived")
)
View Source
var (
	Jobs        map[string]JobSpec
	StartupJobs map[string]JobSpec
)
View Source
var (
	ErrFeedAlreadyExists = errors.New("error: feed already exists by that name")
	ErrAlreadyFollows    = errors.New("error: you already follow this feed")
	ErrTooManyFeeds      = errors.New("error: you have too many feeds")
)
View Source
var (
	// DefaultFeedSources is the default list of external feed sources
	DefaultFeedSources = []string{
		"https://feeds.twtxt.net/we-are-feeds.txt",
		"https://raw.githubusercontent.com/mdom/we-are-twtxt/master/we-are-bots.txt",
		"https://raw.githubusercontent.com/mdom/we-are-twtxt/master/we-are-twtxt.txt",
	}

	// DefaultTwtPrompts are the set of default prompts  for twt text(s)
	DefaultTwtPrompts = []string{
		`What's on your mind?`,
		`Share something insightful!`,
		`Good day to you! What's new?`,
		`Did something cool lately? Share it!`,
		`Hi! 👋 Don't forget to post a Twt today!`,
	}

	// DefaultWhitelistedDomains is the default list of domains to whitelist for external images
	DefaultWhitelistedDomains = []string{
		`imgur\.com`,
		`giphy\.com`,
		`imgs\.xkcd\.com`,
		`tube\.mills\.io`,
		`reactiongifs\.com`,
		`githubusercontent\.com`,
	}
)
View Source
var (
	ErrInvalidStore   = errors.New("error: invalid store")
	ErrUserNotFound   = errors.New("error: user not found")
	ErrTokenNotFound  = errors.New("error: token not found")
	ErrFeedNotFound   = errors.New("error: feed not found")
	ErrInvalidSession = errors.New("error: invalid session")
)
View Source
var (
	ErrInvalidTwtLine = errors.New("error: invalid twt line parsed")
	ErrInvalidFeed    = errors.New("error: erroneous feed detected")
)
View Source
var (
	ErrInvalidFeedName   = errors.New("error: invalid feed name")
	ErrBadRequest        = errors.New("error: request failed with non-200 response")
	ErrFeedNameTooLong   = errors.New("error: feed name is too long")
	ErrInvalidUsername   = errors.New("error: invalid username")
	ErrUsernameTooLong   = errors.New("error: username is too long")
	ErrInvalidUserAgent  = errors.New("error: invalid twtxt user agent")
	ErrReservedUsername  = errors.New("error: username is reserved")
	ErrInvalidImage      = errors.New("error: invalid image")
	ErrInvalidAudio      = errors.New("error: invalid audio")
	ErrInvalidVideo      = errors.New("error: invalid video")
	ErrInvalidVideoSize  = errors.New("error: invalid video size")
	ErrVideoUploadFailed = errors.New("error: video upload failed")
)
View Source
var (
	ErrConfigPathMissing = errors.New("error: config file missing")
)
View Source
var (
	ErrFeedImposter = errors.New("error: imposter detected, you do not own this feed")
)
View Source
var (
	ErrInvalidBlogPath = errors.New("error: invalid blog path")
)
View Source
var (
	ErrSendingEmail = errors.New("error: unable to send email")
)

Functions

func AddFeedOwnership

func AddFeedOwnership(db Store, user *User, feed *Feed) (err error)

func AppendSpecial

func AppendSpecial(conf *Config, db Store, specialUsername, text string, args ...interface{}) (types.Twt, error)

func AppendTwt

func AppendTwt(conf *Config, db Store, user *User, text string, args ...interface{}) (types.Twt, error)

func CleanTwt

func CleanTwt(text string) string

CleanTwt cleans a twt's text, replacing new lines with spaces and stripping surrounding spaces.

func CmdExists

func CmdExists(cmd string) bool

CmdExists ...

func CreateFeed

func CreateFeed(conf *Config, db Store, user *User, name string, force bool) error

func DeleteLastTwt

func DeleteLastTwt(conf *Config, user *User) error

func DetachFeedFromOwner

func DetachFeedFromOwner(db Store, user *User, feed *Feed) (err error)

func DownloadImage

func DownloadImage(conf *Config, url string, resource, name string, opts *ImageOptions) (string, error)

func ExpandMentions

func ExpandMentions(conf *Config, db Store, user *User, text string) string

ExpandMentions turns "@nick" into "@<nick URL>" if we're following the user or feed or if they exist on the local pod. Also turns @user@domain into @<user URL> as a convenient way to mention users across pods.

func ExpandTag

func ExpandTag(conf *Config, db Store, user *User, text string) string

Turns #tag into "@<tag URL>"

func FeedExists

func FeedExists(conf *Config, username string) bool

func FileExists

func FileExists(name string) bool

func FilterTwts

func FilterTwts(user *User, twts types.Twts) (filtered types.Twts)

FilterTwts filters out Twts from users/feeds that a User has chosen to mute

func FormatForDateTime

func FormatForDateTime(t time.Time) string

func FormatMentionsAndTags

func FormatMentionsAndTags(conf *Config, text string, format TwtTextFormat) string

FormatMentionsAndTags turns `@<nick URL>` into `<a href="URL">@nick</a>` and `#<tag URL>` into `<a href="URL">#tag</a>` and a `!<hash URL>` into a `<a href="URL">!hash</a>`.

func FormatMentionsAndTagsForSubject

func FormatMentionsAndTagsForSubject(text string) string

FormatMentionsAndTagsForSubject turns `@<nick URL>` into `@nick`

func FormatRequest

func FormatRequest(r *http.Request) string

FormatRequest generates ascii representation of a request

func FormatTwtFactory

func FormatTwtFactory(conf *Config) func(text string) template.HTML

FormatTwtFactory formats a twt into a valid HTML snippet

func GenerateAvatar

func GenerateAvatar(conf *Config, username string) (image.Image, error)

func GetAllFeeds

func GetAllFeeds(conf *Config) ([]string, error)

func GetAllTwts

func GetAllTwts(conf *Config, name string) (types.Twts, error)

func GetExternalAvatar

func GetExternalAvatar(conf *Config, nick, uri string) string

func GetFeedCount

func GetFeedCount(conf *Config, name string) (int, error)

func GetLastTwt

func GetLastTwt(conf *Config, user *User) (twt types.Twt, offset int, err error)

func GetMediaNamesFromText

func GetMediaNamesFromText(text string) []string

func HasString

func HasString(a []string, x string) bool

func ImageToPng

func ImageToPng(fn string) error

func Indent

func Indent(text, indent string) string

indents a block of text with an indent string

func IntPow

func IntPow(x, y int) int

func IsAdminUserFactory

func IsAdminUserFactory(conf *Config) func(user *User) bool

IsAdminUserFactory returns a function that returns true if the user provided is the configured pod administrator, false otherwise.

func IsAudio

func IsAudio(fn string) bool

func IsExternalFeedFactory

func IsExternalFeedFactory(conf *Config) func(url string) bool

func IsImage

func IsImage(fn string) bool

func IsLocalURLFactory

func IsLocalURLFactory(conf *Config) func(url string) bool

func IsVideo

func IsVideo(fn string) bool

func LineCount

func LineCount(r io.Reader) (int, error)

func MapStrings

func MapStrings(xs []string, f func(s string) string) []string

func NewDeleteOldSessionsJob

func NewDeleteOldSessionsJob(conf *Config, blogs *BlogsCache, cache *Cache, archive Archiver, db Store) cron.Job

func NewFixMissingTwtsJob

func NewFixMissingTwtsJob(conf *Config, blogs *BlogsCache, cache *Cache, archive Archiver, db Store) cron.Job

func NewFixUserAccountsJob

func NewFixUserAccountsJob(conf *Config, blogs *BlogsCache, cache *Cache, archive Archiver, db Store) cron.Job

func NewMergeStoreJob

func NewMergeStoreJob(conf *Config, blogs *BlogsCache, cache *Cache, archive Archiver, db Store) cron.Job

func NewStats

func NewStats(name string) *expvar.Map

NewStats ...

func NewStatsJob

func NewStatsJob(conf *Config, blogs *BlogsCache, cache *Cache, archive Archiver, db Store) cron.Job

func NewSyncStoreJob

func NewSyncStoreJob(conf *Config, blogs *BlogsCache, cache *Cache, archive Archiver, db Store) cron.Job

func NewUpdateFeedSourcesJob

func NewUpdateFeedSourcesJob(conf *Config, blogs *BlogsCache, cache *Cache, archive Archiver, db Store) cron.Job

func NewUpdateFeedsJob

func NewUpdateFeedsJob(conf *Config, blogs *BlogsCache, cache *Cache, archive Archiver, db Store) cron.Job

func NormalizeFeedName

func NormalizeFeedName(name string) string

func NormalizeURL

func NormalizeURL(url string) string

func NormalizeUsername

func NormalizeUsername(username string) string

func ParseFile

func ParseFile(scanner *bufio.Scanner, twter types.Twter, ttl time.Duration, N int) (types.Twts, types.Twts, error)

func ParseLine

func ParseLine(line string, twter types.Twter) (twt types.Twt, err error)

func ParseTime

func ParseTime(timestr string) (tm time.Time, err error)

func PreprocessMedia

func PreprocessMedia(conf *Config, u *url.URL, alt string) string

PreprocessMedia ...

func PrettyURL

func PrettyURL(uri string) string

func ProcessImage

func ProcessImage(conf *Config, ifn string, resource, name string, opts *ImageOptions) (string, error)

func ReceiveAudio

func ReceiveAudio(r io.Reader) (string, error)

func ReceiveImage

func ReceiveImage(r io.Reader) (string, error)

func ReceiveVideo

func ReceiveVideo(r io.Reader) (string, error)

func RedirectURL

func RedirectURL(r *http.Request, conf *Config, defaultURL string) string

func RemoveFeedOwnership

func RemoveFeedOwnership(db Store, user *User, feed *Feed) (err error)

func RemoveString

func RemoveString(xs []string, e string) []string

func RenderAudio

func RenderAudio(conf *Config, uri string) string

RenderAudio ...

func RenderString

func RenderString(tpl string, ctx *Context) (string, error)

RenderString ...

func RenderVideo

func RenderVideo(conf *Config, uri string) string

RenderVideo ...

func ReplaceExt

func ReplaceExt(fn, newExt string) string

func Request

func Request(conf *Config, method, url string, headers http.Header) (*http.Response, error)

func ResourceExists

func ResourceExists(conf *Config, url string) bool

func RunCmd

func RunCmd(timeout time.Duration, command string, args ...string) error

RunCmd ...

func SafeParseInt

func SafeParseInt(s string, d int) int

SafeParseInt ...

func SaveFeedSources

func SaveFeedSources(feedsources *FeedSources, path string) error

func SendEmail

func SendEmail(conf *Config, recipients []string, replyTo, subject string, body string) error

func SendPasswordResetEmail

func SendPasswordResetEmail(conf *Config, user *User, tokenString string) error

func SendReportAbuseEmail

func SendReportAbuseEmail(conf *Config, nick, url, name, email, category, message string) error

func SendSupportRequestEmail

func SendSupportRequestEmail(conf *Config, name, email, subject, message string) error

func Slugify

func Slugify(uri string) string

func StoreUploadedImage

func StoreUploadedImage(conf *Config, r io.Reader, resource, name string, opts *ImageOptions) (string, error)

func StringKeys

func StringKeys(kv map[string]string) []string

func StringValues

func StringValues(kv map[string]string) []string

func TranscodeAudio

func TranscodeAudio(conf *Config, ifn string, resource, name string, opts *AudioOptions) (string, error)

func TranscodeVideo

func TranscodeVideo(conf *Config, ifn string, resource, name string, opts *VideoOptions) (string, error)

func URLForAvatar

func URLForAvatar(conf *Config, username string) string

func URLForBlogFactory

func URLForBlogFactory(conf *Config, blogs *BlogsCache) func(twt types.Twt) string

func URLForBlogs

func URLForBlogs(baseURL, author string) string

func URLForConvFactory

func URLForConvFactory(conf *Config, cache *Cache) func(twt types.Twt) string

func URLForExternalAvatar

func URLForExternalAvatar(conf *Config, uri string) string

func URLForExternalProfile

func URLForExternalProfile(conf *Config, nick, uri string) string

func URLForPage

func URLForPage(baseURL, page string) string

func URLForTag

func URLForTag(baseURL, tag string) string

func URLForTask

func URLForTask(baseURL, uuid string) string

func URLForTwt

func URLForTwt(baseURL, hash string) string

func URLForUser

func URLForUser(conf *Config, username string) string

func UniqStrings

func UniqStrings(xs []string) []string

func UnparseTwtFactory

func UnparseTwtFactory(conf *Config) func(text string) string

UnparseTwtFactory is the opposite of CleanTwt and ExpandMentions/ExpandTags

func UserURL

func UserURL(url string) string

func ValidateFeed

func ValidateFeed(conf *Config, nick, url string) error

func ValidateFeedName

func ValidateFeedName(path string, name string) error

func ValidateUsername

func ValidateUsername(username string) error

ValidateUsername validates the username before allowing it to be created. This ensures usernames match a defined pattern and that some usernames that are reserved are never used by users.

func WebMention

func WebMention(target, source string) error

Types

type API

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

API ...

func NewAPI

func NewAPI(router *Router, config *Config, cache *Cache, archive Archiver, db Store, pm passwords.Passwords) *API

NewAPI ...

func (*API) AuthEndpoint

func (a *API) AuthEndpoint() httprouter.Handle

AuthEndpoint ...

func (*API) ConversationEndpoint

func (a *API) ConversationEndpoint() httprouter.Handle

ConversationEndpoint ...

func (*API) CreateToken

func (a *API) CreateToken(user *User, r *http.Request) (*Token, error)

CreateToken ...

func (*API) DiscoverEndpoint

func (a *API) DiscoverEndpoint() httprouter.Handle

DiscoverEndpoint ...

func (*API) ExternalProfileEndpoint

func (a *API) ExternalProfileEndpoint() httprouter.Handle

ExternalProfileEndpoint ...

func (*API) FetchTwtsEndpoint

func (a *API) FetchTwtsEndpoint() httprouter.Handle

FetchTwtsEndpoint ...

func (*API) FollowEndpoint

func (a *API) FollowEndpoint() httprouter.Handle

FollowEndpoint ...

func (*API) MentionsEndpoint

func (a *API) MentionsEndpoint() httprouter.Handle

MentionsEndpoint ...

func (*API) MuteEndpoint

func (a *API) MuteEndpoint() httprouter.Handle

MuteEndpoint ...

func (*API) PingEndpoint

func (a *API) PingEndpoint() httprouter.Handle

PingEndpoint ...

func (*API) PostEndpoint

func (a *API) PostEndpoint() httprouter.Handle

PostEndpoint ...

func (*API) ProfileEndpoint

func (a *API) ProfileEndpoint() httprouter.Handle

ProfileEndpoint ...

func (*API) RegisterEndpoint

func (a *API) RegisterEndpoint() httprouter.Handle

RegisterEndpoint ...

func (*API) ReportEndpoint

func (a *API) ReportEndpoint() httprouter.Handle

ReportEndpoint ...

func (*API) SupportEndpoint

func (a *API) SupportEndpoint() httprouter.Handle

SupportEndpoint ...

func (*API) TimelineEndpoint

func (a *API) TimelineEndpoint() httprouter.Handle

TimelineEndpoint ...

func (*API) UnfollowEndpoint

func (a *API) UnfollowEndpoint() httprouter.Handle

UnfollowEndpoint ...

func (*API) UnmuteEndpoint

func (a *API) UnmuteEndpoint() httprouter.Handle

UnmuteEndpoint ...

func (*API) UploadMediaEndpoint

func (a *API) UploadMediaEndpoint() httprouter.Handle

UploadMediaEndpoint ...

type Archiver

type Archiver interface {
	Del(hash string) error
	Has(hash string) bool
	Get(hash string) (types.Twt, error)
	Archive(twt types.Twt) error
	Count() (int, error)
}

Archiver is an interface for retrieving old twts from an archive storage such as an on-disk hash layout with one directory per 2-letter part of the hash sequence.

func NewDiskArchiver

func NewDiskArchiver(p string) (Archiver, error)

func NewNullArchiver

func NewNullArchiver() (Archiver, error)

type AudioOptions

type AudioOptions struct {
	Resample   bool
	Channels   int
	Samplerate int
	Bitrate    int
}

type AudioTask

type AudioTask struct {
	*BaseTask
	// contains filtered or unexported fields
}

func NewAudioTask

func NewAudioTask(conf *Config, fn string) *AudioTask

func (*AudioTask) Run

func (t *AudioTask) Run() error

func (*AudioTask) String

func (t *AudioTask) String() string

type BaseTask

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

func NewBaseTask

func NewBaseTask() *BaseTask

func (*BaseTask) Done

func (t *BaseTask) Done()

func (*BaseTask) Error

func (t *BaseTask) Error() error

func (*BaseTask) Fail

func (t *BaseTask) Fail(err error) error

func (*BaseTask) ID

func (t *BaseTask) ID() string

func (*BaseTask) Result

func (t *BaseTask) Result() TaskResult

func (*BaseTask) SetData

func (t *BaseTask) SetData(key, val string)

func (*BaseTask) SetState

func (t *BaseTask) SetState(state TaskState)

func (*BaseTask) State

func (t *BaseTask) State() TaskState

func (*BaseTask) String

func (t *BaseTask) String() string

type BitcaskStore

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

BitcaskStore ...

func (*BitcaskStore) Close

func (bs *BitcaskStore) Close() error

Close ...

func (*BitcaskStore) DelFeed

func (bs *BitcaskStore) DelFeed(name string) error

func (*BitcaskStore) DelSession

func (bs *BitcaskStore) DelSession(sid string) error

func (*BitcaskStore) DelToken

func (bs *BitcaskStore) DelToken(signature string) error

func (*BitcaskStore) DelUser

func (bs *BitcaskStore) DelUser(username string) error

func (*BitcaskStore) GetAllFeeds

func (bs *BitcaskStore) GetAllFeeds() ([]*Feed, error)

func (*BitcaskStore) GetAllSessions

func (bs *BitcaskStore) GetAllSessions() ([]*session.Session, error)

func (*BitcaskStore) GetAllUsers

func (bs *BitcaskStore) GetAllUsers() ([]*User, error)

func (*BitcaskStore) GetFeed

func (bs *BitcaskStore) GetFeed(name string) (*Feed, error)

func (*BitcaskStore) GetSession

func (bs *BitcaskStore) GetSession(sid string) (*session.Session, error)

func (*BitcaskStore) GetToken

func (bs *BitcaskStore) GetToken(signature string) (*Token, error)

func (*BitcaskStore) GetUser

func (bs *BitcaskStore) GetUser(username string) (*User, error)

func (*BitcaskStore) GetUserTokens

func (bs *BitcaskStore) GetUserTokens(user *User) ([]*Token, error)

func (*BitcaskStore) HasFeed

func (bs *BitcaskStore) HasFeed(name string) bool

func (*BitcaskStore) HasSession

func (bs *BitcaskStore) HasSession(sid string) bool

func (*BitcaskStore) HasUser

func (bs *BitcaskStore) HasUser(username string) bool

func (*BitcaskStore) LenFeeds

func (bs *BitcaskStore) LenFeeds() int64

func (*BitcaskStore) LenSessions

func (bs *BitcaskStore) LenSessions() int64

func (*BitcaskStore) LenTokens

func (bs *BitcaskStore) LenTokens() int64

func (*BitcaskStore) LenUsers

func (bs *BitcaskStore) LenUsers() int64

func (*BitcaskStore) Merge

func (bs *BitcaskStore) Merge() error

Merge ...

func (*BitcaskStore) SearchFeeds

func (bs *BitcaskStore) SearchFeeds(prefix string) []string

func (*BitcaskStore) SearchUsers

func (bs *BitcaskStore) SearchUsers(prefix string) []string

func (*BitcaskStore) SetFeed

func (bs *BitcaskStore) SetFeed(name string, feed *Feed) error

func (*BitcaskStore) SetSession

func (bs *BitcaskStore) SetSession(sid string, sess *session.Session) error

func (*BitcaskStore) SetToken

func (bs *BitcaskStore) SetToken(signature string, tkn *Token) error

func (*BitcaskStore) SetUser

func (bs *BitcaskStore) SetUser(username string, user *User) error

func (*BitcaskStore) Sync

func (bs *BitcaskStore) Sync() error

Sync ...

func (*BitcaskStore) SyncSession

func (bs *BitcaskStore) SyncSession(sess *session.Session) error

type BlogPost

type BlogPost struct {
	Author string `json:"author"`
	Year   int    `json:"year"`
	Month  int    `json:"month"`
	Date   int    `json:"date"`
	Slug   string `json:"slub"`
	Title  string `json:"title"`
	Twt    string `json:"twt"`

	PublishedAt time.Time `json:"published_at"`
	// contains filtered or unexported fields
}

func BlogPostFromFile

func BlogPostFromFile(conf *Config, fn string) (*BlogPost, error)

func BlogPostFromParams

func BlogPostFromParams(conf *Config, p httprouter.Params) (*BlogPost, error)

func NewBlogPost

func NewBlogPost(author, title string) *BlogPost

func WriteBlog

func WriteBlog(conf *Config, user *User, title, content string) (*BlogPost, error)

func WriteBlogAs

func WriteBlogAs(conf *Config, feed string, title, content string) (*BlogPost, error)

func (*BlogPost) Bytes

func (b *BlogPost) Bytes() []byte

func (*BlogPost) Content

func (b *BlogPost) Content() string

func (*BlogPost) Created

func (b *BlogPost) Created() time.Time

func (*BlogPost) Filename

func (b *BlogPost) Filename(ext string) string

func (*BlogPost) Hash

func (b *BlogPost) Hash() string

func (*BlogPost) Load

func (b *BlogPost) Load(conf *Config) error

func (*BlogPost) LoadMetadata

func (b *BlogPost) LoadMetadata(conf *Config) error

func (*BlogPost) Modified

func (b *BlogPost) Modified() time.Time

func (*BlogPost) Published

func (b *BlogPost) Published() time.Time

func (*BlogPost) Reset

func (b *BlogPost) Reset()

func (*BlogPost) Save

func (b *BlogPost) Save(conf *Config) error

func (*BlogPost) String

func (b *BlogPost) String() string

func (*BlogPost) URL

func (b *BlogPost) URL(baseURL string) string

func (*BlogPost) Write

func (b *BlogPost) Write(p []byte) (int, error)

func (*BlogPost) WriteString

func (b *BlogPost) WriteString(s string) (int, error)

type BlogPosts

type BlogPosts []*BlogPost

func GetAllBlogPosts

func GetAllBlogPosts(conf *Config) (BlogPosts, error)

func GetBlogPostsByAuthor

func GetBlogPostsByAuthor(conf *Config, author string) (BlogPosts, error)

func (BlogPosts) Len

func (bs BlogPosts) Len() int

func (BlogPosts) Less

func (bs BlogPosts) Less(i, j int) bool

func (BlogPosts) Swap

func (bs BlogPosts) Swap(i, j int)

type BlogsCache

type BlogsCache struct {
	Blogs map[string]*BlogPost
	// contains filtered or unexported fields
}

BlogsCache ...

func LoadBlogsCache

func LoadBlogsCache(path string) (*BlogsCache, error)

LoadBlogsCache ...

func NewBlogsCache

func NewBlogsCache() *BlogsCache

NewBlogsCache ...

func (BlogsCache) Add

func (cache BlogsCache) Add(blogPost *BlogPost)

Add ...

func (BlogsCache) Count

func (cache BlogsCache) Count() int

Count ...

func (BlogsCache) Get

func (cache BlogsCache) Get(hash string) (*BlogPost, bool)

Get ...

func (BlogsCache) GetAll

func (cache BlogsCache) GetAll() BlogPosts

GetAll ...

func (BlogsCache) Store

func (cache BlogsCache) Store(path string) error

Store ...

func (BlogsCache) UpdateBlogs

func (cache BlogsCache) UpdateBlogs(conf *Config)

UpdateBlogs ...

type Cache

type Cache struct {
	Twts map[string]Cached
	// contains filtered or unexported fields
}

Cache ...

func LoadCache

func LoadCache(path string) (*Cache, error)

LoadCache ...

func (*Cache) Count

func (cache *Cache) Count() int

func (*Cache) Delete

func (cache *Cache) Delete(feeds types.Feeds)

Delete ...

func (*Cache) FetchTwts

func (cache *Cache) FetchTwts(conf *Config, archive Archiver, feeds types.Feeds)

FetchTwts ...

func (*Cache) GetAll

func (cache *Cache) GetAll() types.Twts

GetAll ...

func (*Cache) GetByPrefix

func (cache *Cache) GetByPrefix(prefix string, refresh bool) types.Twts

GetByPrefix ...

func (*Cache) GetByURL

func (cache *Cache) GetByURL(url string) types.Twts

GetByURL ...

func (*Cache) GetMentions

func (cache *Cache) GetMentions(u *User) (twts types.Twts)

GetMentions ...

func (*Cache) IsCached

func (cache *Cache) IsCached(url string) bool

IsCached ...

func (*Cache) Lookup

func (cache *Cache) Lookup(hash string) (types.Twt, bool)

Lookup ...

func (*Cache) Store

func (cache *Cache) Store(path string) error

Store ...

type Cached

type Cached struct {
	Twts         types.Twts
	Lastmodified string
	// contains filtered or unexported fields
}

Cached ...

func (Cached) Lookup

func (cached Cached) Lookup(hash string) (types.Twt, bool)

Lookup ...

type CachedItem

type CachedItem struct {
	Value  int
	Expiry time.Time
}

func (CachedItem) Expired

func (item CachedItem) Expired() bool

type CachedItems

type CachedItems map[string]CachedItem

type Config

type Config struct {
	Debug bool

	Data              string
	Name              string
	Description       string
	Store             string
	Theme             string
	BaseURL           string
	AdminUser         string
	AdminName         string
	AdminEmail        string
	FeedSources       []string
	RegisterMessage   string
	CookieSecret      string
	TwtPrompts        []string
	TwtsPerPage       int
	MaxUploadSize     int64
	MaxTwtLength      int
	MaxCacheTTL       time.Duration
	MaxCacheItems     int
	OpenProfiles      bool
	OpenRegistrations bool
	SessionExpiry     time.Duration
	SessionCacheTTL   time.Duration
	TranscoderTimeout time.Duration

	MagicLinkSecret string

	SMTPHost string
	SMTPPort int
	SMTPUser string
	SMTPPass string
	SMTPFrom string

	MaxFetchLimit int64

	APISessionTime time.Duration
	APISigningKey  string

	WhitelistedDomains []string
	// contains filtered or unexported fields
}

Config contains the server configuration parameters

func NewConfig

func NewConfig() *Config

func (*Config) RandomTwtPrompt

func (c *Config) RandomTwtPrompt() string

RandomTwtPrompt returns a random Twt Prompt for display by the UI

func (*Config) Settings

func (c *Config) Settings() *Settings

Settings returns a `Settings` struct containing pod settings that can then be persisted to disk to override some configuration options.

func (*Config) WhitelistedDomain

func (c *Config) WhitelistedDomain(domain string) (bool, bool)

WhitelistedDomain returns true if the domain provided is a whiltelisted domain as per the configuration

type Context

type Context struct {
	Config string

	Debug bool

	BaseURL                 string
	InstanceName            string
	SoftwareVersion         string
	TwtsPerPage             int
	TwtPrompt               string
	MaxTwtLength            int
	RegisterDisabled        bool
	OpenProfiles            bool
	RegisterDisabledMessage string

	Timezones []*timezones.Zoneinfo

	Reply         string
	Username      string
	User          *User
	Tokens        []*Token
	LastTwt       types.Twt
	Profile       types.Profile
	Authenticated bool
	IsAdmin       bool

	Error   bool
	Message string
	Theme   string
	Commit  string

	Page    string
	Content template.HTML

	Title        string
	Meta         Meta
	Links        types.Links
	Alternatives types.Alternatives

	Twter       types.Twter
	Twts        types.Twts
	BlogPost    *BlogPost
	BlogPosts   BlogPosts
	Feeds       []*Feed
	FeedSources FeedSourceMap
	Pager       *paginator.Paginator

	// Report abuse
	ReportNick string
	ReportURL  string

	// Reset Password Token
	PasswordResetToken string
}

func NewContext

func NewContext(conf *Config, db Store, req *http.Request) *Context

type ContextKey

type ContextKey int

ContextKey ...

const (
	TokenContextKey ContextKey = iota
	UserContextKey
)

type DeleteOldSessionsJob

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

func (*DeleteOldSessionsJob) Run

func (job *DeleteOldSessionsJob) Run()

type DiskArchiver

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

DiskArchiver implements Archiver using an on-disk hash layout directory structure with one directory per 2-letter hash sequence with a single JSON encoded file per twt.

func (*DiskArchiver) Archive

func (a *DiskArchiver) Archive(twt types.Twt) error

func (*DiskArchiver) Count

func (a *DiskArchiver) Count() (int, error)

func (*DiskArchiver) Del

func (a *DiskArchiver) Del(hash string) error

func (*DiskArchiver) Get

func (a *DiskArchiver) Get(hash string) (types.Twt, error)

func (*DiskArchiver) Has

func (a *DiskArchiver) Has(hash string) bool

type Dispatcher

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

Dispatcher maintains a pool for available workers and a task queue that workers will process

func NewDispatcher

func NewDispatcher(maxWorkers int, maxQueue int) *Dispatcher

NewDispatcher creates a new dispatcher with the given number of workers and buffers the task queue based on maxQueue. It also initializes the channels for the worker pool and task queue

func (*Dispatcher) Dispatch

func (d *Dispatcher) Dispatch(task Task) (string, error)

Dispatch pushes the given task into the task queue. The first available worker will perform the task

func (*Dispatcher) DispatchFunc

func (d *Dispatcher) DispatchFunc(f func() error) (string, error)

DispatchFunc pushes the given func into the task queue by first wrapping it with a `TaskFunc` task.

func (*Dispatcher) Lookup

func (d *Dispatcher) Lookup(id string) (Task, bool)

Lookup returns the matching `Task` given its id

func (*Dispatcher) Start

func (d *Dispatcher) Start()

Start creates and starts workers, adding them to the worker pool. Then, it starts a select loop to wait for tasks to be dispatched to available workers

func (*Dispatcher) Stop

func (d *Dispatcher) Stop()

Stop ends execution for all workers and closes all channels, then removes all workers

type Feed

type Feed struct {
	Name        string
	Description string
	URL         string
	CreatedAt   time.Time

	Followers map[string]string `default:"{}"`
	// contains filtered or unexported fields
}

Feed ...

func LoadFeed

func LoadFeed(data []byte) (feed *Feed, err error)

LoadFeed ...

func NewFeed

func NewFeed() *Feed

NewFeed ...

func (*Feed) Bytes

func (f *Feed) Bytes() ([]byte, error)

func (*Feed) FollowedBy

func (f *Feed) FollowedBy(url string) bool

func (*Feed) Profile

func (f *Feed) Profile(baseURL string, viewer *User) types.Profile

func (*Feed) Source

func (f *Feed) Source() types.Feeds

type FeedSource

type FeedSource struct {
	Name string
	URL  string
}

func ParseFeedSource

func ParseFeedSource(scanner *bufio.Scanner) (feedsources []FeedSource, err error)

type FeedSourceMap

type FeedSourceMap map[string][]FeedSource

type FeedSources

type FeedSources struct {
	Sources FeedSourceMap `"json:sources"`
}

func FetchFeedSources

func FetchFeedSources(conf *Config, sources []string) *FeedSources

func LoadFeedSources

func LoadFeedSources(path string) (*FeedSources, error)

type FixMissingTwtsJob

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

func (*FixMissingTwtsJob) Run

func (job *FixMissingTwtsJob) Run()

type FixUserAccountsJob

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

func (*FixUserAccountsJob) Run

func (job *FixUserAccountsJob) Run()

type FuncTask

type FuncTask struct {
	*BaseTask
	// contains filtered or unexported fields
}

func NewFuncTask

func NewFuncTask(f func() error) *FuncTask

func (*FuncTask) Run

func (t *FuncTask) Run() error

func (*FuncTask) String

func (t *FuncTask) String() string

type ImageOptions

type ImageOptions struct {
	Resize  bool
	ResizeW int
	ResizeH int
}

type ImageTask

type ImageTask struct {
	*BaseTask
	// contains filtered or unexported fields
}

func NewImageTask

func NewImageTask(conf *Config, fn string) *ImageTask

func (*ImageTask) Run

func (t *ImageTask) Run() error

func (*ImageTask) String

func (t *ImageTask) String() string

type JobFactory

type JobFactory func(conf *Config, blogs *BlogsCache, cache *Cache, archive Archiver, store Store) cron.Job

type JobSpec

type JobSpec struct {
	Schedule string
	Factory  JobFactory
}

JobSpec ...

func NewJobSpec

func NewJobSpec(schedule string, factory JobFactory) JobSpec

type MergeStoreJob

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

func (*MergeStoreJob) Run

func (job *MergeStoreJob) Run()

type Meta

type Meta struct {
	Title       string
	Description string
	UpdatedAt   string
	Image       string
	Author      string
	URL         string
	Keywords    string
}

type Middleware

type Middleware func(httprouter.Handle) httprouter.Handle

Middleware ...

type NullArchiver

type NullArchiver struct{}

NullArchiver implements Archiver using dummy implementation stubs

func (*NullArchiver) Archive

func (a *NullArchiver) Archive(twt types.Twt) error

func (*NullArchiver) Count

func (a *NullArchiver) Count() (int, error)

func (*NullArchiver) Del

func (a *NullArchiver) Del(hash string) error

func (*NullArchiver) Get

func (a *NullArchiver) Get(hash string) (types.Twt, error)

func (*NullArchiver) Has

func (a *NullArchiver) Has(hash string) bool

type OldBlogsCache

type OldBlogsCache map[string]*BlogPost

OldBlogsCache ...

type OldCache

type OldCache map[string]Cached

OldCache ...

type Option

type Option func(*Config) error

Option is a function that takes a config struct and modifies it

func WithAPISessionTime

func WithAPISessionTime(duration time.Duration) Option

WithAPISessionTime sets the API session time for tokens

func WithAPISigningKey

func WithAPISigningKey(key string) Option

WithAPISigningKey sets the API JWT signing key for tokens

func WithAdminEmail

func WithAdminEmail(adminEmail string) Option

WithAdminEmail sets the Admin email used to contact the pod operator

func WithAdminName

func WithAdminName(adminName string) Option

WithAdminName sets the Admin name used to identify the pod operator

func WithAdminUser

func WithAdminUser(adminUser string) Option

WithAdminUser sets the Admin user used for granting special features to

func WithBaseURL

func WithBaseURL(baseURL string) Option

WithBaseURL sets the Base URL used for constructing feed URLs

func WithCookieSecret

func WithCookieSecret(secret string) Option

WithCookieSecret sets the server's cookie secret

func WithData

func WithData(data string) Option

WithData sets the data directory to use for storage

func WithDebug

func WithDebug(debug bool) Option

WithDebug sets the debug mode lfag

func WithDescription

func WithDescription(description string) Option

WithDescription sets the instance's description

func WithFeedSources

func WithFeedSources(feedSources []string) Option

WithFeedSources sets the feed sources to use for external feeds

func WithMagicLinkSecret

func WithMagicLinkSecret(secret string) Option

WithMagicLinkSecret sets the MagicLinkSecert used to create password reset tokens

func WithMaxCacheItems

func WithMaxCacheItems(maxCacheItems int) Option

WithMaxCacheItems sets the maximum cache items (per feed source) of twts in memory

func WithMaxCacheTTL

func WithMaxCacheTTL(maxCacheTTL time.Duration) Option

WithMaxCacheTTL sets the maximum cache ttl of twts in memory

func WithMaxFetchLimit

func WithMaxFetchLimit(limit int64) Option

WithMaxFetchLimit sets the maximum feed fetch limit in bytes

func WithMaxTwtLength

func WithMaxTwtLength(maxTwtLength int) Option

WithMaxTwtLength sets the maximum length of posts permitted on the server

func WithMaxUploadSize

func WithMaxUploadSize(maxUploadSize int64) Option

WithMaxUploadSize sets the maximum upload size permitted by the server

func WithName

func WithName(name string) Option

WithName sets the instance's name

func WithOpenProfiles

func WithOpenProfiles(openProfiles bool) Option

WithOpenProfiles sets whether or not to have open user profiles

func WithOpenRegistrations

func WithOpenRegistrations(openRegistrations bool) Option

WithOpenRegistrations sets the open registrations flag

func WithSMTPFrom

func WithSMTPFrom(from string) Option

WithSMTPFrom sets the SMTPFrom address to use for sending email

func WithSMTPHost

func WithSMTPHost(host string) Option

WithSMTPHost sets the SMTPHost to use for sending email

func WithSMTPPass

func WithSMTPPass(pass string) Option

WithSMTPPass sets the SMTPPass to use for sending email

func WithSMTPPort

func WithSMTPPort(port int) Option

WithSMTPPort sets the SMTPPort to use for sending email

func WithSMTPUser

func WithSMTPUser(user string) Option

WithSMTPUser sets the SMTPUser to use for sending email

func WithSessionCacheTTL

func WithSessionCacheTTL(cacheTTL time.Duration) Option

WithSessionCacheTTL sets the server's session cache ttl

func WithSessionExpiry

func WithSessionExpiry(expiry time.Duration) Option

WithSessionExpiry sets the server's session expiry time

func WithStore

func WithStore(store string) Option

WithStore sets the store to use for accounts, sessions, etc.

func WithTheme

func WithTheme(theme string) Option

WithTheme sets the default theme to use

func WithTranscoderTimeout

func WithTranscoderTimeout(timeout time.Duration) Option

WithTranscoderTimeout sets the video transcoding timeout

func WithTwtsPerPage

func WithTwtsPerPage(twtsPerPage int) Option

WithTwtsPerPage sets the server's twts per page

func WithWhitelistedDomains

func WithWhitelistedDomains(whitelistedDomains []string) Option

WithWhitelistedDomains sets the list of domains whitelisted and permitted for external iamges

type PasswordResetEmailContext

type PasswordResetEmailContext struct {
	Pod     string
	BaseURL string

	Token    string
	Username string
}

type ReportAbuseEmailContext

type ReportAbuseEmailContext struct {
	Pod       string
	AdminUser string

	Nick string
	URL  string

	Name     string
	Email    string
	Category string
	Message  string
}

type Router

type Router struct {
	httprouter.Router
	// contains filtered or unexported fields
}

Router ...

func NewRouter

func NewRouter() *Router

NewRouter ...

func (*Router) DELETE

func (r *Router) DELETE(path string, handle httprouter.Handle)

DELETE is a shortcut for Router.Handle("DELETE", path, handle)

func (*Router) File

func (r *Router) File(path, name string)

File serves the named file.

func (*Router) GET

func (r *Router) GET(path string, handle httprouter.Handle)

GET is a shortcut for Router.Handle("GET", path, handle)

func (*Router) Group

func (r *Router) Group(path string, m ...Middleware) *Router

Group returns new *Router with given path and middlewares. It should be used for handles which have same path prefix or common middlewares.

func (*Router) HEAD

func (r *Router) HEAD(path string, handle httprouter.Handle)

HEAD is a shortcut for Router.Handle("HEAD", path, handle)

func (*Router) Handle

func (r *Router) Handle(method, path string, handle httprouter.Handle)

Handle registers a new request handle combined with middlewares.

func (*Router) Handler

func (r *Router) Handler(method, path string, handler http.Handler)

Handler is an adapter for http.Handler.

func (*Router) HandlerFunc

func (r *Router) HandlerFunc(method, path string, handler http.HandlerFunc)

HandlerFunc is an adapter for http.HandlerFunc.

func (*Router) OPTIONS

func (r *Router) OPTIONS(path string, handle httprouter.Handle)

OPTIONS is a shortcut for Router.Handle("OPTIONS", path, handle)

func (*Router) PATCH

func (r *Router) PATCH(path string, handle httprouter.Handle)

PATCH is a shortcut for Router.Handle("PATCH", path, handle)

func (*Router) POST

func (r *Router) POST(path string, handle httprouter.Handle)

POST is a shortcut for Router.Handle("POST", path, handle)

func (*Router) PUT

func (r *Router) PUT(path string, handle httprouter.Handle)

PUT is a shortcut for Router.Handle("PUT", path, handle)

func (*Router) ServeFilesWithCacheControl

func (r *Router) ServeFilesWithCacheControl(path string, root http.FileSystem)

ServeFilesWithCacheControl ...

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*Router) Static

func (r *Router) Static(path, root string)

Static serves files from given root directory.

func (*Router) Use

func (r *Router) Use(m ...Middleware) *Router

Use appends new middleware to current Router.

type Server

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

Server ...

func NewServer

func NewServer(bind string, options ...Option) (*Server, error)

NewServer ...

func (*Server) AddCronJob

func (s *Server) AddCronJob(spec string, job cron.Job) error

AddCronJob ...

func (*Server) AddRoute

func (s *Server) AddRoute(method, path string, handler http.Handler)

AddRouter ...

func (*Server) AddShutdownHook

func (s *Server) AddShutdownHook(f func())

AddShutdownHook ...

func (*Server) AddUserHandler

func (s *Server) AddUserHandler() httprouter.Handle

AddUserHandler ...

func (*Server) ArchiveFeedHandler

func (s *Server) ArchiveFeedHandler() httprouter.Handle

ArchiveFeedHandler...

func (*Server) AvatarHandler

func (s *Server) AvatarHandler() httprouter.Handle

AvatarHandler ...

func (*Server) BlogHandler

func (s *Server) BlogHandler() httprouter.Handle

BlogHandler ...

func (*Server) BlogsHandler

func (s *Server) BlogsHandler() httprouter.Handle

BlogsHandler ...

func (*Server) CaptchaHandler

func (s *Server) CaptchaHandler() httprouter.Handle

CaptchaHandler ...

func (*Server) ConversationHandler

func (s *Server) ConversationHandler() httprouter.Handle

ConversationHandler ...

func (*Server) DelUserHandler

func (s *Server) DelUserHandler() httprouter.Handle

DelUserHandler ...

func (*Server) DeleteAccountHandler

func (s *Server) DeleteAccountHandler() httprouter.Handle

DeleteAccountHandler ...

func (*Server) DeleteAllHandler

func (s *Server) DeleteAllHandler() httprouter.Handle

DeleteAllHandler ...

func (*Server) DeleteBlogHandler

func (s *Server) DeleteBlogHandler() httprouter.Handle

DeleteBlogHandler ...

func (*Server) DeleteTokenHandler

func (s *Server) DeleteTokenHandler() httprouter.Handle

DeleteTokenHandler ...

func (*Server) DiscoverHandler

func (s *Server) DiscoverHandler() httprouter.Handle

DiscoverHandler ...

func (*Server) EditBlogHandler

func (s *Server) EditBlogHandler() httprouter.Handle

EditBlogHandler ...

func (*Server) ExternalAvatarHandler

func (s *Server) ExternalAvatarHandler() httprouter.Handle

ExternalAvatarHandler ...

func (*Server) ExternalHandler

func (s *Server) ExternalHandler() httprouter.Handle

ExternalHandler ...

func (*Server) FeedHandler

func (s *Server) FeedHandler() httprouter.Handle

FeedHandler ...

func (*Server) FeedsHandler

func (s *Server) FeedsHandler() httprouter.Handle

FeedsHandler ...

func (*Server) FollowHandler

func (s *Server) FollowHandler() httprouter.Handle

FollowHandler ...

func (*Server) FollowersHandler

func (s *Server) FollowersHandler() httprouter.Handle

FollowersHandler ...

func (*Server) FollowingHandler

func (s *Server) FollowingHandler() httprouter.Handle

FollowingHandler ...

func (*Server) ImportHandler

func (s *Server) ImportHandler() httprouter.Handle

ImportHandler ...

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe ...

func (*Server) LoginHandler

func (s *Server) LoginHandler() httprouter.Handle

LoginHandler ...

func (*Server) LogoutHandler

func (s *Server) LogoutHandler() httprouter.Handle

LogoutHandler ...

func (*Server) LookupHandler

func (s *Server) LookupHandler() httprouter.Handle

LookupHandler ...

func (*Server) ManageFeedHandler

func (s *Server) ManageFeedHandler() httprouter.Handle

ManageFeedHandler...

func (*Server) ManagePodHandler

func (s *Server) ManagePodHandler() httprouter.Handle

ManagePodHandler ...

func (*Server) ManageUsersHandler

func (s *Server) ManageUsersHandler() httprouter.Handle

ManageUsersHandler ...

func (*Server) MediaHandler

func (s *Server) MediaHandler() httprouter.Handle

MediaHandler ...

func (*Server) MentionsHandler

func (s *Server) MentionsHandler() httprouter.Handle

MentionsHandler ...

func (*Server) MuteHandler

func (s *Server) MuteHandler() httprouter.Handle

MuteHandler ...

func (*Server) NewPasswordHandler

func (s *Server) NewPasswordHandler() httprouter.Handle

NewPasswordHandler ...

func (*Server) NotFoundHandler

func (s *Server) NotFoundHandler(w http.ResponseWriter, r *http.Request)

func (*Server) OldAvatarHandler

func (s *Server) OldAvatarHandler() httprouter.Handle

OldAvatarHandler ... Redirect old URIs (twtxt <= v0.1.0) of the form /user/<nick>/avatar.png -> /user/<nick>/avatar TODO: Remove this after v1

func (*Server) OldTwtxtHandler

func (s *Server) OldTwtxtHandler() httprouter.Handle

OldTwtxtHandler ... Redirect old URIs (twtxt <= v0.0.8) of the form /u/<nick> -> /user/<nick>/twtxt.txt TODO: Remove this after v1

func (*Server) PageHandler

func (s *Server) PageHandler(name string) httprouter.Handle

PageHandler ...

func (*Server) PermalinkHandler

func (s *Server) PermalinkHandler() httprouter.Handle

PermalinkHandler ...

func (*Server) PodAvatarHandler

func (s *Server) PodAvatarHandler() httprouter.Handle

PodAvatarHandler ...

func (*Server) PostHandler

func (s *Server) PostHandler() httprouter.Handle

PostHandler ...

func (*Server) ProfileHandler

func (s *Server) ProfileHandler() httprouter.Handle

ProfileHandler ...

func (*Server) PublishBlogHandler

func (s *Server) PublishBlogHandler() httprouter.Handle

PublishBlogHandler ...

func (*Server) RegisterHandler

func (s *Server) RegisterHandler() httprouter.Handle

RegisterHandler ...

func (*Server) ReportHandler

func (s *Server) ReportHandler() httprouter.Handle

ReportHandler ...

func (*Server) ResetPasswordHandler

func (s *Server) ResetPasswordHandler() httprouter.Handle

ResetPasswordHandler ...

func (*Server) ResetPasswordMagicLinkHandler

func (s *Server) ResetPasswordMagicLinkHandler() httprouter.Handle

ResetPasswordMagicLinkHandler ...

func (*Server) RobotsHandler

func (s *Server) RobotsHandler() httprouter.Handle

RobotsHandler ...

func (*Server) Run

func (s *Server) Run() (err error)

Run ...

func (*Server) SearchHandler

func (s *Server) SearchHandler() httprouter.Handle

SearchHandler ...

func (*Server) SettingsHandler

func (s *Server) SettingsHandler() httprouter.Handle

SettingsHandler ...

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown ...

func (*Server) SupportHandler

func (s *Server) SupportHandler() httprouter.Handle

SupportHandler ...

func (*Server) SyndicationHandler

func (s *Server) SyndicationHandler() httprouter.Handle

SyndicationHandler ...

func (*Server) TaskHandler

func (s *Server) TaskHandler() httprouter.Handle

TaskHandler ...

func (*Server) TimelineHandler

func (s *Server) TimelineHandler() httprouter.Handle

TimelineHandler ...

func (*Server) TransferFeedHandler

func (s *Server) TransferFeedHandler() httprouter.Handle

TransferFeedHandler...

func (*Server) TwtxtHandler

func (s *Server) TwtxtHandler() httprouter.Handle

TwtxtHandler ...

func (*Server) UnfollowHandler

func (s *Server) UnfollowHandler() httprouter.Handle

UnfollowHandler ...

func (*Server) UnmuteHandler

func (s *Server) UnmuteHandler() httprouter.Handle

UnmuteHandler ...

func (*Server) UploadMediaHandler

func (s *Server) UploadMediaHandler() httprouter.Handle

UploadMediaHandler ...

func (*Server) UserConfigHandler

func (s *Server) UserConfigHandler() httprouter.Handle

UserConfigHandler ...

func (*Server) WebMentionHandler

func (s *Server) WebMentionHandler() httprouter.Handle

WebMentionHandler ...

type SessionStore

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

SessionStore ...

func NewSessionStore

func NewSessionStore(store Store, sessionCacheTTL time.Duration) *SessionStore

func (*SessionStore) Count

func (s *SessionStore) Count() int

func (*SessionStore) DelSession

func (s *SessionStore) DelSession(sid string) error

func (*SessionStore) GetAllSessions

func (s *SessionStore) GetAllSessions() ([]*session.Session, error)

func (*SessionStore) GetSession

func (s *SessionStore) GetSession(sid string) (*session.Session, error)

func (*SessionStore) HasSession

func (s *SessionStore) HasSession(sid string) bool

func (*SessionStore) SetSession

func (s *SessionStore) SetSession(sid string, sess *session.Session) error

func (*SessionStore) SyncSession

func (s *SessionStore) SyncSession(sess *session.Session) error

type Settings

type Settings struct {
	Name        string `yaml:"pod_name"`
	Description string `yaml:"pod_description"`

	MaxTwtLength int `yaml:"max_twt_length"`

	OpenProfiles      bool `yaml:"open_profiles"`
	OpenRegistrations bool `yaml:"open_registrations"`
}

Settings contains Pod Settings that can be customised via the Web UI

func LoadSettings

func LoadSettings(path string) (*Settings, error)

LoadSettings loads pod settings from the given path

func (*Settings) Save

func (s *Settings) Save(path string) error

Save saves the pod settings to the given path

type StatsJob

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

func (*StatsJob) Run

func (job *StatsJob) Run()

type Store

type Store interface {
	Merge() error
	Close() error
	Sync() error

	DelFeed(name string) error
	HasFeed(name string) bool
	GetFeed(name string) (*Feed, error)
	SetFeed(name string, user *Feed) error
	LenFeeds() int64
	SearchFeeds(prefix string) []string
	GetAllFeeds() ([]*Feed, error)

	DelUser(username string) error
	HasUser(username string) bool
	GetUser(username string) (*User, error)
	SetUser(username string, user *User) error
	LenUsers() int64
	SearchUsers(prefix string) []string
	GetAllUsers() ([]*User, error)

	GetSession(sid string) (*session.Session, error)
	SetSession(sid string, sess *session.Session) error
	HasSession(sid string) bool
	DelSession(sid string) error
	SyncSession(sess *session.Session) error
	LenSessions() int64
	GetAllSessions() ([]*session.Session, error)

	GetUserTokens(user *User) ([]*Token, error)
	SetToken(signature string, token *Token) error
	DelToken(signature string) error
	LenTokens() int64
}

func NewStore

func NewStore(store string) (Store, error)

type SupportRequestEmailContext

type SupportRequestEmailContext struct {
	Pod       string
	AdminUser string

	Name    string
	Email   string
	Subject string
	Message string
}

type SyncStoreJob

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

func (*SyncStoreJob) Run

func (job *SyncStoreJob) Run()

type TTLCache

type TTLCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewTTLCache

func NewTTLCache(ttl time.Duration) *TTLCache

func (*TTLCache) Dec

func (cache *TTLCache) Dec(k string) int

func (*TTLCache) Get

func (cache *TTLCache) Get(k string) int

func (*TTLCache) Inc

func (cache *TTLCache) Inc(k string) int

func (*TTLCache) Reset

func (cache *TTLCache) Reset(k string) int

func (*TTLCache) Set

func (cache *TTLCache) Set(k string, v int) int

type Task

type Task interface {
	fmt.Stringer

	ID() string
	State() TaskState
	Result() TaskResult
	Error() error
	Run() error
}

Task is an interface that represents a single task to be executed by a worker. Any object can implement a `Task` if it implements the interface.

type TaskData

type TaskData map[string]string

type TaskResult

type TaskResult struct {
	State string   `json:"state"`
	Error string   `json:"error"`
	Data  TaskData `json:"data"`
}

type TaskState

type TaskState int
const (
	TaskStatePending TaskState = iota
	TaskStateRunning
	TaskStateComplete
	TaskStateFailed
)

func (TaskState) String

func (t TaskState) String() string

type Templates

type Templates struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewTemplates

func NewTemplates(conf *Config, blogs *BlogsCache, cache *Cache) (*Templates, error)

func (*Templates) Add

func (t *Templates) Add(name string, template *template.Template)

func (*Templates) Exec

func (t *Templates) Exec(name string, ctx *Context) (io.WriterTo, error)

type TimeVar

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

TimeVar ...

func (*TimeVar) Add

func (o *TimeVar) Add(duration time.Duration)

Add ...

func (*TimeVar) Set

func (o *TimeVar) Set(date time.Time)

Set ...

func (*TimeVar) String

func (o *TimeVar) String() string

String ...

type Token

type Token struct {
	Signature string
	Value     string
	UserAgent string
	CreatedAt time.Time
	ExpiresAt time.Time
}

Token ...

func LoadToken

func LoadToken(data []byte) (token *Token, err error)

func (*Token) Bytes

func (t *Token) Bytes() ([]byte, error)

type TwtTextFormat

type TwtTextFormat int

TwtTextFormat represents the format of which the twt text gets formatted to

const (
	// MarkdownFmt to use markdown format
	MarkdownFmt TwtTextFormat = iota
	// HTMLFmt to use HTML format
	HTMLFmt
	// TextFmt to use for og:description
	TextFmt
)

type TwtxtUserAgent

type TwtxtUserAgent struct {
	ClientName    string
	ClientVersion string
	Nick          string
	URL           string
}

func DetectFollowerFromUserAgent

func DetectFollowerFromUserAgent(ua string) (*TwtxtUserAgent, error)

type URI

type URI struct {
	Type string
	Path string
}

func ParseURI

func ParseURI(uri string) (*URI, error)

func (URI) IsZero

func (u URI) IsZero() bool

func (URI) String

func (u URI) String() string

type UpdateFeedSourcesJob

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

func (*UpdateFeedSourcesJob) Run

func (job *UpdateFeedSourcesJob) Run()

type UpdateFeedsJob

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

func (*UpdateFeedsJob) Run

func (job *UpdateFeedsJob) Run()

type User

type User struct {
	Username  string
	Password  string
	Tagline   string
	Email     string
	URL       string
	CreatedAt time.Time

	Theme                      string `default:"auto"`
	DisplayDatesInTimezone     string `default:"UTC"`
	IsFollowersPubliclyVisible bool   `default:"true"`
	IsFollowingPubliclyVisible bool   `default:"true"`

	Feeds  []string `default:"[]"`
	Tokens []string `default:"[]"`

	Followers map[string]string `default:"{}"`
	Following map[string]string `default:"{}"`
	Muted     map[string]string `default:"{}"`
	// contains filtered or unexported fields
}

User ...

func GetUserFromURL

func GetUserFromURL(conf *Config, db Store, url string) (*User, error)

func LoadUser

func LoadUser(data []byte) (user *User, err error)

func NewUser

func NewUser() *User

NewUser ...

func (*User) AddToken

func (u *User) AddToken(token *Token)

HasToken will add a token to a user if it doesn't exist already

func (*User) Bytes

func (u *User) Bytes() ([]byte, error)

func (*User) Filter

func (u *User) Filter(twts []types.Twt) (filtered []types.Twt)

func (*User) Follow

func (u *User) Follow(nick, url string)

func (*User) FollowAndValidate

func (u *User) FollowAndValidate(conf *Config, nick, url string) error

func (*User) FollowedBy

func (u *User) FollowedBy(url string) bool

func (*User) Follows

func (u *User) Follows(url string) bool

func (*User) HasMuted

func (u *User) HasMuted(url string) bool

func (*User) HasToken

func (u *User) HasToken(token string) bool

HasToken will compare a token value with stored tokens

func (*User) Is

func (u *User) Is(url string) bool

func (*User) Mute

func (u *User) Mute(nick, url string)

func (*User) OwnsFeed

func (u *User) OwnsFeed(name string) bool

func (*User) Profile

func (u *User) Profile(baseURL string, viewer *User) types.Profile

func (*User) Reply

func (u *User) Reply(twt types.Twt) string

func (*User) Source

func (u *User) Source() types.Feeds

func (*User) Sources

func (u *User) Sources() types.Feeds

func (*User) String

func (u *User) String() string

func (*User) Twter

func (u *User) Twter() types.Twter

func (*User) Unmute

func (u *User) Unmute(nick string)

type VideoOptions

type VideoOptions struct {
	Resize bool
	Size   int
}

type VideoTask

type VideoTask struct {
	*BaseTask
	// contains filtered or unexported fields
}

func NewVideoTask

func NewVideoTask(conf *Config, fn string) *VideoTask

func (*VideoTask) Run

func (t *VideoTask) Run() error

func (*VideoTask) String

func (t *VideoTask) String() string

type Worker

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

Worker attaches to a provided worker pool, and looks for tasks on its task channel

func NewWorker

func NewWorker(workerPool chan chan Task) *Worker

NewWorker creates a new worker using the given id and attaches to the provided worker pool. It also initializes the task/quit channels

func (*Worker) Start

func (w *Worker) Start()

Start initializes a select loop to listen for tasks to execute

func (*Worker) Stop

func (w *Worker) Stop()

Stop will end the task select loop for the worker

Directories

Path Synopsis
webmention project webmention.go
webmention project webmention.go

Jump to

Keyboard shortcuts

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