Documentation ¶
Index ¶
- Constants
- Variables
- func EscapeTag(name string) string
- func NameIsLegal(name string) error
- func TagIsValid(tagName string) error
- type ErrResponse
- type Permission
- func (p Permission) HasPermOverUser(min, target Permission, isSelf bool) error
- func (p Permission) HasPermission(min Permission, inclusive bool) error
- func (p Permission) IsUserOrHasPermOver(min, target Permission, isSelf bool) error
- func (p Permission) IsValid() bool
- func (p Permission) String() string
- func (p Permission) StringInt() string
- type Post
- type PostAttribute
- type PostExtended
- type PostTag
- type Query
- type SearchResults
- type Session
- type Token
- type TokenList
- type User
- type UserList
- type UserPart
Constants ¶
const HashCost = 12
HashCost controls the bcrypt hash cost.
const MaxTagLen = 128
const MaxUsernameLen = 128
MaxUsernameLen is the maximum username length.
const MinimumPassLength = 8
MinimumPassLength defines the minimum length of a password.
const QueryTagLimit = 1024
QueryTagLimit is the maximum number of tags allowed in a single query.
Variables ¶
var ( ErrMissingExt = httperr.New(400, "file does not have extension") ErrPostNotFound = httperr.New(404, "post not found") ErrPageCountLimit = httperr.New(400, "count is over 100 limit") )
var ( ErrEmptyTag = httperr.New(400, "empty tag not allowed") ErrIllegalTag = httperr.New(400, "tag contains illegal character") ErrTagAlreadyAdded = httperr.New(400, "tag is already added") ErrTagTooLong = httperr.New(400, fmt.Sprintf("tag is too long (max %d)", MaxTagLen)) )
var ( ErrQueryAlreadyHasUser = httperr.New(400, "search query already has a user filter") ErrQueryHasTooMayTags = httperr.New(400, "search query has too many tags") )
var ( ErrSessionNotFound = httperr.New(401, "session not found") ErrSessionExpired = httperr.New(410, "session expired") )
var ( ErrUnknownToken = httperr.New(401, "unknown token") ErrOverUseLimit = httperr.New(400, "requested use is over limit") ErrZeroNotAllowed = httperr.New(400, "zero use not allowed") )
var ( ErrOwnerAccountStays = httperr.New(400, "owner account stays") ErrActionNotPermitted = httperr.New(403, "action not permitted") ErrUserNotFound = httperr.New(404, "user not found") ErrInvalidPassword = httperr.New(401, "invalid password") ErrPasswordTooShort = httperr.New(400, "password too short") ErrUsernameTooLong = httperr.New(400, "username too long") ErrUsernameTaken = httperr.New(409, "username taken") ErrIllegalName = httperr.New(403, "username contains illegal characters") )
var AllPosts = Query{}
AllPosts searches for all posts; it is a zero value instance of PostQuery.
var ErrInvalidPermission = httperr.New(400, "invalid permission")
var NoResults = SearchResults{}
NoResults contains no search results; it is a zero value instance of PostQueryResults.
var NoUsers = UserList{}
NoUsers is a zero-value user list containing no users.
Functions ¶
func NameIsLegal ¶
NameIsLegal returns whether or not name contains illegal characters. It returns nil if the name does not contain any.
Legal runes include: digits, letters and an underscore.
func TagIsValid ¶
TagIsValid returns nil if the tag is valid else an error. A tag is invalid if it's empty, it's longer than 128 bytes, it's prefixed with an at sign "@" or it contains anything not a graphical character defined by the Unicode standards.
Types ¶
type ErrResponse ¶
type ErrResponse struct {
Error string `json:"error"`
}
ErrResponse is the structure of the response when the request returns an error.
type Permission ¶
type Permission int8
const ( // PermissionGuest is the zero-value of permission, which indicates a guest. PermissionGuest Permission = iota // PermissionUser is a normal user's base permission. It allows uploading. PermissionUser // PermissionTrusted has access to posts marked as trusted-only. Trusted // users can mark a post as trusted. PermissionTrusted // PermissionAdministrator can create limited use tokens as well as banning // and promoting people up to Trusted. This permission inherits all // permissions above. PermissionAdministrator // PermissionOwner indicates the owner of the image board. The owner can // create unlimited tokens and inherits all permissions above. They are also // the only person that can promote a person to Administrator. PermissionOwner // if username == Owner )
func AllPermissions ¶
func AllPermissions() []Permission
AllPermissions returns all possible permissions in a slice. It starts with the lowest (guest) and ends with the highest (owner).
func (Permission) HasPermOverUser ¶
func (p Permission) HasPermOverUser(min, target Permission, isSelf bool) error
HasPermOverUser returns nil if the current user (self) has permission over the target user with the given lowest permission required. If target is -1, then PermissionAdministrator is assumed. This is done for deleted accounts.
func (Permission) HasPermission ¶
func (p Permission) HasPermission(min Permission, inclusive bool) error
func (Permission) IsUserOrHasPermOver ¶
func (p Permission) IsUserOrHasPermOver(min, target Permission, isSelf bool) error
func (Permission) IsValid ¶
func (p Permission) IsValid() bool
IsValid returns true if the permission is valid.
func (Permission) String ¶
func (p Permission) String() string
func (Permission) StringInt ¶
func (p Permission) StringInt() string
Int returns the permission as a stringed integer enum. This should only be used for form values and the like.
type Post ¶
type Post struct { ID int64 `json:"id" db:"id"` Size int64 `json:"size" db:"size"` Poster *string `json:"poster" db:"poster"` ContentType string `json:"content_type" db:"contenttype"` Permission Permission `json:"permission" db:"permission"` Attributes PostAttribute `json:"attributes" db:"attributes"` }
func (Post) CreatedTime ¶
CreatedTime returns the time the post was created. It's milliseconds accurate.
type PostAttribute ¶
type PostAttribute struct { Width int `json:"w,omitempty"` Height int `json:"h,omitempty"` Blurhash string `json:"blurhash,omitempty"` }
func (*PostAttribute) Scan ¶
func (a *PostAttribute) Scan(v interface{}) error
type PostExtended ¶
type PostExtended struct { Post // PosterUser is non-nil if the poster is not null. PosterUser *UserPart `json:"poster_user"` // Tags is manually queried externally. Tags []PostTag `json:"tags"` }
PostExtended is the type for a post with queried tags and the poster user. This struct is returned from /posts/:id.
type PostTag ¶
type Query ¶
Query represents the parsed query string. A zero-value PostQuery searches for nothing and thus will list all posts.
func ParsePostQuery ¶
ParsePostQuery parses a search string to query the post gallery. The syntax is space-delimited optionally quoted tags with an optional prefix in front to indicate a post author. A post author search may only appear once. Below is an example:
tag1 "tag with space" 'more spaces' @diamondburned
type SearchResults ¶
type SearchResults struct { // Posts contains the paginated list of posts. Posts []Post `json:"posts"` // Total is the total number of posts found. It is zero if Posts is empty. Total int `json:"total"` // Sizes is the total size of all posts found. It is zero if Posts is empty. Sizes int64 `json:"sizes"` // User is the user stated in the search query. It is nil if there's no user // stated. User *UserPart `json:"user,omitempty"` }
SearchResults is the results returned from the queried posts.
type Session ¶
type Session struct { ID int64 `json:"id" db:"id"` Username string `json:"username" db:"username"` // AuthToken is the token stored in the cookies. If the session isn't the // current one, then AuthToken will be empty. AuthToken string `json:"auth_token,omitempty" db:"authtoken"` // Deadline is gradually updated with each Session call, which is per // request. Deadline int64 `json:"deadline" db:"deadline"` // UserAgent is obtained once on login. UserAgent string `json:"user_agent" db:"useragent"` }
type TokenList ¶
type TokenList struct { Tokens []Token `json:"tokens"` Creators map[string]UserPart `json:"creators"` MaxUses int `json:"max_uses"` SelfPerm Permission `json:"self_perm"` }
type UserPart ¶
type UserPart struct { Username string `db:"username" json:"username"` JoinTime int64 `db:"jointime" json:"join_time"` Permission Permission `db:"permission" json:"permission"` }
UserPart contains non-sensitive parts about the user.
func (UserPart) AllowedPermissions ¶
func (u UserPart) AllowedPermissions() []Permission
AllowedPermissions returns the list of allowed permissions this user can set on their post.
func (UserPart) CanChangePost ¶
CanChangePost returns nil if the user can change the given post. This is kept in sync with the backend functions.
func (UserPart) CanSetPostPermission ¶
func (u UserPart) CanSetPostPermission(p PostExtended, target Permission) error
CanSetPostPermission returns nil if the user can change the post's permission to target. This is kept in sync with the backend functions.