api

package
v0.18.4-alpha.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2025 License: MIT Imports: 28 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ErrInvalidOp   = `invalid patch op: "%s"`
	ErrInvalidPath = `invalid patch path: "%s"`
)
View Source
const AutoDownloadKey string = "auto_download"
View Source
const AutoSaveKey string = "auto_save"
View Source
const JWTSecretKeyKey string = "jwt_secret_key"
View Source
const MagicUIDKey string = "_magic_uid_key_"
View Source
const Version = "v0.18.4"

Variables

View Source
var (
	ErrOpenAPINotExist = errors.New("webhook/api: OpenAPI does not exist")

	ErrAuthNotExist   = errors.New("webhook/api: Authorization does not exist")
	ErrBlogNotExist   = errors.New("webhook/api: blog does not exist")
	ErrUserNotExist   = errors.New("webhook/api: user does not exist")
	ErrTaskNotExist   = errors.New("webhook/api: task does not exist")
	ErrFilterNotExist = errors.New("webhook/api: filter does not exist")

	ErrExpired    = errors.New("webhook/api: token is expired")
	ErrPermDenied = errors.New("webhook/api: permission denied")

	ErrUserRegistered = errors.New("webhook/api: user registered")
	ErrIncorrectPwd   = errors.New("webhook/api: incorrect password")
	ErrBanned         = errors.New("webhook/api: user has been banned")
)
View Source
var API = group.G{
	Middlewares: []gin.HandlerFunc{group.CORS, Index},
	Handlers:    []group.H{GetValid, GetPing},
	Groups:      []group.G{vistor, user, admin, owner},
}
View Source
var AutoDownload bool

自动下载

开启会极大的占用带宽,建议发送完所有 hook 请求后再下载

View Source
var AutoSave bool

自动另存数据库

View Source
var JWTSecretKey []byte

用于 JWT 加密的密钥

View Source
var UserDB, BlogDB *gorm.DB

Functions

func CloseDB added in v0.15.0

func CloseDB() error

func DeleteTaskID added in v0.15.0

func DeleteTaskID(ctx *gin.Context) (any, error)

移除任务

func DownloadAssets added in v0.18.0

func DownloadAssets(blog *model.Blog) error

下载资源

func Error added in v0.10.0

func Error(ctx *gin.Context, err error)

func FindBlogs added in v0.18.2

func FindBlogs(f Filter, dest any) error

func Get added in v0.15.0

func Get(ctx *gin.Context) (any, error)

获取自身信息

func GetBlogID added in v0.15.0

func GetBlogID(ctx *gin.Context) (any, error)

查询单条博文

func GetBlogs added in v0.15.0

func GetBlogs(ctx *gin.Context) (any, error)

查询博文

func GetExecute added in v0.17.0

func GetExecute(ctx *gin.Context) (any, error)

func GetFollowing added in v0.19.0

func GetFollowing(ctx *gin.Context) (any, error)

关注中博文查询

func GetOnline added in v0.14.0

func GetOnline(ctx *gin.Context) (any, error)

获取当前在线状态

func GetPing added in v0.14.0

func GetPing(ctx *gin.Context) (any, error)

更新在线时间

func GetShutdown added in v0.15.0

func GetShutdown(ctx *gin.Context) (any, error)

func GetTaskID added in v0.15.0

func GetTaskID(ctx *gin.Context) (any, error)

获取任务

func GetToken

func GetToken(ctx *gin.Context) (data any, err error)

获取 Token

func GetUID added in v0.15.0

func GetUID(ctx *gin.Context) string

func GetUUID added in v0.15.0

func GetUUID(ctx *gin.Context) (any, error)

获取用户信息

func GetUserUID added in v0.15.0

func GetUserUID(ctx *gin.Context) (any, error)

func GetValid added in v0.16.0

func GetValid(ctx *gin.Context) (any, error)

检验鉴权码是否有效

func GetVersion added in v0.14.0

func GetVersion(ctx *gin.Context) (any, error)

当前版本号

func Index added in v0.18.0

func Index(ctx *gin.Context)

func Info added in v0.15.0

func Info(ctx *gin.Context)

func Initial added in v0.19.0

func Initial(cfg *Config) error

func IsAdmin added in v0.14.0

func IsAdmin(ctx *gin.Context)

func IsOwner added in v0.15.0

func IsOwner(ctx *gin.Context)

func IsUser added in v0.15.0

func IsUser(ctx *gin.Context)

func JWTAuth added in v0.15.0

func JWTAuth(ctx *gin.Context) (uid string, err error)

func JWTSecretKeyFn added in v0.18.2

func JWTSecretKeyFn(*jwt.Token) (any, error)

func JWTUser added in v0.15.0

func JWTUser(ctx *gin.Context) (user *model.User, err error)

func LoadDir added in v0.18.0

func LoadDir(root, path string) error

func LoadFile added in v0.18.0

func LoadFile(root, file string)

func LoadOrStore added in v0.19.0

func LoadOrStore[T any](extra map[string]any, key string, value T) (actual T, loaded bool)

从配置中读取值,如果不存在则写入

func LogMiddleware added in v0.15.0

func LogMiddleware(ctx *gin.Context)

func PatchTaskID added in v0.15.0

func PatchTaskID(ctx *gin.Context) (any, error)

修改任务

func PatchUser added in v0.15.0

func PatchUser(ctx *gin.Context) (any, error)

修改用户信息

func PatchUserBan added in v0.15.0

func PatchUserBan(ctx *gin.Context, me, user *model.User, patch PatchBody) error

func PatchUserName added in v0.15.0

func PatchUserName(ctx *gin.Context, me, user *model.User, patch PatchBody) error

func PatchUserNickname added in v0.15.0

func PatchUserNickname(ctx *gin.Context, me, user *model.User, patch PatchBody) error

func PatchUserRole added in v0.15.0

func PatchUserRole(ctx *gin.Context, me, user *model.User, patch PatchBody) error

func PostBlog added in v0.15.0

func PostBlog(ctx *gin.Context) (any, error)

提交博文

func PostFilter added in v0.17.0

func PostFilter(ctx *gin.Context) (any, error)

筛选查询

func PostRegister added in v0.15.0

func PostRegister(ctx *gin.Context) (any, error)

新建用户

func PostTask added in v0.15.0

func PostTask(ctx *gin.Context) (any, error)

新增任务

func PostTest added in v0.15.0

func PostTest(ctx *gin.Context) (any, error)

测试单个任务

func PostTests added in v0.15.0

func PostTests(ctx *gin.Context) (any, error)

测试已有任务

func PostUpload added in v0.18.0

func PostUpload(ctx *gin.Context) (any, error)

上传文件

Types

type Config added in v0.19.0

type Config struct {
	Filename string         `toml:"-"      yaml:"-"      json:"-"`      // 配置文件保存路径
	Path     Path           `toml:"path"   yaml:"path"   json:"path"`   // 各文件路径
	Server   Server         `toml:"server" yaml:"server" json:"server"` // 服务器参数
	Role     Role           `toml:"role"   yaml:"role"   json:"role "`  // 权限组
	Extra    map[string]any `toml:"extra"  yaml:"extra"  json:"extra"`  // 额外项
}

webhook 配置

func (*Config) AfterInitial added in v0.19.0

func (c *Config) AfterInitial()

func (*Config) Export added in v0.19.0

func (c *Config) Export() (err error)

func (*Config) Import added in v0.19.0

func (c *Config) Import() (err error)

type Filter added in v0.18.2

type Filter struct {
	Filters  []model.Filter `json:"filters"`
	Reply    bool           `json:"reply"    form:"reply"`
	Comments bool           `json:"comments" form:"comments"`
	Order    string         `json:"order"    form:"order"`
	Limit    int            `json:"limit"    form:"limit"`
	Offset   int            `json:"offset"   form:"offset"`
	Conds    []string       `json:"conds"    form:"conds"`
}

type PatchBody added in v0.15.0

type PatchBody struct {
	Op    string `json:"op"` // [replace, add, remove, move, copy, test]
	Path  string `json:"path"`
	Value string `json:"value,omitempty"`
	From  string `json:"from,omitempty"`
}

type Path added in v0.19.0

type Path struct {
	Root   string `toml:"root"   yaml:"root"   json:"root"   default:"resource"`               // 程序根目录
	Logs   string `toml:"logs"   yaml:"logs"   json:"logs"   default:"logs"     join:"Root"`   // 记录文件夹
	UserDB string `toml:"userDB" yaml:"userDB" json:"userDB" default:"users.db" join:"Root"`   // 用户数据库文件
	BlogDB string `toml:"blogDB" yaml:"blogDB" json:"blogDB" default:"blogs.db" join:"Root"`   // 博文数据库文件
	Public string `toml:"public" yaml:"public" json:"public" default:"public"   join:"Root"`   // 公开文件夹
	Backup string `toml:"backup" yaml:"backup" json:"backup" default:"backup"   join:"Public"` // 博文数据库备份文件夹
	Upload string `toml:"upload" yaml:"upload" json:"upload" default:"upload"   join:"Public"` // 上传文件文件夹

	Full *Path `toml:"-" yaml:"-" json:"-"` // 以上字段的全路径 通过 utils.NewJoin 函数拼接
}

func (*Path) AfterInitial added in v0.19.0

func (p *Path) AfterInitial() (err error)

func (*Path) CopyBlogDB added in v0.19.0

func (p *Path) CopyBlogDB()

type Role added in v0.19.0

type Role struct {
	Owner string   `toml:"owner" yaml:"owner" json:"owner"` // 所有者
	Admin []string `toml:"admin" yaml:"admin" json:"admin"` // 管理员
}

type Server added in v0.19.0

type Server struct {
	Mode string `toml:"mode" yaml:"mode" json:"mode" default:"release"` // 模式
	Host string `toml:"host" yaml:"host" json:"host" default:"0.0.0.0"` // 主机
	Port uint16 `toml:"port" yaml:"port" json:"port" default:"9000"`    // 端口
}

func (Server) Addr added in v0.19.0

func (s Server) Addr() string

type UserClaims added in v0.15.0

type UserClaims struct {
	UID      string `json:"uid" gorm:"primaryKey"`
	IssuedAt int64  `json:"iat"`
}

func (UserClaims) TableName added in v0.17.3

func (UserClaims) TableName() string

func (UserClaims) Token added in v0.15.0

func (c UserClaims) Token(update bool) (string, error)

func (UserClaims) Valid added in v0.15.0

func (c UserClaims) Valid() error

Jump to

Keyboard shortcuts

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