Documentation ¶
Overview ¶
Package db handles all core database interactions of the server
Index ¶
- Constants
- Variables
- func AllBoardCounter() (uint64, error)
- func AllocateImage(src, thumb []byte, img common.ImageCommon) error
- func Ban(board, reason, by string, expires time.Time, ids ...uint64) (ips map[string]uint64, err error)
- func BoardCounter(board string) (uint64, error)
- func CanPerform(account, board string, action auth.ModerationLevel) (can bool, err error)
- func ChangePassword(account string, hash []byte) error
- func CheckThreadNonLive(id uint64) (nonLive bool, err error)
- func ClearTables(tables ...string) error
- func ClosePost(id, op uint64, body string, links [][2]uint64, com []common.Command) (err error)
- func CreateAdminAccount() error
- func DeleteBoard(board string) error
- func DeleteImage(id uint64, by string) error
- func DeletePost(id uint64, by string) error
- func FindPosition(board, userID string) (pos auth.ModerationLevel, err error)
- func GetAllBoardCatalog() (threads common.Board, err error)
- func GetAllThreadsIDs() ([]uint64, error)
- func GetBanInfo(ip, board string) (b auth.BanRecord, 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) (common.ImageCommon, error)
- func GetModLog(board string) (log []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 GetPost(id uint64) (res common.StandalonePost, err error)
- func GetPostBoard(id uint64) (board string, err error)
- func GetPostOP(id uint64) (op uint64, err error)
- func GetPostParenthood(id uint64) (board string, op uint64, err error)
- func GetPostPassword(id uint64) (p []byte, err error)
- func GetPyu() (c uint64, err error)
- func GetReports(board string) (rep []auth.Report, err error)
- func GetSameIPPosts(id uint64, board string) (posts []common.StandalonePost, err error)
- func GetStaff(board string) (staff map[string][]string, err error)
- func GetThread(id uint64, lastN int) (t common.Thread, err error)
- func GetThreadIDs(board string) ([]uint64, error)
- func GetThreadMutations(id uint64) (deleted, banned []uint64, err error)
- func HasImage(id uint64) (has bool, err error)
- func IncrementPyu() (c uint64, err error)
- func InsertImage(id uint64, img common.Image) (err error)
- func InsertPost(p Post, sage bool) (err error)
- func InsertThread(subject string, nonLive bool, p Post) (err error)
- func IsConflictError(err error) bool
- func IsLoggedIn(user, session string) (loggedIn bool, err error)
- func LoadDB() (err error)
- func LogOut(account, token string) error
- func LogOutAll(account string) error
- func ModSpoilerImage(id uint64, by string) (err error)
- func NewImageToken(SHA1 string) (token string, err error)
- func NewPostID() (id uint64, err error)
- func PostCounter() (uint64, error)
- func RefreshBanCache() (err error)
- func RegisterAccount(ID string, hash []byte) error
- func Report(id uint64, board, reason, ip string, illegal bool) error
- func RollbackOnError(tx *sql.Tx, err *error)
- func SetBanners(board string, banners []assets.File) (err error)
- func SetLoadingAnimation(board string, file assets.File) (err error)
- func SetOpenBody(id uint64, body []byte) error
- func SetPostCounter(c uint64) error
- func SetPyu(c uint) error
- func SetThreadSticky(id uint64, sticky bool) error
- func SpoilerImage(id uint64) error
- func StartTransaction() (*sql.Tx, error)
- func ThreadCounter(id uint64) (uint64, error)
- func Unban(board string, id uint64, by string) error
- func UpdateBoard(c config.BoardConfigs) error
- func UseImageToken(token string) (img common.ImageCommon, err error)
- func ValidateOP(id uint64, board string) (valid bool, err error)
- func WriteBoard(tx *sql.Tx, c BoardConfigs) error
- func WriteConfigs(c config.Configs) error
- func WriteImage(tx *sql.Tx, i common.ImageCommon) error
- func WriteLoginSession(account, token string) error
- func WritePost(tx *sql.Tx, p Post) (err error)
- func WriteStaff(tx *sql.Tx, board string, staff map[string][]string) error
- func WriteThread(tx *sql.Tx, t Thread, p Post) (err error)
- type BoardConfigs
- type Post
- type PostStats
- type Thread
Constants ¶
const (
// TestConnArgs contains ConnArgs used for tests
TestConnArgs = `user=meguca password=meguca dbname=meguca_test sslmode=disable binary_parameters=yes`
)
Variables ¶
var ( // ConnArgs specifies the PostgreSQL connection arguments ConnArgs = `user=meguca password=meguca dbname=meguca sslmode=disable binary_parameters=yes` // IsTest can be overridden to not launch several infinite loops during // tests IsTest bool )
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 = errors.New("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(src, thumb []byte, img common.ImageCommon) error
AllocateImage allocates an image's file resources to their respective served directories and write its data to the database
func Ban ¶
func Ban(board, reason, by string, expires time.Time, ids ...uint64) ( ips map[string]uint64, err error, )
Ban IPs from accessing a specific board. Need to target posts. Returns all banned IPs.
func BoardCounter ¶
BoardCounter retrieves the progress counter of a board
func CanPerform ¶
func CanPerform(account, board string, action auth.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 CheckThreadNonLive ¶
Check, if a thread has live post updates disabled
func ClearTables ¶
ClearTables deletes the contents of specified DB tables. Only used for tests.
func CreateAdminAccount ¶
func CreateAdminAccount() error
CreateAdminAccount writes a fresh admin account with the default password to the database
func DeleteBoard ¶
DeleteBoard deletes a board and all of its contained threads and posts
func DeleteImage ¶
Permanently delete an image from a post
func DeletePost ¶
DeletePost marks the target post as deleted
func FindPosition ¶
func FindPosition(board, userID string) (pos auth.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 GetAllBoardCatalog ¶
GetAllBoardCatalog retrieves all threads for the "/all/" meta-board
func GetAllThreadsIDs ¶
Retrieves all threads IDs in bump order
func GetBanInfo ¶
GetBanInfo retrieves information about a specific ban
func GetBoardBans ¶
Get 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) (common.ImageCommon, error)
GetImage retrieves a thumbnailed image record from the DB
func GetModLog ¶
func GetModLog(board string) (log []auth.ModLogEntry, err error)
Retrieve moderation log for a specific board
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 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 ¶
Retrieve the board and OP of a post
func GetPostPassword ¶
GetPostPassword retrieves a post's modification password
func GetReports ¶
Read reports for a specific board. Pass "all" for global reports.
func GetSameIPPosts ¶
func GetSameIPPosts(id uint64, board string) ( posts []common.StandalonePost, err error, )
GetSameIPPosts returns posts with the same IP and on the same board as the target post
func GetThreadIDs ¶
Retrieves all threads IDs on the board in bump order with stickies first
func GetThreadMutations ¶
Retvies mutations, that can happen to posts in a thread, after the post is closed
func IncrementPyu ¶
IncrementPyu increments the pyu counter by one and returns the new counter
func InsertImage ¶
InsertImage insert and image into and existing open post
func InsertPost ¶
InsertPost inserts a post into an existing thread
func InsertThread ¶
InsertThread inserts a new thread into the database
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 LoadDB ¶
func LoadDB() (err error)
LoadDB establishes connections to RethinkDB and Redis and bootstraps both databases, if not yet done.
func ModSpoilerImage ¶
Spoiler image as a moderator
func NewImageToken ¶
NewImageToken inserts a new image allocation token into the DB and returns it's ID
func PostCounter ¶
PostCounter retrieves the current post 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 RollbackOnError ¶
RollbackOnError on error undoes the transaction on error
func SetBanners ¶
Overwrite list of banners in the DB, for a specific board
func SetLoadingAnimation ¶
Set loading animation for 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 SetThreadSticky ¶
Set the sticky field on a thread
func SpoilerImage ¶
SpoilerImage spoilers an already allocated image
func StartTransaction ¶
StartTransaction initiates a new DB transaction. It is the responsibility of the caller to commit or rollback the transaction.
func ThreadCounter ¶
ThreadCounter retrieves the progress counter of a thread
func UpdateBoard ¶
func UpdateBoard(c config.BoardConfigs) error
UpdateBoard updates board configurations
func UseImageToken ¶
func UseImageToken(token string) (img common.ImageCommon, err error)
UseImageToken deletes an image allocation token and returns the matching processed image. If no token exists, returns ErrInvalidToken.
func ValidateOP ¶
ValidateOP confirms the specified thread exists on specific board
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(tx *sql.Tx, i common.ImageCommon) error
WriteImage writes a processed image record to the DB
func WriteLoginSession ¶
WriteLoginSession writes a new user login session to the DB
func WriteStaff ¶
WriteStaff writes staff positions of a specific board. Old rows are overwritten. tx must not be nil.
Types ¶
type BoardConfigs ¶
type BoardConfigs struct { config.BoardConfigs Created time.Time }
BoardConfigs contains extra fields not exposed on database reads
type Post ¶
type Post struct { Deleted bool 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 PostStats ¶
PostStats contains post open status, body and creation time
func GetRecentPosts ¶
GetRecentPosts retrieves posts created in the thread in the last 15 minutes. Posts that are being editted also have their Body property set.