Documentation
¶
Overview ¶
Package common contains common shared types, variables and constants used throughout the project
Index ¶
- Constants
- Variables
- func CanIgnoreClientError(err error) bool
- func EncodeMessage(typ MessageType, msg interface{}) ([]byte, error)
- func ErrAccessDenied(s string) error
- func ErrInvalidBoard(board string) error
- func ErrInvalidInput(s string) error
- func ErrInvalidThread(id uint64, board string) error
- func ErrNonPrintable(r rune) error
- func ErrTooLong(s string) error
- func PrependMessageType(typ MessageType, data []byte) []byte
- type Board
- type Client
- type Command
- type CommandType
- type Image
- type ImageCommon
- type Link
- type MessageType
- type ModerationAction
- type ModerationEntry
- type ModerationLevel
- type Post
- type StandalonePost
- type StatusError
- type Thread
Constants ¶
const ( JPEG uint8 = iota PNG GIF WEBM PDF SVG MP4 MP3 OGG ZIP SevenZip TGZ TXZ FLAC NoFile TXT WEBP RAR CBZ CBR AAC WAV MIDI )
Supported file formats
const ( MaxLenName = 50 MaxLenAuth = 50 MaxLenPostPassword = 100 MaxLenSubject = 80 MaxLenBody = 20000 MaxLinesBody = 30 MaxLenPassword = 50 MaxLenUserID = 20 MaxLenBoardID = 10 MaxLenBoardTitle = 100 MaxLenNotice = 500 MaxLenRules = 5000 MaxLenEightball = 2000 MaxLenReason = 100 MaxNumBanners = 20 MaxAssetSize = 100 << 10 MaxDiceSides = 10000 BumpLimit = 1000 )
Maximum lengths of various input fields
const ( LenSession = 171 LenImageToken = 86 )
Various cryptographic token exact lengths
const ProtocolVersion = 1
ProtocolVersion is the websocket protocol version
Variables ¶
var ( ErrNameTooLong = ErrTooLong("name") ErrSubjectTooLong = ErrTooLong("subject") ErrPostPasswordTooLong = ErrTooLong("post password") ErrBodyTooLong = ErrTooLong("post body") ErrContainsNull = ErrInvalidInput("null byte in message") ErrInvalidCaptcha = ErrInvalidInput("captcha") ErrInvalidCreds = ErrAccessDenied("login credentials") ErrBanned = ErrAccessDenied("you are banned from this board") ErrTooManyConnections = ErrAccessDenied("too many connections") ErrNoPermissions = ErrAccessDenied("insufficient permissions") // The poster is almost certainly spamming ErrSpamDected = ErrAccessDenied("spam detected") )
Commonly used errors
var ( // GetVideoNames is a forwarded function // from "github.com/filteredfm/ffmboardassets" to avoid circular imports GetVideoNames func() []string // Recompile is a forwarded function // from "github.com/filteredfm/ffmboardtemplates" to avoid circular imports Recompile func() error // Project is being unit tested IsTest bool // Currently running inside CI IsCI = os.Getenv("CI") == "true" )
var ( Langs = []string{ "en_GB", } Themes = []string{ "dark", "light", "altdark", "chanblue", "gar", "higan", "inumi", "tea", "win95", } )
Available language packs and themes. Change this, when adding any new ones.
var ( CommandRegexp = regexp.MustCompile(`^#(flip|\d*d\d+|8ball|pyu|pcount|timer(?:\d+:)?\d+:\d+(?:[+-]\d+)?|autobahn)$`) DiceRegexp = regexp.MustCompile(`(\d*)d(\d+)`) )
Common Regex expressions
var ( // GetByIPAndBoard retrieves all Clients that match the passed IP on a board GetByIPAndBoard func(ip, board string) []Client // GetClientsByIP returns connected clients with matching ips GetClientsByIP func(ip string) []Client // SendTo sends a message to a feed, if it exists SendTo func(id uint64, msg []byte) // ClosePost closes a post in a feed, if it exists ClosePost func(id, op uint64, links []Link, commands []Command) error )
Forwarded functions from "github.com/filteredfm/ffmboardwebsockets/feeds" to avoid circular imports
var Extensions = map[uint8]string{ JPEG: "jpg", PNG: "png", GIF: "gif", WEBP: "webp", MP3: "mp3", MP4: "mp4", WEBM: "webm", OGG: "ogg", PDF: "pdf", ZIP: "zip", SevenZip: "7z", TGZ: "tar.gz", TXZ: "tar.xz", FLAC: "flac", TXT: "txt", RAR: "rar", CBZ: "cbz", CBR: "cbr", AAC: "aac", WAV: "wav", MIDI: "midi", }
Extensions maps internal file types to their canonical file extensions
var ParseBody func([]byte, string, uint64, uint64, string, bool) ([]Link, []Command, error)
ParseBody forwards parser.ParseBody to avoid cyclic imports in db/upkeep TODO: Clean up this function signature
Functions ¶
func CanIgnoreClientError ¶
CanIgnoreClientError returns, if client-caused error can be safely ignored and not logged
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 ErrAccessDenied ¶
ErrAccessDenied is an error that user does not have enough access rights
func ErrInvalidBoard ¶
ErrInvalidBoard is an error that an invalid board was provided
func ErrInvalidInput ¶
ErrInvalidInput is an error that invalid user input was supplied
func ErrInvalidThread ¶
ErrInvalidThread is an error that no such thread on this board
func ErrNonPrintable ¶
ErrNonPrintable is an error that user input has non-printable runes
func ErrTooLong ¶
ErrTooLong is passed, when a field exceeds the maximum string length for that specific field
func PrependMessageType ¶
func PrependMessageType(typ MessageType, data []byte) []byte
PrependMessageType prepends the encoded websocket message type to an already encoded message
Types ¶
type Client ¶
type Client interface { Send([]byte) Redirect(board string) IP() string LastTime() int64 Close(error) }
Client exposes some globally accessible websocket client functionality without causing circular imports
type Command ¶
type Command struct { Type CommandType Flip bool Pyu uint64 SyncWatch [5]uint64 Eightball string Dice []uint16 }
Command contains the type and value array of hash commands, such as dice rolls, #flip, #8ball, etc. The Val field depends on the Type field. Dice: []uint16 Flip: bool EightBall: string SyncWatch: [5]uint64 Pyu: uint64 Pcount: uint64
func (Command) MarshalJSON ¶
MarshalJSON implements json.Marshaler
func (*Command) UnmarshalJSON ¶
UnmarshalJSON decodes a dynamically-typed JSON-encoded command into the statically-typed Command struct
type CommandType ¶
type CommandType uint8
CommandType are the various struct types of hash commands and their responses, such as dice rolls, #flip, #8ball, etc.
const ( // Dice is the dice roll command type Dice CommandType = iota // Flip is the coin flip command type Flip // EightBall is the the #8ball random answer dispenser command type EightBall // SyncWatch is the synchronized timer command type for synchronizing // audio/video time among everyone in a thread SyncWatch // Pyu - don't ask Pyu // Pcount - don't ask Pcount // Autobahn - self ban. brum brum Autobahn )
type Image ¶
type Image struct { Spoiler bool `json:"spoiler"` ImageCommon Name string `json:"name"` }
Image contains a post's image and thumbnail data
type ImageCommon ¶
type ImageCommon struct { Audio bool `json:"audio"` Video bool `json:"video"` FileType uint8 `json:"file_type"` ThumbType uint8 `json:"thumb_type"` Length uint32 `json:"length"` Dims [4]uint16 `json:"dims"` Size int `json:"size"` Artist string `json:"artist"` Title string `json:"title"` MD5 string `json:"md5"` SHA1 string `json:"sha1"` }
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 MessageInsertImage MessageSpoiler MessageModeratePost )
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 // Passes MeguTV playlist data MessageMeguTV // Used by the client to send it's protocol version and by the server to // send server and board configurations MessageConfigs // Set a cookie on the client MessageSetCookie )
>= 30 are miscellaneous and do not write to post models
type ModerationAction ¶
type ModerationAction uint8
ModerationAction is an action performable by moderation staff
const ( BanPost ModerationAction = iota UnbanPost DeletePost DeleteImage SpoilerImage LockThread DeleteBoard ViewSameIP PurgePost ShadowBinPost )
All supported moderation actions
type ModerationEntry ¶
type ModerationEntry struct { Type ModerationAction `json:"type"` Length uint64 `json:"length"` By string `json:"by"` Data string `json:"data"` }
Contains fields of a post moderation log entry
type ModerationLevel ¶
type ModerationLevel int8
ModerationLevel defines the level required to perform an action or the permission level held by a user
const ( NotLoggedIn ModerationLevel = iota - 1 NotStaff Janitor Moderator BoardOwner Admin )
All available moderation levels
func (ModerationLevel) String ¶
func (l ModerationLevel) String() string
Returns string representation of moderation level
type Post ¶
type Post struct { Editing bool `json:"editing"` Moderated bool `json:"-"` Sage bool `json:"sage"` Auth ModerationLevel `json:"auth"` ID uint64 `json:"id"` Time int64 `json:"time"` Body string `json:"body"` Flag string `json:"flag"` Name string `json:"name"` Trip string `json:"trip"` Image *Image `json:"image"` Links []Link `json:"links"` Commands []Command `json:"commands"` Moderation []ModerationEntry `json:"moderation"` }
Post is a generic post exposed publically through the JSON API. Either OP or reply.
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 StatusError ¶
StatusError is a simple error with HTTP status code attached
func (StatusError) Error ¶
func (e StatusError) Error() string
type Thread ¶
type Thread struct { Abbrev bool `json:"abbrev"` Sticky bool `json:"sticky"` Locked bool `json:"locked"` PostCount uint32 `json:"post_count"` ImageCount uint32 `json:"image_count"` UpdateTime int64 `json:"update_time"` BumpTime int64 `json:"bump_time"` Subject string `json:"subject"` Board string `json:"board"` Post Posts []Post `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.