common

package
v4.1.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2017 License: AGPL-3.0, AGPL-3.0-or-later Imports: 7 Imported by: 0

Documentation

Overview

Package common contains common shared types, variables and constants used throughout the project

Index

Constants

View Source
const (
	JPEG = iota
	PNG
	GIF
	WEBM
	PDF
	SVG
	MP4
	MP3
	OGG
	ZIP
	SevenZip
	TGZ
	TXZ
)

Supported file formats

View Source
const (
	MaxLenName         = 50
	MaxLenAuth         = 50
	MaxLenPostPassword = 100
	MaxLenSubject      = 100
	MaxLenBody         = 2000
	MaxLinesBody       = 100
	MaxLenPassword     = 50
	MaxLenUserID       = 20
	MaxLenBoardID      = 3
	MaxLenBoardTitle   = 100
	MaxLenNotice       = 500
	MaxLenRules        = 5000
	MaxLenEightball    = 2000
	MaxBanReasonLength = 100
)

Maximum lengths of various string input fields

View Source
const (
	LenSession    = 171
	LenImageToken = 86
)

Various cryptographic token exact lengths

Variables

View Source
var (
	ErrNameTooLong         = ErrTooLong("name")
	ErrSubjectTooLong      = ErrTooLong("subject")
	ErrPostPasswordTooLong = ErrTooLong("post password")
	ErrBodyTooLong         = ErrTooLong("post body")
	ErrInvalidCreds        = errors.New("invalid login credentials")
	ErrContainsNull        = errors.New("null byte in non-concatenated message")
)

Commonly used errors

View Source
var (
	Langs = []string{
		"en_GB", "es_ES", "pl_PL", "pt_BR", "sk_SK", "tr_TR", "uk_UA",
	}
	Themes = []string{
		"ashita", "console", "gar", "glass", "higan", "inumi", "mawaru", "moe",
		"moon", "ocean", "rave", "tea",
	}
)

Available language packs and themes. Change this, when adding any new ones.

View Source
var (
	CommandRegexp = regexp.MustCompile(`^#(flip|\d*d\d+|8ball|pyu|pcount|sw(?:\d+:)?\d+:\d+(?:[+-]\d+)?)$`)
	DiceRegexp    = regexp.MustCompile(`(\d*)d(\d+)`)
)

Common Regex expressions

View Source
var Clients interface {
	Clear()
	GetByIP(ip string) []Client
}

Clients exposes the global client map to all packages without causing circular imports

View Source
var Extensions = map[uint8]string{
	JPEG:     "jpg",
	PNG:      "png",
	GIF:      "gif",
	MP3:      "mp3",
	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

View Source
var ParseBody func([]byte, string) ([][2]uint64, []Command, error)

ParseBody forwards parser.ParseBody to avoid cyclic imports in db/upkeep

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 a slice of threads. Defined to enable marshalling optimizations.

type Client

type Client interface {
	Redirect(board string)
}

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) MarshalEasyJSON

func (c Command) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON implements easyjson.Marshaler. Defined manually to dynamically marshal the appropriate fields by struct type.

func (Command) MarshalJSON

func (c Command) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*Command) UnmarshalJSON

func (c *Command) UnmarshalJSON(data []byte) error

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
	// episode time during group anime watching and such
	SyncWatch

	// Pyu - don't ask
	Pyu

	// Pcount - don't ask
	Pcount
)

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 Image

type Image struct {
	Spoiler bool `json:"spoiler,omitempty"`
	ImageCommon
	Name string `json:"name"`
}

Image contains a post's image and thumbnail data

type ImageCommon

type ImageCommon struct {
	APNG  bool `json:"apng,omitempty"`
	Audio bool `json:"audio,omitempty"`
	// Only used for file formats like OGG and MP4 that may or may not contain
	// video
	Video     bool      `json:"video,omitempty"`
	FileType  uint8     `json:"fileType"`
	ThumbType uint8     `json:"thumbType"`
	Length    uint32    `json:"length,omitempty"`
	Dims      [4]uint16 `json:"dims"`
	Size      int       `json:"size"`
	MD5       string
	SHA1      string
}

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
	MessageInsertThread
	MessageInsertPost
	MessageAppend
	MessageBackspace
	MessageSplice
	MessageClosePost
	MessageBacklink
	MessageInsertImage
	MessageSpoiler
	MessageDeletePost
	MessageBanned
)

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
)

>= 30 are miscellaneous and do not write to post models

type Post

type Post struct {
	Editing   bool        `json:"editing,omitempty"`
	Banned    bool        `json:"banned,omitempty"`
	ID        uint64      `json:"id"`
	Time      int64       `json:"time"`
	Body      string      `json:"body"`
	Name      string      `json:"name,omitempty"`
	Trip      string      `json:"trip,omitempty"`
	Auth      string      `json:"auth,omitempty"`
	Links     [][2]uint64 `json:"links,omitempty"`
	Backlinks [][2]uint64 `json:"backlinks,omitempty"`
	Commands  []Command   `json:"commands,omitempty"`
	Image     *Image      `json:"image,omitempty"`
}

Post is a generic post exposed publically through the JSON API. Either OP or reply.

type StandalonePost

type StandalonePost struct {
	Post
	OP    uint64 `json:"op"`
	Board string `json:"board"`
}

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"`
	Locked    bool   `json:"locked,omitempty"`
	PostCtr   uint32 `json:"postCtr"`
	ImageCtr  uint32 `json:"imageCtr"`
	ReplyTime int64  `json:"replyTime"`
	BumpTime  int64  `json:"bumpTime"`
	LogCtr    uint64 `json:"logCtr"`
	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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL