model

package
v0.0.0-...-b111a5f Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FlarumAPIPath flarum 的api位置
	FlarumAPIPath      = "/api/v1/flarum"
	FlarumAdminPath    = "/admin"
	FlarumExtensionAPI = "/api/extensions" // 用于网站管理员
)

Variables

View Source
var DefaultPreference = flarum.Preferences{
	Locale: "en",
}

Functions

func AddNewArticleList

func AddNewArticleList(cid uint64, rankItems []ArticleRankItem)

AddNewArticleList 为某个分类添加话题

func ContentFmt

func ContentFmt(input string) string

ContentFmt 处理markdown样式

func ContentRich

func ContentRich(input string) string

ContentRich 用来转换文本, 转义以及允许用户添加一些富文本样式 该函数效率奇差, 但不会优化

func CreateActionRecord

func CreateActionRecord(gormDB *gorm.DB, userID uint64, postData string) error

func FlarumCreateCurrentUser

func FlarumCreateCurrentUser(user User) flarum.Resource

FlarumCreateCurrentUser 创建用户资源

func FlarumCreateDiscussion

func FlarumCreateDiscussion(topic Topic) flarum.Resource

FlarumCreateDiscussion 创建帖子资源

func FlarumCreateForumInfo

func FlarumCreateForumInfo(
	user *User,
	appConf AppConf,
	siteInfo SiteInfo,
	tags []flarum.Resource,
) flarum.Resource

FlarumCreateForumInfo 从SiteInfo创建ForumInfo tags 当前站点具有的标签集合, TODO: 缓存

func FlarumCreateGroup

func FlarumCreateGroup() flarum.Resource

FlarumCreateGroup 创建组信息

func FlarumCreateLocale

func FlarumCreateLocale(coreData *flarum.CoreData, locale string)

FlarumCreateLocale 生成语言包配置

func FlarumCreatePost

func FlarumCreatePost(comment Comment, currentUser *User) flarum.Resource

FlarumCreatePost 创建评论

func FlarumCreatePostRelations

func FlarumCreatePostRelations(postArr []flarum.Resource, comments []uint64) flarum.IRelation

FlarumCreatePostRelations 创建关系结构

func FlarumCreateTag

func FlarumCreateTag(cat Tag) flarum.Resource

FlarumCreateTag 创建tag资源

func FlarumCreateTagRelations

func FlarumCreateTagRelations(tagArr []flarum.Resource) flarum.IRelation

FlarumCreateTagRelations 创建关系结构

func FlarumCreateUser

func FlarumCreateUser(user User) flarum.Resource

FlarumCreateUser 创建用户资源

func FlarumCreateUserLikeRelations

func FlarumCreateUserLikeRelations(userList []uint64) flarum.RelationArray

FlarumCreateUserLikeRelations 点赞关系

func GetArticleCntFromRedisDB

func GetArticleCntFromRedisDB(redisDB *redis.Client, aid uint64) uint64

GetArticleCntFromRedisDB 从不同的数据库中获取点击数

func GetAvatarByID

func GetAvatarByID(gormDB *gorm.DB, redisDB *redis.Client, uid uint64) string

GetAvatarByID 获取用户头像

func GetCIDArticleMax

func GetCIDArticleMax(cid uint64) uint64

GetCIDArticleMax 获取当前分类的偏移值

func GetDays

func GetDays(redisDB *redis.Client) uint64

GetDays 获取从建站开始, 到目前的天数, 用于主页中的显示

func GetTopicListByPageNum

func GetTopicListByPageNum(cid uint64, page uint64, limit uint64) []uint64

GetTopicListByPageNum 通过给定的页码查找话题的ID值

func GetUserNameByID

func GetUserNameByID(gormDB *gorm.DB, redisDB *redis.Client, uid uint64) string

GetUserNameByID 获取用户名称

func MentionToHTML

func MentionToHTML(content string) string

func NewCaptcha

func NewCaptcha(path string) string

NewCaptcha 产生新的验证码图片

func PreProcessUserMention

func PreProcessUserMention(gormDB *gorm.DB, redisDB *redis.Client, tz int, userComment string) string

PreProcessUserMention 预处理用户的引用 #14

func RankMapInit

func RankMapInit(gormDB *gorm.DB, redisDB *redis.Client)

RankMapInit init a ttl map

func SaveImage

func SaveImage(path, id string)

SaveImage to static dir

func SetCaptchaUseRedisStore

func SetCaptchaUseRedisStore(redisDB *redis.Client)

SetCaptchaUseRedisStore use redis to store captcha

func TimelyResort

func TimelyResort()

TimelyResort 刷新Redis数据库中每个帖子的权重

Types

type ActionRecord

type ActionRecord struct {
	gorm.Model
	UserID uint64 `gorm:"column:user_id;index"`

	PostData string
}

type AppConf

type AppConf struct {
	Main *MainConf
	Site *SiteConf
}

AppConf 应用配置文件

type ArticleFeedListItem

type ArticleFeedListItem struct {
	ID          uint64
	UID         uint64
	Name        string
	Cname       string
	Title       string
	AddTimeFmt  string
	EditTimeFmt string
	Des         string
}

ArticleFeedListItem rss资源

type ArticleLi

type ArticleLi struct {
	ID    uint64 `json:"id"`
	Title string `json:"title"`
	Tags  string `json:"tags"`
}

type ArticleListItem

type ArticleListItem struct {
	Topic
	Name        string `json:"name"`
	Avatar      string `json:"avatar"`
	Cname       string `json:"cname"`
	Ruid        uint64 `json:"ruid"`
	Rname       string `json:"rname"`
	AddTimeFmt  string `json:"addtimefmt"`
	EditTimeFmt string `json:"edittimefmt"`

	/**
	 * When in search page, every article item have the highlight content,
	 * we need tell users that we do not return a random list.
	 */
	HighlightContent template.HTML `json:"highlight_content"`
}

ArticleListItem data strucy only used in page.

type ArticleMini

type ArticleMini struct {
	Topic
	Ruid   uint64 `json:"ruid"`
	Hidden bool   `json:"hidden"`
}

ArticleMini 缩略版的Article信息

type ArticlePageInfo

type ArticlePageInfo struct {
	Items      []ArticleListItem `json:"items"`
	HasPrev    bool              `json:"hasprev"`
	HasNext    bool              `json:"hasnext"`
	FirstKey   uint64            `json:"firstkey"`
	FirstScore uint64            `json:"firstscore"`
	LastKey    uint64            `json:"lastkey"`
	PageNum    uint64            `json:"pagenum"`
	PagePrev   uint64            `json:"pageprev"`
	PageNext   uint64            `json:"pagenext"`
	LastScore  uint64            `json:"lastscore"`
}

ArticlePageInfo data in every list page

type ArticleRankItem

type ArticleRankItem struct {
	AID     uint64 `json:"a_id"`
	Weight  uint64
	SQLDB   *sql.DB
	RedisDB *redis.Client
}

ArticleRankItem 记录每个话题的权重

type ArticleRelative

type ArticleRelative struct {
	Articles []ArticleLi
	Tags     []string
}

type ArticleTag

type ArticleTag struct {
	ID      uint64
	OldTags string
	NewTags string
}

ArticleTag 文章添加、编辑后传给后台任务的信息 TODO: delete

type CategoryRankData

type CategoryRankData struct {
	CID uint64 `json:"c_id"`
	// contains filtered or unexported fields
}

CategoryRankData 一个分类下的排序数据

type Comment

type Comment struct {
	Reply
	Avatar     string `json:"avatar"`
	ContentFmt template.HTML
	Likes      []uint64 // 点赞的用户
}

Comment 评论信息

func SQLCommentByID

func SQLCommentByID(gormDB *gorm.DB, redisDB *redis.Client, cid uint64, tz int) (Comment, error)

SQLCommentByID 获取一条评论

func SQLCommentListByCID

func SQLCommentListByCID(gormDB *gorm.DB, redisDB *redis.Client, commentID uint64, limit uint64, tz int) ([]Comment, error)

SQLCommentListByCID 获取某条评论

func SQLCommentListByList

func SQLCommentListByList(gormDB *gorm.DB, redisDB *redis.Client, commentList []uint64, tz int) ([]Comment, error)

SQLCommentListByList 获取某条评论

func SQLCommentListByTopic

func SQLCommentListByTopic(gormDB *gorm.DB, redisDB *redis.Client, topicID uint64, limit uint64, tz int) ([]Comment, error)

SQLCommentListByTopic 获取帖子的所有评论

func SQLCommentListByUser

func SQLCommentListByUser(gormDB *gorm.DB, redisDB *redis.Client, userID uint64, limit uint64, tz int) ([]Comment, error)

SQLCommentListByUser 获取某个用户的帖子信息

func (*Comment) CreateFlarumComment

func (comment *Comment) CreateFlarumComment(gormDB *gorm.DB) (bool, error)

CreateFlarumComment 创建flarum的评论

func (*Comment) DoLike

func (comment *Comment) DoLike(gormDB *gorm.DB, redisDB *redis.Client, user *User, isLiked bool)

DoLike 用户的点赞

type FlarumArticlePageInfo

type FlarumArticlePageInfo struct {
	Items     []flarum.Discussion
	LinkFirst string
	LinkPrev  string
	LinkNext  string
}

FlarumArticlePageInfo flarum站点的数据信息

type ISQLLoader

type ISQLLoader interface {
	LoadDictData(map[string]interface{})
}

ISQLLoader dict结果的loader

type MainConf

type MainConf struct {
	HTTPPort int
	Domain   string // 若启用https 则该domain 为注册的域名,eg: domain.com、www.domain.com

	BaseURL string

	// 数据库地址
	MySQLURL string
	MongoURL string
	RedisURL string

	StaticDir     string
	WebpackDir    string
	LocaleDir     string
	ExtensionsDir string
	ViewDir       string
	Debug         bool

	ServerName     string
	CookieSecure   bool
	CookieHttpOnly bool
	OldSiteDomain  string
	TLSCrtFile     string
	TLSKeyFile     string

	// secure cookie 初始化时需要
	SCHashKey  string
	SCBlockKey string
}

MainConf 主配置

type POSTHTMLTag

type POSTHTMLTag struct {
	XMLName xml.Name `xml:"a"`
	Text    string   `xml:",chardata"`
	Href    string   `xml:"href,attr"`
	Class   string   `xml:"class,attr"`
	DataID  string   `xml:"data-id,attr"`
}

POSTHTMLTag 引用其他评论的tag

type POSTMENTION

type POSTMENTION struct {
	XMLName      xml.Name `xml:"POSTMENTION"`
	Text         string   `xml:",chardata"`
	Discussionid string   `xml:"discussionid,attr"`
	Displayname  string   `xml:"displayname,attr"`
	ID           string   `xml:"id,attr"`
	Number       string   `xml:"number,attr"`
	Username     string   `xml:"username,attr"`
}

POSTMENTION 引用评论

type RankMap

type RankMap struct {
	GormDB  *gorm.DB
	SQLDB   *sql.DB
	RedisDB *redis.Client
	// contains filtered or unexported fields
}

RankMap time to live map

func GetRankMap

func GetRankMap() *RankMap

GetRankMap you can get ttlmap by this.

type Reply

type Reply struct {
	gorm.Model
	ID       uint64 `gorm:"primaryKey"`
	AID      uint64 `gorm:"column:topic_id"`
	UID      uint64 `gorm:"column:user_id"`
	Number   uint64 `json:"number"`
	Content  string `json:"content"`
	ClientIP string `json:"clientip"`
	AddTime  uint64 `json:"addtime"`
}

Reply 会在数据库中保存的信息

type ReplyLikes

type ReplyLikes struct {
	gorm.Model
	UserID  uint64 `gorm:"column:user_id;index"`
	ReplyID uint64 `gorm:"column:reply_id;index"`
}

type RestfulAPIBase

type RestfulAPIBase struct {
	State bool `json:"success"`
}

RestfulAPIBase for restful API

type RestfulReply

type RestfulReply struct {
}

RestfulReply Reply for restful API

type RestfulTopic

type RestfulTopic struct {
	ID       uint64        `json:"id"`
	UID      uint64        `json:"author_id"`
	Content  template.HTML `json:"content"`
	Title    string        `json:"title"`
	CreateAt string        `json:"create_at"`
	Author   RestfulUser   `json:"author"`

	ReplyCount uint64 `json:"reply_count"`
	VisitCount uint64 `json:"visit_count"`

	Replies     []RestfulReply `json:"replies"`
	LastReplyAt string         `json:"last_reply_at"`
}

RestfulTopic topic for restful API

type RestfulUser

type RestfulUser struct {
	Name   string `json:"loginname"`
	Avatar string `json:"avatar_url"`
}

RestfulUser user for restful API

type SiteConf

type SiteConf struct {
	GoVersion  string
	MD5Sums    string
	Name       string
	Desc       string
	AdminEmail string
	MainDomain string // 上传图片后添加网址前缀, eg: http://domian.comhttp://234.21.35.89:8082

	CDNBaseURL string // 静态文件cdn地址

	MainNodeIDs       string
	TimeZone          int
	HomeShowNum       int
	TitleMaxLen       int
	ContentMaxLen     int
	PostInterval      int
	CommentListNum    int
	CommentInterval   int
	Authorized        bool
	RegReview         bool
	CloseReg          bool
	AutoDataBackup    bool
	AutoGetTag        bool
	UploadSuffix      string
	UploadImgOnly     bool
	UploadImgResize   bool
	AllowSignup       bool
	UploadMaxSize     int
	UploadMaxSizeByte int64

	WelcomeMessage string
	WelcomeTitle   string

	// Google tracking code id
	TrackingCodeID string

	GithubClientID     string
	GithubClientSecret string
}

SiteConf 站点配置

type SiteInfo

type SiteInfo struct {
	Days     uint64 // 创建的天数
	UserNum  uint64 // 用户数量
	NodeNum  uint64 // 节点数量
	TagNum   uint64 // tag数量
	PostNum  uint64 // 帖子数量
	ReplyNum uint64 // 回复数量
}

SiteInfo 当前站点的一些集合类信息

func GetSiteInfo

func GetSiteInfo(redisDB *redis.Client) SiteInfo

GetSiteInfo 直接获取网站信息

type Tag

type Tag struct {
	gorm.Model
	ID   uint64 `gorm:"primaryKey"`
	Name string `json:"name" gorm:"index:idx_name,unique"`

	URLName     string `json:"urlname" gorm:"index:idx_urlname,unique"`
	Articles    uint64 `json:"articles"`
	About       string `json:"about"`
	ParentID    uint64 `json:"parent_id"`
	Position    uint64 `json:"position"`
	Description string `json:"description"`
	Hidden      bool   `json:"hidden"`
	Color       string `json:"color"`
	IconIMG     string `json:"icon_img"`

	Topics []Topic `gorm:"many2many:topic_tags;"`
}

Tag 帖子分类

func SQLGetTagByID

func SQLGetTagByID(gormDB *gorm.DB, id uint64) (tag Tag, err error)

func SQLGetTagByUrlName

func SQLGetTagByUrlName(gormDB *gorm.DB, urlName string) (tag Tag, err error)

func SQLGetTags

func SQLGetTags(gormDB *gorm.DB) (tags []Tag, err error)

func (*Tag) CreateFlarumTag

func (tag *Tag) CreateFlarumTag(gormDB *gorm.DB)

type Topic

type Topic struct {
	gorm.Model
	ID     uint64 `gorm:"primaryKey"`
	UserID uint64 `gorm:"column:user_id;index"`

	Title   string `json:"title"`
	Content string `json:"content"`

	FirstPostID uint64

	LastPostID     uint64
	LastPostUserID uint64

	CommentCount uint64

	ClientIP string `json:"clientip"`
	IsSticky bool

	Tags []Tag `gorm:"many2many:topic_tags;"`
}

Topic 基础的文档类, 在数据库表中的字段

func SQLArticleGetByID

func SQLArticleGetByID(gormDB *gorm.DB, redisDB *redis.Client, aid uint64) (Topic, error)

SQLArticleGetByID 通过 article id获取内容

func SQLGetTopicByTag

func SQLGetTopicByTag(gormDB *gorm.DB, redisDB *redis.Client, tagID, start uint64, limit uint64) (topics []Topic, err error)

tagID 为0 表示全部主题

func SQLGetTopicByUser

func SQLGetTopicByUser(gormDB *gorm.DB, userID, start uint64, limit uint64) (topics []Topic, err error)

func (*Topic) CacheCommentList

func (topic *Topic) CacheCommentList(redisDB *redis.Client, comments []Comment, done chan bool) error

CacheCommentList 缓存当前话题对应的评论ID, 该函数可以用于进行增加或是减少 注意这里是有顺序的, 顺序为发帖时间

func (*Topic) CleanCache

func (article *Topic) CleanCache()

func (*Topic) CreateFlarumTopic

func (topic *Topic) CreateFlarumTopic(gormDB *gorm.DB) (bool, error)

CreateFlarumTopic 创建flarum的帖子 帖子中, category和tag是不同的数据 category是帖子比较大的分类, 每个帖子只能有一个 tag只是这个帖子具有的某种特征, 每个帖子可以有多个tag

func (*Topic) GetCommentIDList

func (topic *Topic) GetCommentIDList(redisDB *redis.Client) (comments []uint64)

GetCommentIDList 获取帖子已经排序好的评论列表

func (*Topic) GetWeight

func (article *Topic) GetWeight(redisDB *redis.Client) float64

GetWeight 获取当前帖子的权重 *

  • (Log10(QView) * 2 + 4 * comments)/ QAge *
  • db (*sql.DB): TODO
  • redisDB (redis.Client): TODO

type TopicTag

type TopicTag struct {
	gorm.Model
	TopicID uint64 `gorm:"primaryKey"`
	TagID   uint64 `gorm:"primaryKey"`
}

TopicTags 帖子的标签 使用gorm 的many2many, 不需要单独初始化了

type USERHTMLTag

type USERHTMLTag struct {
	XMLName xml.Name `xml:"a"`
	Text    string   `xml:",chardata"`
	Href    string   `xml:"href,attr"`
	Class   string   `xml:"class,attr"`
}

USERHTMLTag 引用用户的tag

type USERMENTION

type USERMENTION struct {
	XMLName     xml.Name `xml:"USERMENTION"`
	Text        string   `xml:",chardata"`
	Displayname string   `xml:"displayname,attr"`
	ID          string   `xml:"id,attr"`
	Username    string   `xml:"username,attr"`
}

USERMENTION 引用用户

type User

type User struct {
	gorm.Model
	ID       uint64 `gorm:"primaryKey"`
	Name     string `json:"name" gorm:"index:idx_name,unique"`
	Nickname string `json:"nickname"`
	Gender   string `json:"gender"`
	Flag     int    `json:"flag"`
	Avatar   string `json:"avatar"`
	Password string `json:"password"`
	Email    string `json:"email"`
	URL      string `json:"url"`
	Articles uint64 `json:"articles"`
	Replies  uint64 `json:"replies"`
	About    string `json:"about"`
	Hidden   bool   `json:"hidden"`
	Session  string `json:"session"`
	Token    string `json:"token"`

	Description string
	WebSite     string
	Reputation  uint64 `json:"reputation"` // 声望值

	// Preferences *flarum.Preferences `gorm:"foreignKey:PreferencesRefer"`
	Preferences []byte
}

User store in database

func RedisGetUserByID

func RedisGetUserByID(redisDB *redis.Client, uid string) (User, error)

RedisGetUserByID 从Redis中获取缓存的用户

func SQLGithubRegister

func SQLGithubRegister(gormDB *gorm.DB, gu *github.User) (User, error)

SQLGithubRegister github用户注册

func SQLUserGet

func SQLUserGet(gormDB *gorm.DB, _userID string) (User, error)

SQLUserGet 获取用户 当你不确定用户传来的是用户名还是用户id时, 可以调用该函数获取用户

func SQLUserGetByEmail

func SQLUserGetByEmail(gormDB *gorm.DB, email string) (User, error)

SQLUserGetByEmail 获取数据库中用户

func SQLUserGetByID

func SQLUserGetByID(gormDB *gorm.DB, uid uint64) (User, error)

SQLUserGetByID 获取数据库用户

func SQLUserGetByName

func SQLUserGetByName(gormDB *gorm.DB, name string) (User, error)

SQLUserGetByName 获取数据库中用户

func SQLUserRegister

func SQLUserRegister(gormDB *gorm.DB, name, email, password string) (User, error)

func (*User) CachedToRedis

func (user *User) CachedToRedis(redisDB *redis.Client) error

CachedToRedis 缓存当前用户的信息至Redis

func (*User) CanCreateTopic

func (user *User) CanCreateTopic() bool

CanCreateTopic 检查当前用户是否可以创建帖子

func (*User) CanEdit

func (user *User) CanEdit(aobjBase *Topic) bool

CanEdit 检查当前用户是否可以编辑帖子

func (*User) CanReply

func (user *User) CanReply() bool

CanReply 检查当前用户是否可以回复帖子

func (*User) CleareRedisCache

func (user *User) CleareRedisCache(redisDB *redis.Client) error

CleareRedisCache 缓存当前用户的信息至Redis

func (*User) IsAdmin

func (user *User) IsAdmin() bool

IsAdmin 检查当前用户是否为管理员

func (*User) IsForbid

func (user *User) IsForbid() bool

IsForbid 检查当前用户是否被禁用

func (*User) IsValid

func (user *User) IsValid() bool

IsValid 当前用户是否有效

func (*User) RefreshCSRF

func (user *User) RefreshCSRF(redisDB *redis.Client) string

RefreshCSRF 刷新CSRF token

func (*User) RefreshCache

func (user *User) RefreshCache(redisDB *redis.Client)

RefreshCache 刷新当前用户的信息

func (*User) SQLGithubSync

func (user *User) SQLGithubSync(gormDB *gorm.DB, gu *github.User)

SQLGithubSync github用户同步信息

func (*User) SetPreference

func (user *User) SetPreference(gormDB *gorm.DB, preference flarum.Preferences)

SetPreference 更新用户配置信息 数据库中使用了blob的数据类型, 查看数据时, 需要进行转换:

SELECT CONVERT(`preferences` USING utf8) FROM `user`;

func (*User) StrID

func (user *User) StrID() string

StrID 返回string类型的ID值

func (*User) VerifyCSRFToken

func (user *User) VerifyCSRFToken(redisDB *redis.Client, token string) bool

VerifyCSRFToken 确认用户CSRF token

type UserTopic

type UserTopic struct {
	gorm.Model
	ID      uint64 `gorm:"primaryKey"`
	UserID  uint64 `gorm:"column:user_id;index"`
	TopicID uint64 `gorm:"column:topic_id;index"`

	LastReadAt         time.Time // last read time
	LastReadPostNumber uint64    // last read post number
	Subscription       string    // subscription status enum(follow, ignore)
}

It will record the user relation with the topic

type WeightAble

type WeightAble interface {
	GetWeight() uint64
}

WeightAble 可以获取权值的一种结构

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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