http

package
v0.0.0-...-476b199 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2023 License: LGPL-3.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CaptchaExpiration = 5 * time.Minute // 验证码 5 分钟内有效
)
View Source
var ImgUpload_RoutePath = "/static/images/"

图片目录路由重写路径

View Source
var SiteOriginSkips = []string{
	"/api/user-get",
	"/api/login",
}

不启用 Origin 控制的 API paths

Functions

func ActionLimitMiddleware

func ActionLimitMiddleware(conf ActionLimitConf) echo.MiddlewareFunc

操作限制 中间件

func AdminOnlyHandler

func AdminOnlyHandler(next echo.HandlerFunc) echo.HandlerFunc

func AllowedComment

func AllowedComment(c echo.Context, p ParamsGet) func(db *gorm.DB) *gorm.DB

允许的评论

func AllowedCommentChecker

func AllowedCommentChecker(c echo.Context, p ParamsGet) func(*model.Comment) bool

func CheckIsAdminReq

func CheckIsAdminReq(c echo.Context) bool

func CheckIsAllowed

func CheckIsAllowed(c echo.Context, name string, email string, page model.Page, siteName string) (bool, error)

func CheckOrigin

func CheckOrigin(c echo.Context, allowSite *model.Site) (bool, error)

检测 Origin 合法性 防止跨域的 CSRF 攻击 @see https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html

func CommentSearchScope

func CommentSearchScope(a *action, p ParamsGet) func(d *gorm.DB) *gorm.DB

评论搜索

func CopyStruct

func CopyStruct(src *map[string]interface{}, dest *map[string]interface{}) error

func CountComments

func CountComments(db *gorm.DB) int64

评论计数

func DisposeImageCaptcha

func DisposeImageCaptcha(ip string)

销毁图片验证码

func GetAlwaysCaptchaMode_Pass

func GetAlwaysCaptchaMode_Pass(ip string) bool

AlwaysMode 是否能 Pass (for 总是需要验证码的选项)

func GetCommentQuery

func GetCommentQuery(a *action, c echo.Context, p ParamsGet, siteID uint, scopes ...func(*gorm.DB) *gorm.DB) *gorm.DB

获取评论查询实例

func GetImageCaptchaRealCode

func GetImageCaptchaRealCode(ip string) string

#region 图片验证码 获取对应 IP 图片验证码正确的值

func GetIsAllowOrigin

func GetIsAllowOrigin(origin string, allowURLs []string) bool

判断 Origin 是否被允许 origin is 'schema://hostname:port', allowURLs is a collection of url strings

func GetIsSuperAdmin

func GetIsSuperAdmin(c echo.Context) bool

func GetJwtInstanceByReq

func GetJwtInstanceByReq(c echo.Context) *jwt.Token

func GetJwtStrByReqCookie

func GetJwtStrByReqCookie(c echo.Context) string

func GetNewImageCaptchaBase64

func GetNewImageCaptchaBase64(ip string) string

获取新验证码 base64 格式图片

func GetSortRuleSQL

func GetSortRuleSQL(sortBy string, defaultSQL string) string

排序规则

func GetUserByJwt

func GetUserByJwt(jwt *jwt.Token) model.User

func GetUserByReq

func GetUserByReq(c echo.Context) model.User

func HashPassword

func HashPassword(password string) (string, error)

func InitCorsControl

func InitCorsControl(e *echo.Echo)

func InitRouter

func InitRouter(e *echo.Echo)

func IsActionInTimeFrame

func IsActionInTimeFrame(c echo.Context) bool

操作计数是否应该被重置

func IsAdminHasSiteAccess

func IsAdminHasSiteAccess(c echo.Context, siteName string) bool

func IsReqNeedCaptchaCheck

func IsReqNeedCaptchaCheck(c echo.Context) bool

请求是否需要验证码

func LogWithHttpInfo

func LogWithHttpInfo(c echo.Context) *logrus.Entry

func LoginGetUserToken

func LoginGetUserToken(user model.User) string

func Paginate

func Paginate(offset int, limit int) func(db *gorm.DB) *gorm.DB

分页

func ParamsDecode

func ParamsDecode(c echo.Context, destParams interface{}) (isContinue bool, resp error)

func RecordAction

func RecordAction(c echo.Context)

记录操作

func RenotifyWhenPendingModified

func RenotifyWhenPendingModified(comment *model.Comment)

func ResetActionRecord

func ResetActionRecord(c echo.Context)

重置操作记录

func RespData

func RespData(c echo.Context, data interface{}) error

RespData is just response data

func RespError

func RespError(c echo.Context, msg string, data ...Map) error

RespError is just response error

func RespJSON

func RespJSON(c echo.Context, msg string, data interface{}, success bool) error

RespJSON is normal json result

func RespSuccess

func RespSuccess(c echo.Context, msg ...string) error

RespSuccess is just response success

func RootComments

func RootComments() func(db *gorm.DB) *gorm.DB

根评论 Root comments

func RootPageMiddleware

func RootPageMiddleware() echo.MiddlewareFunc

func Run

func Run()

func SetAlwaysCaptchaMode_Pass

func SetAlwaysCaptchaMode_Pass(ip string, pass bool)

设置 AlwaysMode 允许 Pass (for 总是需要验证码的选项)

func SiteIsolationChecker

func SiteIsolationChecker(c echo.Context, p ParamsGet) func(*model.Comment) bool

func SiteIsolationScope

func SiteIsolationScope(c echo.Context, p ParamsGet) func(db *gorm.DB) *gorm.DB

站点隔离

func SiteOriginMiddleware

func SiteOriginMiddleware() echo.MiddlewareFunc

站点隔离 & Origin 控制

func UseCfgFrontend

func UseCfgFrontend(p *ParamsGet)

处理来自配置文件的 fronted 配置项

func UseSite

func UseSite(c echo.Context, siteName *string, destID *uint, destSiteAll *bool)

func VoteSync

func VoteSync(a *action)

Types

type ActionLimitConf

type ActionLimitConf struct {
	ProtectPaths []string
}

type JSONResult

type JSONResult struct {
	Success bool        `json:"success"`         // 是否成功
	Msg     string      `json:"msg,omitempty"`   // 消息
	Data    interface{} `json:"data,omitempty"`  // 数据
	Extra   interface{} `json:"extra,omitempty"` // 数据
}

JSONResult JSON 响应数据结构

type Map

type Map = map[string]interface{}

func GetApiPublicConfDataMap

func GetApiPublicConfDataMap(c echo.Context) Map

func GetApiVersionDataMap

func GetApiVersionDataMap() Map

type ParamsAdd

type ParamsAdd struct {
	Name    string `mapstructure:"name"`
	Email   string `mapstructure:"email"`
	Link    string `mapstructure:"link"`
	Content string `mapstructure:"content" param:"required"`
	Rid     uint   `mapstructure:"rid"`
	UA      string `mapstructure:"ua"`

	PageKey   string `mapstructure:"page_key" param:"required"`
	PageTitle string `mapstructure:"page_title"`

	Token    string `mapstructure:"token"`
	SiteName string
	SiteID   uint
}

type ParamsAdminCacheFlush

type ParamsAdminCacheFlush struct {
	FlushAll bool `mapstructure:"flush_all"`
}

type ParamsAdminCacheWarm

type ParamsAdminCacheWarm struct {
}

type ParamsAdminImport

type ParamsAdminImport struct {
	Payload string `mapstructure:"payload"`
}

type ParamsAdminPageDel

type ParamsAdminPageDel struct {
	Key      string `mapstructure:"key" param:"required"`
	SiteName string
	SiteID   uint
}

type ParamsAdminPageEdit

type ParamsAdminPageEdit struct {
	// 查询值
	ID       uint `mapstructure:"id"`
	SiteName string
	SiteID   uint

	// 修改值
	Key       string `mapstructure:"key"`
	Title     string `mapstructure:"title"`
	AdminOnly bool   `mapstructure:"admin_only"`
}

type ParamsAdminPageFetch

type ParamsAdminPageFetch struct {
	ID       uint `mapstructure:"id"`
	SiteName string

	GetStatus bool `mapstructure:"get_status"`
}

type ParamsAdminPageGet

type ParamsAdminPageGet struct {
	SiteName string
	SiteID   uint
	SiteAll  bool
	Limit    int `mapstructure:"limit"`
	Offset   int `mapstructure:"offset"`
}

type ParamsAdminSendMail

type ParamsAdminSendMail struct {
	Subject string `mapstructure:"subject" param:"required"`
	Body    string `mapstructure:"body" param:"required"`
	ToAddr  string `mapstructure:"to_addr" param:"required"`
}

type ParamsAdminSettingSave

type ParamsAdminSettingSave struct {
	Data string `mapstructure:"data" param:"required"`
}

type ParamsAdminSiteAdd

type ParamsAdminSiteAdd struct {
	Name string `mapstructure:"name" param:"required"`
	Urls string `mapstructure:"urls"`
}

type ParamsAdminSiteDel

type ParamsAdminSiteDel struct {
	ID uint `mapstructure:"id" param:"required"`
}

type ParamsAdminSiteEdit

type ParamsAdminSiteEdit struct {
	// 查询值
	ID uint `mapstructure:"id" param:"required"`

	// 修改值
	Name string `mapstructure:"name"`
	Urls string `mapstructure:"urls"`
}

type ParamsAdminSiteGet

type ParamsAdminSiteGet struct {
}

type ParamsAdminUserAdd

type ParamsAdminUserAdd struct {
	Name         string `mapstructure:"name" param:"required"`
	Email        string `mapstructure:"email" param:"required"`
	Password     string `mapstructure:"password"`
	Link         string `mapstructure:"link"`
	IsAdmin      bool   `mapstructure:"is_admin" param:"required"`
	SiteNames    string `mapstructure:"site_names"`
	ReceiveEmail bool   `mapstructure:"receive_email" param:"required"`
	BadgeName    string `mapstructure:"badge_name"`
	BadgeColor   string `mapstructure:"badge_color"`
}

type ParamsAdminUserDel

type ParamsAdminUserDel struct {
	ID uint `mapstructure:"id" param:"required"`
}

type ParamsAdminUserEdit

type ParamsAdminUserEdit struct {
	// 查询值
	ID uint `mapstructure:"id" param:"required"`

	// 修改值
	Name         string `mapstructure:"name" param:"required"`
	Email        string `mapstructure:"email" param:"required"`
	Password     string `mapstructure:"password"`
	Link         string `mapstructure:"link"`
	IsAdmin      bool   `mapstructure:"is_admin" param:"required"`
	SiteNames    string `mapstructure:"site_names"`
	ReceiveEmail bool   `mapstructure:"receive_email" param:"required"`
	BadgeName    string `mapstructure:"badge_name"`
	BadgeColor   string `mapstructure:"badge_color"`
}

type ParamsAdminUserGet

type ParamsAdminUserGet struct {
	Limit  int    `mapstructure:"limit"`
	Offset int    `mapstructure:"offset"`
	Type   string `mapstructure:"type"`
}

type ParamsAdminVoteSync

type ParamsAdminVoteSync struct {
}

type ParamsCaptchaCheck

type ParamsCaptchaCheck struct {
	Value string `mapstructure:"value" param:"required"`
}

type ParamsCommentDel

type ParamsCommentDel struct {
	ID uint `mapstructure:"id" param:"required"`

	SiteName string
	SiteID   uint
	SiteAll  bool
}

type ParamsCommentEdit

type ParamsCommentEdit struct {
	// 查询值
	ID       uint `mapstructure:"id" param:"required"`
	SiteName string
	SiteID   uint
	SiteAll  bool

	// 可修改
	Content     string `mapstructure:"content"`
	PageKey     string `mapstructure:"page_key"`
	Nick        string `mapstructure:"nick"`
	Email       string `mapstructure:"email"`
	Link        string `mapstructure:"link"`
	Rid         string `mapstructure:"rid"`
	UA          string `mapstructure:"ua"`
	IP          string `mapstructure:"ip"`
	IsCollapsed bool   `mapstructure:"is_collapsed"`
	IsPending   bool   `mapstructure:"is_pending"`
	IsPinned    bool   `mapstructure:"is_pinned"`
}

type ParamsGet

type ParamsGet struct {
	PageKey  string `mapstructure:"page_key" param:"required"`
	SiteName string

	Limit  int `mapstructure:"limit"`
	Offset int `mapstructure:"offset"`

	FlatMode      bool   `mapstructure:"flat_mode"`
	SortBy        string `mapstructure:"sort_by"`         // date_asc, date_desc, vote
	ViewOnlyAdmin bool   `mapstructure:"view_only_admin"` // 只看 admin

	Search string `mapstructure:"search"`

	// Message Center
	Type  string `mapstructure:"type"` // ["", "all", "mentions", "mine", "pending", "admin_all", "admin_pending"]
	Name  string `mapstructure:"name"`
	Email string `mapstructure:"email"`

	SiteID  uint
	SiteAll bool

	IsMsgCenter bool
	User        *model.User
	IsAdminReq  bool
}

type ParamsImgUpload

type ParamsImgUpload struct {
	Name  string `mapstructure:"name" param:"required"`
	Email string `mapstructure:"email" param:"required"`

	PageKey   string `mapstructure:"page_key" param:"required"`
	PageTitle string `mapstructure:"page_title"`

	SiteName string

	SiteID  uint
	SiteAll bool
}

type ParamsLogin

type ParamsLogin struct {
	Name     string `mapstructure:"name"`
	Email    string `mapstructure:"email" param:"required"`
	Password string `mapstructure:"password" param:"required"`
}

type ParamsLoginStatus

type ParamsLoginStatus struct {
	Name  string `mapstructure:"name"`
	Email string `mapstructure:"email"`
}

type ParamsMarkRead

type ParamsMarkRead struct {
	NotifyKey string `mapstructure:"notify_key"`

	Name    string `mapstructure:"name"`
	Email   string `mapstructure:"email"`
	AllRead bool   `mapstructure:"all_read"`

	SiteName string
	SiteID   uint
	SiteAll  bool
}

type ParamsPV

type ParamsPV struct {
	PageKey   string `mapstructure:"page_key" param:"required"`
	PageTitle string `mapstructure:"page_title"`

	SiteName string
	SiteID   uint
	SiteAll  bool
}

type ParamsStat

type ParamsStat struct {
	Type string `mapstructure:"type" param:"required"`

	SiteName string
	PageKeys string `mapstructure:"page_keys"`

	Limit int `mapstructure:"limit"`

	SiteID  uint
	SiteAll bool
}

type ParamsUserGet

type ParamsUserGet struct {
	Name  string `mapstructure:"name"`
	Email string `mapstructure:"email"`
}

type ParamsVote

type ParamsVote struct {
	TargetID uint   `mapstructure:"target_id" param:"required"`
	FullType string `mapstructure:"type"`

	Name  string `mapstructure:"name"`
	Email string `mapstructure:"email"`

	SiteName string
	SiteID   uint
	SiteAll  bool
}

type ResponseAdd

type ResponseAdd struct {
	Comment model.CookedComment `json:"comment"`
}

type ResponseAdminPageGet

type ResponseAdminPageGet struct {
	Total int64              `json:"total"`
	Pages []model.CookedPage `json:"pages"`
}

type ResponseAdminUserGet

type ResponseAdminUserGet struct {
	Total int64                      `json:"total"`
	Users []model.CookedUserForAdmin `json:"users"`
}

type ResponseGet

type ResponseGet struct {
	Comments    []model.CookedComment `json:"comments"`
	Total       int64                 `json:"total"`
	TotalRoots  int64                 `json:"total_roots"`
	Page        model.CookedPage      `json:"page"`
	Unread      []model.CookedNotify  `json:"unread"`
	UnreadCount int                   `json:"unread_count"`
	ApiVersion  Map                   `json:"api_version"`
	Conf        Map                   `json:"conf,omitempty"`
}

type Skipper

type Skipper func(echo.Context) bool

Jump to

Keyboard shortcuts

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