models

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2018 License: GPL-3.0 Imports: 37 Imported by: 1

Documentation

Index

Constants

View Source
const (
	RateIP      = 10 * time.Minute
	RatePost    = 5 * time.Minute
	RateComment = 30 * time.Second

	VoteComStore = 24 * time.Hour
	VoteArtStore = 24 * time.Hour

	VoteComMax = 10
	VoteArtMax = 10
)

Variables

This section is empty.

Functions

func ArticleDelete

func ArticleDelete(lang, username string, aid uint32) (err error)

ArticleDelete delete article

func ArticleNew

func ArticleNew(a *Article) (id uint32, err error)

ArticleNew create article

func ArticleUpd

func ArticleUpd(a *Article, oldTag string) (err error)

ArticleUpd update article

func ArticleViewGet

func ArticleViewGet(lang, ip string, aid uint32) (view int)

func BintoUint32

func BintoUint32(b []byte) uint32

BintoUint32 convert to uint32

func ComLimitGet

func ComLimitGet(lang, username string) int

func ComLimitSet

func ComLimitSet(lang, username string)

func ComUpSet

func ComUpSet(lang, username, cid string) error

func CommentNew

func CommentNew(a *Article, user string, mainaid uint32) (id uint32, err error)

CommentNew create comment

func DauGet added in v1.3.2

func DauGet(lang string) int

DauGet return dau

func DauSet added in v1.3.2

func DauSet(lang, ip string)

DauSet log of dau

func FollowCount

func FollowCount(lang, cat, u string) int

FollowCount count

func Following

func Following(lang, cat, u, v string) (err error)

Following set follow

func GenerateMonster added in v1.3.2

func GenerateMonster(username string) (image.Image, error)

GenerateFromUsername generates avatar from string

func GetMasterSlave

func GetMasterSlave(master string, slave string) ([]byte, []byte)

GetMasterSlave convert to bin

func ImgProcess

func ImgProcess(s, lang, username, host string) (res string, err error)

ImgProcess extract img links from markdown, download, and replace with local copy

func IsFollowing

func IsFollowing(lang, cat, u, v string) bool

IsFollowing return IsFollowing

func IsSmtpSet added in v1.3.2

func IsSmtpSet(SMTPHost, SMTPPort, SMTPUser, SMTPPassword string) bool

func MentionDel

func MentionDel(lang, username, path string)

MentionDel remove mention for username by path

func PostLimitDel

func PostLimitDel(lang, username string)

func PostLimitGet

func PostLimitGet(lang, username string) int

func PostLimitSet

func PostLimitSet(lang, username string)

func RegisterIPGet

func RegisterIPGet(ip string) int

func RegisterIPSet

func RegisterIPSet(ip string)

func ReplyParse

func ReplyParse(s, lang string) string

ReplyParse - replace first '@username ' on markdown link and return array of username

func SaveToFile added in v1.3.2

func SaveToFile(img image.Image, filePath string) error

func Send2fcm added in v1.3.2

func Send2fcm(to string, a *Article) []byte

func SendMail added in v1.3.2

func SendMail(SMTPHost, SMTPPort, SMTPUser, SMTPPassword, Domain, address, title, body string)

SendMail send text/plain email via smtp

func SendMentions added in v1.3.2

func SendMentions(lang, SMTPHost, SMTPPort, SMTPUser, SMTPPassword, Domain string, mentions []Mention)

func Store

func Store(href, lang, username string, b []byte) (file, orig string, origSize int)

Store store file by lang/username

func TgClickableImage

func TgClickableImage(s string) string

func TgGet

func TgGet(bot, req string) (res []byte)

func TgIsAdmin

func TgIsAdmin(bot, req, admin string) (isAdmin bool, err error)

TgIsAdmin return true is username admin in channel and canpostmessages return false in case of errors (tgapi is banned, not respond)

func TgSendMsg

func TgSendMsg(bot, channel, txt, title, link, img string, msgID int) (mid int)

func Type2TeleGet

func Type2TeleGet(aid uint32) int

func Type2TeleSet

func Type2TeleSet(aid uint32, mid int)

func Uint32toBin

func Uint32toBin(id uint32) []byte

Uint32toBin convert to binary

func Unfollowing

func Unfollowing(lang, cat, u, v string) (err error)

Unfollowing remove follow

func UserBanGet

func UserBanGet(username string) bool

func UserBanSet

func UserBanSet(author string)

func UserNew

func UserNew(user *User) (err error)

UserNew - create

func UserSave

func UserSave(user *User) (err error)

UserSave - save

func ViewGet

func ViewGet(lang string, aid uint32) (v int)

ViewGet return stored counter

func ViewSet

func ViewSet(lang string, aid uint32, v int)

ViewSet counter view by aid

func VoteSet

func VoteSet(lang, username string) error

func WauGet added in v1.3.2

func WauGet(lang string) int

WauGet return wau

func Zip

func Zip(a1, a2 []string) []string

Types

type Article

type Article struct {
	ID          uint32
	Title       string `form:"title" json:"title" binding:"max=255"`
	Body        string `form:"body" json:"body" binding:"exists,min=10,max=65536"`
	Author      string
	Image       string
	OgImage     string `form:"ogimage" json:"ogimage" binding:"omitempty,url"`
	CreatedAt   time.Time
	Lang        string
	HTML        template.HTML
	Plus        uint32
	Minus       uint32
	Comments    []Article
	ReadingTime int
	WordCount   int
	Tag         string `form:"tag" json:"tag" binding:"omitempty,alphanum,max=20"`
}

Article model

func AllArticles

func AllArticles(lang, from_str, tag string) (models []Article, page string, prev, next, last uint32, err error)

AllArticles return page from list of articles

func ArticleGet

func ArticleGet(lang, username string, aid uint32) (a *Article, err error)

ArticleGet get article

func ArticlesAuthor

func ArticlesAuthor(lang, username, author, from_str string) (models []Article, page string, prev, next, last uint32, err error)

ArticlesAuthor return articles by author

func ArticlesSelect

func ArticlesSelect(lang, fAids string, from []byte, limit, offset uint32, asc bool) (models []Article, first, last uint32, err error)

func ArticlesSort

func ArticlesSort(models []Article, by string, cnt uint32) (sorted []Article, err error)

func Favorites

func Favorites(lang, u string) (articles []Article)

Favorites return 100 last Favorites

func TopArticles

func TopArticles(lang string, cnt uint32, by string) (models []Article, err error)

type FcmMsg added in v1.3.2

type FcmMsg struct {
	To   string   `json:"to"`
	Data *Article `json:"data"`
}

type Gender added in v1.3.2

type Gender int

Gender represents gender type

const (
	// MONSTER default person type
	MONSTER Gender = iota
)

type Mention

type Mention struct {
	Then       time.Time
	Path       string
	ByUsername string
	Aid        uint32
	Cid        uint32
	Text       string
	ToUsername string
}

func MentionNew

func MentionNew(s, lang, text, byuser, url, fullurl string, aid, cid uint32) (mentions []Mention)

MentionNew parce mentions

func Mentions

func Mentions(lang, username string) (mentions []Mention)

Mentions return arr of mentions

type TgMsg

type TgMsg struct {
	Ok     bool `json:"ok"`
	Result struct {
		MessageID int `json:"message_id"`
		Chat      struct {
			ID    int64  `json:"id"`
			Title string `json:"title"`
			Type  string `json:"type"`
		} `json:"chat"`
		Date int    `json:"date"`
		Text string `json:"text"`
	} `json:"result"`
}

type TgUsers

type TgUsers struct {
	Ok     bool `json:"ok"`
	Result []struct {
		User struct {
			ID        int    `json:"id"`
			IsBot     bool   `json:"is_bot"`
			FirstName string `json:"first_name"`
			Username  string `json:"username"`
		} `json:"user"`
		Status             string `json:"status"`
		CanBeEdited        bool   `json:"can_be_edited,omitempty"`
		CanChangeInfo      bool   `json:"can_change_info,omitempty"`
		CanPostMessages    bool   `json:"can_post_messages,omitempty"`
		CanEditMessages    bool   `json:"can_edit_messages,omitempty"`
		CanDeleteMessages  bool   `json:"can_delete_messages,omitempty"`
		CanInviteUsers     bool   `json:"can_invite_users,omitempty"`
		CanRestrictMembers bool   `json:"can_restrict_members,omitempty"`
		CanPromoteMembers  bool   `json:"can_promote_members,omitempty"`
	} `json:"result"`
}

type User

type User struct {
	Username       string `form:"username" json:"username" binding:"exists,alphanum,min=1,max=20"`
	Email          string `form:"email" json:"email" binding:"omitempty,email"`
	Password       string `form:"password" json:"password" binding:"exists,min=6,max=255"`
	NewPassword    string `form:"newpassword" json:"newpassword" binding:"omitempty,min=6,max=255"`
	Bio            string `form:"bio" json:"bio" binding:"max=1024"`
	Image          string `form:"image" json:"image" binding:"omitempty,url"`
	Lang           string
	PasswordHash   string `json:"-"`
	LastPost       uint32 `json:"-"`
	Unseen         uint32 `json:"-"`
	IP             string `json:"-"`
	NoJs           bool   `json:"-"`
	Type2Telegram  string `json:"-"`
	Type2TeleNoTxt bool   `json:"-"`
}

User model

func IFollow

func IFollow(lang, cat, u string) (followings []User)

IFollow return users which i follow

func UserCheckGet

func UserCheckGet(lang, username, password string) (u *User, err error)

UserCheckGet check

func UserGet

func UserGet(lang, username string) (u *User, err error)

UserGet return user

Jump to

Keyboard shortcuts

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