Documentation
¶
Overview ¶
Package db handles all core database interactions of the server
Index ¶
- Variables
- func AllBoardCounter() (uint64, error)
- func AllocateImage(tx *sql.Tx, src, thumb io.ReadSeeker, img common.ImageCommon) (err error)
- func AssertNotSpammer(session auth.Base64Token, ip string) (err error)
- func Ban(board, reason, by string, length time.Duration, id uint64) (err error)
- func BoardCounter(board string) (uint64, error)
- func CanPerform(account, board string, action common.ModerationLevel) (can bool, err error)
- func ChangePassword(account string, hash []byte) error
- func CheckThreadLocked(id uint64) (locked bool, err error)
- func ClearLoginAttempts(ip, account string) error
- func ClearTables(tables ...string) error
- func Close() (err error)
- func ClosePost(id, op uint64, body string, links []common.Link, com []common.Command) (err error)
- func CreateAdminAccount(tx *sql.Tx) (err error)
- func CreateSystemAccount(tx *sql.Tx) (err error)
- func DecrementPyuLimit(tx *sql.Tx, ip string, b string) (err error)
- func DeleteBoard(board, by string) error
- func DeleteImages(ids []uint64, by string) (err error)
- func DeletePosts(ids []uint64, by string) (err error)
- func DeletePostsByIP(id uint64, account string, keepDeleting time.Duration, reason string) (err error)
- func FindPosition(board, userID string) (pos common.ModerationLevel, err error)
- func FreePyuLimit() error
- func GetAllBoardCatalog() (board common.Board, err error)
- func GetAllThreadsIDs() ([]uint64, error)
- func GetBanInfo(ip, board string) (b auth.BanRecord, err error)
- func GetBitChuteTitle(id string) (title string, err error)
- func GetBoardBans(board string) (b []auth.BanRecord, err error)
- func GetBoardCatalog(board string) (b common.Board, err error)
- func GetBoardConfigs(board string) (config.BoardConfigs, error)
- func GetConfigs() (c config.Configs, err error)
- func GetIP(id uint64) (string, error)
- func GetImage(sha1 string) (img common.ImageCommon, err error)
- func GetModLog(board string) (log []auth.ModLogEntry, err error)
- func GetModLogEntry(id uint64) (e auth.ModLogEntry, err error)
- func GetOpenBody(id uint64) (body string, err error)
- func GetOwnedBoards(account string) (boards []string, err error)
- func GetPassword(id string) (hash []byte, err error)
- func GetPcount(b string) (c uint64, err error)
- func GetPcountA(tx *sql.Tx, b string) (c uint64, err error)
- func GetPost(id uint64) (res common.StandalonePost, err error)
- func GetPostBoard(id uint64) (board string, err error)
- func GetPostParenthood(id uint64) (board string, op uint64, err error)
- func GetPostPassword(id uint64) (p []byte, err error)
- func GetPyuLimit(tx *sql.Tx, ip string, b string) (c uint8, err error)
- func GetPyuLimitRestricted(tx *sql.Tx, ip string, b string) (restricted bool, err error)
- func GetReports(board string) (rep []auth.Report, err error)
- func GetSameIPPosts(id uint64, board string, by string) (posts []common.StandalonePost, err error)
- func GetStaff(board string) (staff map[common.ModerationLevel][]string, err error)
- func GetThread(id uint64, lastN int) (t common.Thread, err error)
- func GetThreadIDs(board string) ([]uint64, error)
- func HasImage(id uint64) (has bool, err error)
- func ImageExists(tx *sql.Tx, sha1 string) (exists bool, err error)
- func ImageVisible(sha1, board string) (visible bool, err error)
- func InTransaction(readOnly bool, fn func(*sql.Tx) error) (err error)
- func IncrementLoginAttempts(ip, account string) (attempts uint8, err error)
- func IncrementPcount(tx *sql.Tx, b string) (c uint64, err error)
- func IncrementSpamScore(session auth.Base64Token, ip string, increment uint)
- func InsertImage(tx *sql.Tx, postID uint64, token, name string, spoiler bool) (json []byte, err error)
- func InsertPost(tx *sql.Tx, p *Post) (err error)
- func InsertThread(tx *sql.Tx, subject string, p *Post) (err error)
- func IsBanned(board, ip string) error
- func IsConflictError(err error) bool
- func IsLoggedIn(user, session string) (loggedIn bool, err error)
- func Listen(event string, fn func(msg string) error) (err error)
- func ListenCancelable(event string, canceller <-chan struct{}, fn func(msg string) error) (err error)
- func LoadDB() error
- func LoadTestDB(suffix string) (close func() error, err error)
- func LogOut(account, token string) error
- func LogOutAll(account string) error
- func ModSpoilerImages(ids []uint64, by string) (err error)
- func NeedCaptcha(session auth.Base64Token, ip string) (need bool, err error)
- func NewImageToken(tx *sql.Tx, SHA1 string) (token string, err error)
- func PurgePost(id uint64, by, reason string) (err error)
- func PyuLimitExists(tx *sql.Tx, ip string, b string) (e bool, err error)
- func Read()
- func RefreshBanCache() (err error)
- func RegisterAccount(tx *sql.Tx, id string, hash []byte) error
- func Report(id uint64, board, reason, ip string, illegal bool) error
- func SetBanners(board string, banners []assets.File) error
- func SetLoadingAnimation(board string, file assets.File) error
- func SetOpenBody(id uint64, body []byte) (err error)
- func SetPostCounter(c uint64) error
- func SetPyuLimitRestricted(tx *sql.Tx, ip string, b string) (err error)
- func SetThreadLock(id uint64, locked bool, by string) error
- func SetThreadSticky(id uint64, sticky bool) error
- func SolvedCaptchaRecently(session auth.Base64Token, dur time.Duration) (has bool, err error)
- func SplitBoardAndID(msg string) (board string, id uint64, err error)
- func SplitUint64s(msg string, n int) (arr []uint64, err error)
- func SpoilerImage(id, op uint64) error
- func SystemBan(ip, reason string, length time.Duration) (err error)
- func ThreadCounter(id uint64) (uint64, error)
- func Unban(board string, id uint64, by string) error
- func UpdateBoard(c config.BoardConfigs) (err error)
- func ValidateCaptcha(req auth.Captcha, session auth.Base64Token, ip string) (err error)
- func ValidateOP(id uint64, board string) (valid bool, err error)
- func WriteBitChuteTitle(id string, title string) error
- func WriteBoard(tx *sql.Tx, c BoardConfigs) error
- func WriteConfigs(c config.Configs) (err error)
- func WriteImage(i common.ImageCommon) error
- func WriteLoginSession(account, token string) error
- func WritePost(tx *sql.Tx, p Post) (err error)
- func WritePyuLimit(tx *sql.Tx, ip string, b string) error
- func WriteStaff(tx *sql.Tx, board string, staff map[common.ModerationLevel][]string) (err error)
- func WriteThread(t Thread, p Post) (err error)
- type BoardConfigs
- type ErrMsgParse
- type Post
- type PostStats
- type Thread
- type ThreadPostCountDiff
- type Video
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidToken occurs, when trying to retrieve an image with an // non-existent token. The token might have expired (60 to 119 seconds) or // the client could have provided an invalid token to begin with. ErrInvalidToken = common.ErrInvalidInput("invalid image token") )
var (
ErrUserNameTaken = errors.New("user name already taken")
)
Common errors
Functions ¶
func AllBoardCounter ¶
AllBoardCounter retrieves the progress counter of the /all/ board
func AllocateImage ¶
func AllocateImage(tx *sql.Tx, src, thumb io.ReadSeeker, img common.ImageCommon, ) ( err error, )
AllocateImage allocates an image's file resources to their respective served directories and write its data to the database
func AssertNotSpammer ¶
func AssertNotSpammer(session auth.Base64Token, ip string) (err error)
Check if IP is spammer
func BoardCounter ¶
BoardCounter retrieves the progress counter of a board
func CanPerform ¶
func CanPerform(account, board string, action common.ModerationLevel) ( can bool, err error, )
CanPerform returns, if the account can perform an action of ModerationLevel 'action' on the target board
func ChangePassword ¶
ChangePassword changes an existing user's login password
func CheckThreadLocked ¶
CheckThreadLocked checks, if a thread has been locked by a moderator
func ClearLoginAttempts ¶
ClearLoginAttempts clears login attempts for account for IP
func ClearTables ¶
ClearTables deletes the contents of specified DB tables. Only used for tests.
func CreateAdminAccount ¶
CreateAdminAccount writes a fresh admin account with the default password to the database
func CreateSystemAccount ¶
CreateSystemAccount create an inaccessible account used for automatic internal purposes
func DecrementPyuLimit ¶
DecrementPyuLimit decrements the pyu limit counter by one and returns the new counter
func DeleteBoard ¶
DeleteBoard deletes a board and all of its contained threads and posts
func DeleteImages ¶
DeleteImage permanently deletes an image from a post
func DeletePosts ¶
DeletePost marks the target post as deleted
func DeletePostsByIP ¶
func DeletePostsByIP(id uint64, account string, keepDeleting time.Duration, reason string, ) (err error)
Delete posts of the same IP as target post on board and optionally keep deleting posts by this IP
func FindPosition ¶
func FindPosition(board, userID string) (pos common.ModerationLevel, err error)
FindPosition returns the highest matching position of a user on a certain board. As a special case the admin user will always return "admin".
func FreePyuLimit ¶
func FreePyuLimit() error
FreePyuLimit resets the restricted status and pcount so sluts can #pyu again.
func GetAllBoardCatalog ¶
GetAllBoardCatalog retrieves all threads for the "/all/" meta-board
func GetAllThreadsIDs ¶
GetAllThreadsIDs retrieves all threads IDs in bump order
func GetBanInfo ¶
GetBanInfo retrieves information about a specific ban
func GetBitChuteTitle ¶
GetBitChuteTitle retrieves the bitchute video title by ID
func GetBoardBans ¶
GetBoardBans gets all bans on a specific board. "all" counts as a valid board value.
func GetBoardCatalog ¶
GetBoardCatalog retrieves all OPs of a single board
func GetBoardConfigs ¶
func GetBoardConfigs(board string) (config.BoardConfigs, error)
GetBoardConfigs retrives the configurations of a specific board
func GetConfigs ¶
GetConfigs retrieves global configurations. Only used in tests.
func GetIP ¶
GetIP returns an IP of the poster that created a post. Posts older than 7 days will not have this information.
func GetImage ¶
func GetImage(sha1 string) (img common.ImageCommon, err error)
GetImage retrieves a thumbnailed image record from the DB.
Only used in tests.
func GetModLog ¶
func GetModLog(board string) (log []auth.ModLogEntry, err error)
GetModLog retrieves the moderation log for a specific board
func GetModLogEntry ¶
func GetModLogEntry(id uint64) (e auth.ModLogEntry, err error)
GetModLog retrieves the moderation log entry by ID
func GetOpenBody ¶
GetOpenBody retrieves an open body of a post
func GetOwnedBoards ¶
GetOwnedBoards returns boards the account holder owns
func GetPassword ¶
GetPassword retrieves the login password hash of the registered user account
func GetPcountA ¶
GetPcountA retrieves the board's pyu counter atomically
func GetPost ¶
func GetPost(id uint64) (res common.StandalonePost, err error)
GetPost reads a single post from the database
func GetPostBoard ¶
GetPostBoard retrieves the board of a post by ID
func GetPostParenthood ¶
GetPostParenthood retrieves the board and OP of a post
func GetPostPassword ¶
GetPostPassword retrieves a post's modification password
func GetPyuLimit ¶
GetPyuLimit retrieves the IP and respective board's pyu limit counter
func GetPyuLimitRestricted ¶
GetPyuLimitRestricted retrieves the IP and respective board's pyu limit restricted status
func GetReports ¶
GetReports reads reports for a specific board. Pass "all" for global reports.
func GetSameIPPosts ¶
func GetSameIPPosts(id uint64, board string, by string) ( posts []common.StandalonePost, err error, )
GetSameIPPosts returns posts with the same IP and on the same board as the target post
func GetStaff ¶
func GetStaff(board string, ) (staff map[common.ModerationLevel][]string, err error)
GetStaff retrieves all staff positions of a specific board
func GetThreadIDs ¶
GetThreadIDs retrieves all threads IDs on the board in bump order with stickies first
func ImageExists ¶
ImageExists returns, if image exists
func ImageVisible ¶
ImageVisible returns if the image is attached to any non-deleted and unspoilered posts on the board
func InTransaction ¶
InTransaction runs a function inside a transaction and handles comminting and rollback on error. readOnly: the DBMS can optimise read-only transactions for better concurrency
TODO: Get rid off readOnly param, once reader ported to output JSON
func IncrementLoginAttempts ¶
IncrementLoginAttempts increments or creates the login attempt counter for user
func IncrementPcount ¶
IncrementPcount increments the board's pyu counter by one and returns the new counter
func IncrementSpamScore ¶
func IncrementSpamScore(session auth.Base64Token, ip string, increment uint)
IncrementSpamScore increments spam detection score of a captcha session and sends captcha requests, if score exceeded.
session: token identifying captcha session ip: IP of client increment: increment amount in milliseconds
func InsertImage ¶
func InsertImage(tx *sql.Tx, postID uint64, token, name string, spoiler bool, ) ( json []byte, err error, )
InsertImage insert and image into and existing open post and return image JSON
func InsertPost ¶
Insert Post into thread and set its ID and creation time and moderation status. Thread OPs must have their post ID set to the thread ID. Any images are to be inserted in a separate call.
func InsertThread ¶
InsertThread inserts a new thread into the database. Sets ID, OP and time on inserted post.
func IsConflictError ¶
IsConflictError returns if an error is a unique key conflict error
func IsLoggedIn ¶
IsLoggedIn check if the user is logged in with the specified session
func Listen ¶
Listen assigns a function to listen to Postgres notifications on a channel. Can't be used in tests.
func ListenCancelable ¶
func ListenCancelable(event string, canceller <-chan struct{}, fn func(msg string) error, ) (err error)
Like listen, but is cancelable. Can be used in tests.
func LoadTestDB ¶
Create and load testing database. Call close() to clean up temporary resources.
func ModSpoilerImages ¶
ModSpoilerImage spoilers image as a moderator
func NeedCaptcha ¶
func NeedCaptcha(session auth.Base64Token, ip string) (need bool, err error)
NeedCaptcha returns, if the user needs a captcha to proceed with usage of server resources
func NewImageToken ¶
NewImageToken inserts a new image allocation token into the DB and returns it's ID
func PyuLimitExists ¶
PyuLimitExists checks whether an IP has a pyu limit counter
func RefreshBanCache ¶
func RefreshBanCache() (err error)
RefreshBanCache loads up to date bans from the database and caches them in memory
func RegisterAccount ¶
RegisterAccount writes the ID and password hash of a new user account to the database
func SetBanners ¶
SetBanners overwrites the list of banners in the DB, for a specific board
func SetLoadingAnimation ¶
SetLoadingAnimation sets the loading animation for a specific board. Nil file.Data means the default animation should be used.
func SetOpenBody ¶
SetOpenBody sets the open body of a post
func SetPostCounter ¶
SetPostCounter sets the post counter. Should only be used in tests.
func SetPyuLimitRestricted ¶
SetPyuLimitRestricted sets the IP and respective board's pyu limit restricted status
func SetThreadLock ¶
SetThreadLock sets the ability of users to post in a specific thread
func SetThreadSticky ¶
SetThreadSticky sets the sticky field on a thread
func SolvedCaptchaRecently ¶
Returns, if IP has solved a captcha within the last dur
func SplitBoardAndID ¶
Split message containing a board and post/thread ID
func SplitUint64s ¶
Split message containing a list of uint64 numbers. Returns error, if message did not contain n integers.
func SpoilerImage ¶
SpoilerImage spoilers an already allocated image
func ThreadCounter ¶
ThreadCounter retrieves the progress counter of a thread
func UpdateBoard ¶
func UpdateBoard(c config.BoardConfigs) (err error)
UpdateBoard updates board configurations
func ValidateCaptcha ¶
ValidateCaptcha with captcha backend
func ValidateOP ¶
ValidateOP confirms the specified thread exists on specific board
func WriteBitChuteTitle ¶
WriteBitChuteTitle creates a new bitchute title row.
func WriteBoard ¶
func WriteBoard(tx *sql.Tx, c BoardConfigs) error
WriteBoard writes a board complete with configurations to the database
func WriteConfigs ¶
WriteConfigs writes new global configurations to the database
func WriteImage ¶
func WriteImage(i common.ImageCommon) error
WriteImage writes a processed image record to the DB. Only used in tests.
func WriteLoginSession ¶
WriteLoginSession writes a new user login session to the DB
func WritePyuLimit ¶
WritePyuLimit creates a new pyu limit row. Only used on the first post of a new IP.
func WriteStaff ¶
WriteStaff writes staff positions of a specific board. Old rows are overwritten.
func WriteThread ¶
WriteThread writes a thread and it's OP to the database. Only used for tests.
Types ¶
type BoardConfigs ¶
type BoardConfigs struct { config.BoardConfigs Created time.Time }
BoardConfigs contains extra fields not exposed on database reads
type ErrMsgParse ¶
type ErrMsgParse string
PostgreSQL notification message parse error
func (ErrMsgParse) Error ¶
func (e ErrMsgParse) Error() string
type Post ¶
type Post struct { common.StandalonePost Password []byte IP string }
Post is for writing new posts to a database. It contains the Password field, which is never exposed publically through Post.
type Thread ¶
type Thread struct { ID uint64 PostCtr, ImageCtr uint32 UpdateTime, BumpTime int64 Subject, Board string }
Thread is a template for writing new threads to the database
type ThreadPostCountDiff ¶
type ThreadPostCountDiff struct { Changed map[uint64]uint64 `json:"changed"` Deleted []uint64 `json:"deleted"` }
Diff of passed and actual thread posts counts
func DiffThreadPostCounts ¶
func DiffThreadPostCounts(old map[uint64]uint64) ( diff ThreadPostCountDiff, err error, )
Return diff of passed and actual thread post counts