common

package
v3.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2016 License: AGPL-3.0, AGPL-3.0-or-later Imports: 3 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 = 50
	MaxLenSubject      = 100
	MaxLenBody         = 2000
	MaxLenPassword     = 50
	MaxLenUserID       = 20
	MaxLenBoardID      = 3
	MaxLenBoardTitle   = 100
	MaxLenNotice       = 500
	MaxLenRules        = 5000
	MaxLenEightball    = 2000
)

Maximum lengths of various string input fields

View Source
const (
	// LenSession defines the length of an unpadded base64-encoded account
	// login session token
	LenSession = 171
)

Variables

View Source
var (
	ErrNameTooLong         = ErrTooLong("name")
	ErrSubjectTooLong      = ErrTooLong("subject")
	ErrPostPasswordTooLong = ErrTooLong("post password")
	ErrBodyTooLong         = ErrTooLong("post body")
)

Commonly used errors

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

Functions

This section is empty.

Types

type Board

type Board []BoardThread

Board is an array stripped down version of Thread for whole-board retrieval queries. Reduces server memory usage and served JSON payload.

type BoardThread

type BoardThread struct {
	ThreadCommon
	ID    uint64 `json:"id" gorethink:"id"`
	Time  int64  `json:"time" gorethink:"time"`
	Name  string `json:"name,omitempty" gorethink:"name,omitempty"`
	Trip  string `json:"trip,omitempty" gorethink:"trip,omitempty"`
	Auth  string `json:"auth,omitempty" gorethink:"auth,omitempty"`
	Image *Image `json:"image,omitempty" gorethink:"image,omitempty"`
}

BoardThread is a stripped down version of Thread for board catalog queries

func (*BoardThread) MarshalJSON added in v3.1.0

func (mj *BoardThread) MarshalJSON() ([]byte, error)

func (*BoardThread) MarshalJSONBuf added in v3.1.0

func (mj *BoardThread) MarshalJSONBuf(buf fflib.EncodingBuffer) error

type Captcha

type Captcha struct {
	Captcha, CaptchaID string
}

Captcha stores captcha data for request messages that require it, if captchas s are enabled

func (*Captcha) MarshalJSON added in v3.1.0

func (mj *Captcha) MarshalJSON() ([]byte, error)

func (*Captcha) MarshalJSONBuf added in v3.1.0

func (mj *Captcha) MarshalJSONBuf(buf fflib.EncodingBuffer) error

type Command

type Command struct {
	Type CommandType `json:"type" gorethink:"type"`
	Val  interface{} `json:"val" gorethink:"val"`
}

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: TODO: SyncWatch storage type Pyu: int64 Pcount: int64

func (*Command) MarshalJSON added in v3.1.0

func (mj *Command) MarshalJSON() ([]byte, error)

func (*Command) MarshalJSONBuf added in v3.1.0

func (mj *Command) MarshalJSONBuf(buf fflib.EncodingBuffer) error

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 DatabasePost

type DatabasePost struct {
	StandalonePost
	LastUpdated int64    `json:"lastUpdated" gorethink:"lastUpdated"`
	IP          string   `gorethink:"ip"`
	Password    []byte   `gorethink:"password"`
	Log         [][]byte `gorethink:"log"`
}

DatabasePost is for writing new posts to a database. It contains the IP and Password fields, which are never exposed publically through Post.

func (*DatabasePost) MarshalJSON added in v3.1.0

func (mj *DatabasePost) MarshalJSON() ([]byte, error)

func (*DatabasePost) MarshalJSONBuf added in v3.1.0

func (mj *DatabasePost) MarshalJSONBuf(buf fflib.EncodingBuffer) error

type DatabaseThread

type DatabaseThread struct {
	PostCtr   uint32 `gorethink:"postCtr"`
	ImageCtr  uint32 `gorethink:"imageCtr"`
	ID        uint64 `gorethink:"id"`
	ReplyTime int64  `gorethink:"replyTime"`
	Subject   string `gorethink:"subject"`
	Board     string `gorethink:"board"`
}

DatabaseThread is a template for writing new threads to the database

func (*DatabaseThread) MarshalJSON added in v3.1.0

func (mj *DatabaseThread) MarshalJSON() ([]byte, error)

func (*DatabaseThread) MarshalJSONBuf added in v3.1.0

func (mj *DatabaseThread) MarshalJSONBuf(buf fflib.EncodingBuffer) error

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" gorethink:"spoiler,omitempty"`
	ImageCommon
	Name string `json:"name" gorethink:"name"`
}

Image contains a post's image and thumbnail data

func (*Image) MarshalJSON added in v3.1.0

func (mj *Image) MarshalJSON() ([]byte, error)

func (*Image) MarshalJSONBuf added in v3.1.0

func (mj *Image) MarshalJSONBuf(buf fflib.EncodingBuffer) error

type ImageCommon

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

ImageCommon contains the common fields of both Image and ProtoImage structs

func (*ImageCommon) MarshalJSON added in v3.1.0

func (mj *ImageCommon) MarshalJSON() ([]byte, error)

func (*ImageCommon) MarshalJSONBuf added in v3.1.0

func (mj *ImageCommon) MarshalJSONBuf(buf fflib.EncodingBuffer) error
type Link struct {
	OP    uint64 `json:"op" gorethink:"op"`
	Board string `json:"board" gorethink:"board"`
}

Link stores the target post's parent board and parent thread

func (*Link) MarshalJSON added in v3.1.0

func (mj *Link) MarshalJSON() ([]byte, error)

func (*Link) MarshalJSONBuf added in v3.1.0

func (mj *Link) MarshalJSONBuf(buf fflib.EncodingBuffer) error

type LinkMap

type LinkMap map[uint64]Link

LinkMap contains a map of post numbers, this tread is linking, to corresponding Link structs

type Post

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

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

func (*Post) MarshalJSON added in v3.1.0

func (mj *Post) MarshalJSON() ([]byte, error)

func (*Post) MarshalJSONBuf added in v3.1.0

func (mj *Post) MarshalJSONBuf(buf fflib.EncodingBuffer) error

type ProtoImage

type ProtoImage struct {
	ImageCommon
	Posts uint `gorethink:"posts"`
}

ProtoImage stores image data related to the source and thumbnail resources themselves. This struct is partially copied into the image struct on image allocation.

func (*ProtoImage) MarshalJSON added in v3.1.0

func (mj *ProtoImage) MarshalJSON() ([]byte, error)

func (*ProtoImage) MarshalJSONBuf added in v3.1.0

func (mj *ProtoImage) MarshalJSONBuf(buf fflib.EncodingBuffer) error

type StandalonePost

type StandalonePost struct {
	Post
	OP    uint64 `json:"op" gorethink:"op"`
	Board string `json:"board" gorethink:"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.

func (*StandalonePost) MarshalJSON added in v3.1.0

func (mj *StandalonePost) MarshalJSON() ([]byte, error)

func (*StandalonePost) MarshalJSONBuf added in v3.1.0

func (mj *StandalonePost) MarshalJSONBuf(buf fflib.EncodingBuffer) error

type Thread

type Thread struct {
	Post
	ThreadCommon
	Posts []Post `json:"posts" gorethink:"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.

func (*Thread) MarshalJSON added in v3.1.0

func (mj *Thread) MarshalJSON() ([]byte, error)

func (*Thread) MarshalJSONBuf added in v3.1.0

func (mj *Thread) MarshalJSONBuf(buf fflib.EncodingBuffer) error

type ThreadCommon

type ThreadCommon struct {
	Locked      bool   `json:"locked,omitempty" gorethink:"locked"`
	Archived    bool   `json:"archived,omitempty" gorethink:"archived"`
	Sticky      bool   `json:"sticky,omitempty" gorethink:"sticky"`
	PostCtr     uint32 `json:"postCtr" gorethink:"postCtr"`
	ImageCtr    uint32 `json:"imageCtr" gorethink:"imageCtr"`
	ReplyTime   int64  `json:"replyTime" gorethink:"replyTime"`
	LastUpdated int64  `json:"lastUpdated" gorethink:"lastUpdated"`
	Subject     string `json:"subject" gorethink:"subject"`
	Board       string `json:"board" gorethink:"board"`
}

ThreadCommon contains common fields of both BoardThread and Thread

func (*ThreadCommon) MarshalJSON added in v3.1.0

func (mj *ThreadCommon) MarshalJSON() ([]byte, error)

func (*ThreadCommon) MarshalJSONBuf added in v3.1.0

func (mj *ThreadCommon) MarshalJSONBuf(buf fflib.EncodingBuffer) error

Jump to

Keyboard shortcuts

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