Documentation ¶
Overview ¶
TODO(Kagami): Somehow merge with server/errors.go
Package common contains common shared types, variables and constants used throughout the project.
Index ¶
- Constants
- Variables
- func EncodeMessage(typ MessageType, msg interface{}) ([]byte, error)
- func PrependMessageType(typ MessageType, data []byte) []byte
- type Backlinks
- type Board
- type Client
- type Command
- type CommandType
- type Commands
- type ErrInvalidPostID
- type ErrTooLong
- type Files
- type Image
- type ImageCommon
- type Links
- type MessageType
- type NewsEntry
- type Post
- type Posts
- type React
- type Reacts
- type SmileCommon
- type StandalonePost
- type Thread
Constants ¶
const ( JPEG uint8 = iota PNG GIF WEBM PDF SVG MP4 MP3 FLAC OGG ZIP SevenZip TGZ TXZ )
Supported file formats. MUST BE KEPT IN SYNC WITH ts/common/index.ts!
const ( MaxLenName = 50 MaxLenAuth = 50 MaxLenSubject = 100 MaxLenBody = 4000 MaxLinesBody = 100 MaxLenPassword = 50 MaxLenUserID = 32 MaxLenBoardID = 10 MaxLenBoardTitle = 100 MaxBanReasonLength = 100 MaxLenIgnoreList = 100 MaxLenStaffList = 1000 MaxLenBansList = 1000 )
Maximum lengths of various input fields
const ( LenSession = 171 LenImageToken = 86 )
Various cryptographic token exact lengths
const ( SessionExpiry = 5 * 365 // Days DefaultMaxSize = 40 // Megabytes DefaultMaxFiles = 5 DefaultCSS = "light" DefaultAdminPassword = "password" ThreadsPerPage = 20 NumPostsAtIndex = 3 NumPostsOnRequest = 100 )
Some default options.
Variables ¶
var ( ErrNameTooLong = ErrTooLong("Name") ErrNoSubject = errors.New("No subject") ErrSubjectTooLong = ErrTooLong("Subject") ErrBodyTooLong = ErrTooLong("Post body") ErrInvalidCreds = errors.New("Invalid login credentials") ErrContainsNull = errors.New("Null byte in non-concatenated message") )
Commonly used errors
var ( WebRoot string ImageWebRoot string )
Server paths
var ( // GetByIPAndBoard retrieves all Clients that match the passed IP on a board GetByIPAndBoard func(ip, board string) []Client // SendTo sends a message to a feed, if it exists SendTo func(id uint64, msg []byte) // SendToBoard sends a message to a board feeds, if it exists SendToBoard func(id string, msg []byte) // ClosePost closes a post in a feed, if it exists ClosePost func(id, op uint64, msg []byte) // Propagate a message about a post being banned BanPost func(id, op uint64) error // Propagate a message about a post being deleted DeletePost func(id, op uint64) error // Propagate a message about an image being deleted from a post DeleteImage func(id, op uint64) error // Propagate a message about an image being spoilered SpoilerImage func(id, op uint64) error )
Forwarded functions from "meguca/feeds" to avoid circular imports
var Extensions = map[uint8]string{ JPEG: "jpg", PNG: "png", GIF: "gif", MP3: "mp3", FLAC: "flac", MP4: "mp4", WEBM: "webm", OGG: "ogg", PDF: "pdf", ZIP: "zip", SevenZip: "7z", TGZ: "tar.gz", TXZ: "tar.xz", }
Extensions maps internal file types to their canonical file extensions.
var (
Themes = []string{
"light", "dark",
}
)
Available themes. Change this, when adding any new ones.
Functions ¶
func EncodeMessage ¶
func EncodeMessage(typ MessageType, msg interface{}) ([]byte, error)
EncodeMessage encodes a message for sending through websockets or writing to the replication log.
func PrependMessageType ¶
func PrependMessageType(typ MessageType, data []byte) []byte
PrependMessageType prepends the encoded websocket message type to an already encoded message
Types ¶
type Board ¶
type Board []Thread
Board is defined to enable marshalling optimizations and sorting by sticky threads.
type Client ¶
Client exposes some globally accessible websocket client functionality without causing circular imports
type Command ¶
type Command struct { Type CommandType Roll int Flip bool }
func (Command) MarshalEasyJSON ¶
Dynamically marshal the appropriate fields by struct type.
func (Command) MarshalJSON ¶
func (*Command) UnmarshalJSON ¶
Decode a dynamically-typed JSON-encoded command into the statically-typed Command struct.
type CommandType ¶
type CommandType uint8
const ( // Roll number between X and Y. Roll CommandType = iota // Flip coin with X% probability. Flip )
type ErrInvalidPostID ¶
type ErrInvalidPostID uint64
ErrInvalidPostID signifies that the post ID passed by the client is invalid in some way. In what way exactly should be evident from the API endpoint.
func (ErrInvalidPostID) Error ¶
func (e ErrInvalidPostID) Error() string
type ErrTooLong ¶
type ErrTooLong string
ErrTooLong is passed, when a field exceeds the maximum string length for that specific field
func (ErrTooLong) Error ¶
func (e ErrTooLong) Error() string
type ImageCommon ¶
type ImageCommon struct { SHA1 string Size int `json:"size"` Video bool `json:"video,omitempty"` Audio bool `json:"audio,omitempty"` APNG bool `json:"apng,omitempty"` FileType uint8 `json:"fileType"` ThumbType uint8 `json:"thumbType"` Length uint32 `json:"length,omitempty"` Title string `json:"title,omitempty"` Dims [4]uint16 `json:"dims"` MD5 string `json:"-"` Artist string `json:"-"` }
ImageCommon contains the common data shared between multiple post referencing the same image.
type MessageType ¶
type MessageType uint8
MessageType is the identifier code for websocket message types
const ( MessageInvalid MessageType = iota MessageInsertPost MessageAppend MessageBackspace MessageSplice MessageClosePost ReactToPost MessageInsertImage MessageSpoiler MessageDeletePost MessageBanned MessageDeleteImage MessageReacted )
1 - 29 modify post model state
const ( MessageSynchronise MessageType = 30 + iota MessageReclaim // Send new post ID to client MessagePostID // Concatenation of multiple websocket messages to reduce transport overhead MessageConcat // Message from the client meant to invoke no operation. Mostly used as a // one way ping, because the JS Websocket API does not provide access to // pinging. MessageNOOP // Transmit current synced IP count to client MessageSyncCount // Send current server Unix time to client MessageServerTime // Redirect the client to a specific board MessageRedirect // Send a notification to a client MessageNotification // Notify the client, he needs a captcha solved MessageCaptcha SmilesUpdated )
>= 30 are miscellaneous and do not write to post models
type NewsEntry ¶
Single news entry. TODO(Kagami): Need to use in both templates/ and db/ and can't keep in db/ because of cyclic imports. Move to some better place.
type Post ¶
type Post struct { ID uint64 `json:"id"` Time int64 `json:"time"` Auth string `json:"auth,omitempty"` UserID string `json:"userID,omitempty"` UserName string `json:"userName,omitempty"` Settings string `json:"settings,omitempty"` UserColor string `json:"userColor,omitempty"` ShowColor bool `json:"ShowColor,omitempty"` Body string `json:"body"` Links Links `json:"links,omitempty"` Commands Commands `json:"commands,omitempty"` Files Files `json:"files,omitempty"` Reacts Reacts `json:"reacts"` }
Post is a generic post exposed publically through the JSON API.
type React ¶
type React struct { Count uint64 `json:"count"` PostID uint64 `json:"postId"` Self bool `json:"self,omitempty"` Smile SmileCommon `json:"smile,omitempty"` }
type SmileCommon ¶
type StandalonePost ¶
StandalonePost is a post view that includes the "op" and "board" fields, which are not exposed though Post, but are required for retrieving a post with unknown parenthood.
type Thread ¶
type Thread struct { Abbrev bool `json:"abbrev,omitempty"` Sticky bool `json:"sticky,omitempty"` PostCtr uint32 `json:"postCtr"` ImageCtr uint32 `json:"imageCtr"` ReplyTime int64 `json:"replyTime"` BumpTime int64 `json:"bumpTime"` Subject string `json:"subject"` Board string `json:"board"` *Post Posts Posts `json:"posts"` }
Thread is a transport/export wrapper that stores both the thread metadata, its opening post data and its contained posts. The composite type itself is not stored in the database.