serializer

package
v1.4.19 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CodeNotFullySuccess 未完全成功
	CodeNotFullySuccess = 203
	// CodeCheckLogin 未登录
	CodeCheckLogin = 401
	// CodeNoPermissionErr 未授权访问
	CodeNoPermissionErr = 403
	// CodeNotFound 资源未找到
	CodeNotFound = 404
	// CodeConflict 资源冲突
	CodeConflict = 409
	// CodeUploadFailed 上传出错
	CodeUploadFailed = 40002
	// CodeCreateFolderFailed 目录创建失败
	CodeCreateFolderFailed = 40003
	// CodeObjectExist 对象已存在
	CodeObjectExist = 40004
	// CodeSignExpired 签名过期
	CodeSignExpired = 40005
	// CodePolicyNotAllowed 当前存储策略不允许
	CodePolicyNotAllowed = 40006
	// CodeGroupNotAllowed 用户组无法进行此操作
	CodeGroupNotAllowed = 40007
	// CodeAdminRequired 非管理用户组
	CodeAdminRequired = 40008
	// CodeMasterNotFound 主机节点未注册
	CodeMasterNotFound = 40009
	// CodeUploadSessionExpired 上传会话已过期
	CodeUploadSessionExpired = 400011
	// CodeInvalidChunkIndex 无效的分片序号
	CodeInvalidChunkIndex = 400012
	// CodeInvalidContentLength 无效的正文长度
	CodeInvalidContentLength = 400013
	// CodeBatchSourceSize 超出批量获取外链限制
	CodeBatchSourceSize = 40014
	// CodeBatchAria2Size 超出最大 Aria2 任务数量限制
	CodeBatchAria2Size = 40015
	// CodeParentNotExist 父目录不存在
	CodeParentNotExist = 40016
	// CodeUserBaned 用户不活跃
	CodeUserBaned = 40017
	// CodeUserNotActivated 用户不活跃
	CodeUserNotActivated = 40018
	// CodeFeatureNotEnabled 此功能未开启
	CodeFeatureNotEnabled = 40019
	// CodeCredentialInvalid 凭证无效
	CodeCredentialInvalid = 40020
	// CodeUserNotFound 用户不存在
	CodeUserNotFound = 40021
	// Code2FACodeErr 二步验证代码错误
	Code2FACodeErr = 40022
	// CodeLoginSessionNotExist 登录会话不存在
	CodeLoginSessionNotExist = 40023
	// CodeInitializeAuthn 无法初始化 WebAuthn
	CodeInitializeAuthn = 40024
	// CodeWebAuthnCredentialError WebAuthn 凭证无效
	CodeWebAuthnCredentialError = 40025
	// CodeCaptchaError 验证码错误
	CodeCaptchaError = 40026
	// CodeCaptchaRefreshNeeded 验证码需要刷新
	CodeCaptchaRefreshNeeded = 40027
	// CodeFailedSendEmail 邮件发送失败
	CodeFailedSendEmail = 40028
	// CodeInvalidTempLink 临时链接无效
	CodeInvalidTempLink = 40029
	// CodeTempLinkExpired 临时链接过期
	CodeTempLinkExpired = 40030
	// CodeEmailExisted 邮箱已被使用
	CodeEmailExisted = 40032
	// CodeEmailSent 邮箱已重新发送
	CodeEmailSent = 40033
	// CodeUserCannotActivate 用户无法激活
	CodeUserCannotActivate = 40034
	// CodeDBError 数据库操作失败
	CodeDBError = 50001
	// CodeEncryptError 加密失败
	CodeEncryptError = 50002
	// CodeIOFailed IO操作失败
	CodeIOFailed = 50004
	// CodeInternalSetting 内部设置参数错误
	CodeInternalSetting = 50005
	// CodeCacheOperation 缓存操作失败
	CodeCacheOperation = 50006
	// CodeCallbackError 回调失败
	CodeCallbackError = 50007
	//CodeParamErr 各种奇奇怪怪的参数错误
	CodeParamErr = 40001
	// CodeNotSet 未定错误,后续尝试从error中获取
	CodeNotSet = -1
)

三位数错误编码为复用http原本含义 五位数错误编码为应用自定义错误 五开头的五位数错误编码为服务器端错误,比如数据库操作失败 四开头的五位数错误编码为客户端错误,有时候是客户端代码写错了,有时候是用户操作错误

View Source
const (
	SlaveTransferSuccess = "success"
	SlaveTransferFailed  = "failed"
)

Variables

This section is empty.

Functions

func NewRequestSignString

func NewRequestSignString(path, header, body string) string

NewRequestSignString 返回JSON格式的待签名字符串

Types

type AppError

type AppError struct {
	Code     int
	Msg      string
	RawError error
}

AppError 应用错误,实现了error接口

func NewError

func NewError(code int, msg string, err error) AppError

NewError 返回新的错误对象

func NewErrorFromResponse

func NewErrorFromResponse(resp *Response) AppError

NewErrorFromResponse 从 serializer.Response 构建错误

func (AppError) Error

func (err AppError) Error() string

Error 返回业务代码确定的可读错误信息

func (*AppError) WithError

func (err *AppError) WithError(raw error) AppError

WithError 将应用error携带标准库中的error

type DownloadListResponse

type DownloadListResponse struct {
	UpdateTime     time.Time      `json:"update"`
	UpdateInterval int            `json:"interval"`
	Name           string         `json:"name"`
	Status         int            `json:"status"`
	Dst            string         `json:"dst"`
	Total          uint64         `json:"total"`
	Downloaded     uint64         `json:"downloaded"`
	Speed          int            `json:"speed"`
	Info           rpc.StatusInfo `json:"info"`
}

DownloadListResponse 下载列表响应条目

type FinishedListResponse

type FinishedListResponse struct {
	Name       string         `json:"name"`
	GID        string         `json:"gid"`
	Status     int            `json:"status"`
	Dst        string         `json:"dst"`
	Error      string         `json:"error"`
	Total      uint64         `json:"total"`
	Files      []rpc.FileInfo `json:"files"`
	TaskStatus int            `json:"task_status"`
	TaskError  string         `json:"task_error"`
	CreateTime time.Time      `json:"create"`
	UpdateTime time.Time      `json:"update"`
}

FinishedListResponse 已完成任务条目

type GeneralUploadCallbackFailed

type GeneralUploadCallbackFailed struct {
	Error string `json:"error"`
}

GeneralUploadCallbackFailed 存储策略上传回调失败响应

type ListRequest

type ListRequest struct {
	Path      string `json:"path"`
	Recursive bool   `json:"recursive"`
}

ListRequest 远程策略列文件请求正文

type NodePingReq

type NodePingReq struct {
	SiteURL       string      `json:"site_url"`
	SiteID        string      `json:"site_id"`
	IsUpdate      bool        `json:"is_update"`
	CredentialTTL int         `json:"credential_ttl"`
	Node          *model.Node `json:"node"`
}

NodePingReq 从机节点Ping请求

type NodePingResp

type NodePingResp struct {
}

NodePingResp 从机节点Ping响应

type Object

type Object struct {
	ID            string    `json:"id"`
	Name          string    `json:"name"`
	Path          string    `json:"path"`
	Pic           string    `json:"pic"`
	Size          uint64    `json:"size"`
	Type          string    `json:"type"`
	Date          time.Time `json:"date"`
	CreateDate    time.Time `json:"create_date"`
	Key           string    `json:"key,omitempty"`
	SourceEnabled bool      `json:"source_enabled"`
}

Object 文件或者目录

type ObjectList

type ObjectList struct {
	Parent  string         `json:"parent,omitempty"`
	Objects []Object       `json:"objects"`
	Policy  *PolicySummary `json:"policy,omitempty"`
}

ObjectList 文件、目录列表

func BuildObjectList

func BuildObjectList(parent uint, objects []Object, policy *model.Policy) ObjectList

BuildObjectList 构建列目录响应

type ObjectProps

type ObjectProps struct {
	CreatedAt      time.Time `json:"created_at"`
	UpdatedAt      time.Time `json:"updated_at"`
	Policy         string    `json:"policy"`
	Size           uint64    `json:"size"`
	ChildFolderNum int       `json:"child_folder_num"`
	ChildFileNum   int       `json:"child_file_num"`
	Path           string    `json:"path"`

	QueryDate time.Time `json:"query_date"`
}

ObjectProps 文件、目录对象的详细属性信息

type PolicySummary

type PolicySummary struct {
	ID       string   `json:"id"`
	Name     string   `json:"name"`
	Type     string   `json:"type"`
	MaxSize  uint64   `json:"max_size"`
	FileType []string `json:"file_type"`
}

PolicySummary 用于前端组件使用的存储策略概况

type RemoteDeleteRequest

type RemoteDeleteRequest struct {
	Files []string `json:"files"`
}

RemoteDeleteRequest 远程策略删除接口请求正文

type RequestRawSign

type RequestRawSign struct {
	Path   string
	Header string
	Body   string
}

RequestRawSign 待签名的HTTP请求

type Response

type Response struct {
	Code  int         `json:"code"`
	Data  interface{} `json:"data,omitempty"`
	Msg   string      `json:"msg"`
	Error string      `json:"error,omitempty"`
}

Response 基础序列化器

func BuildDownloadingResponse

func BuildDownloadingResponse(tasks []model.Download, intervals map[uint]int) Response

BuildDownloadingResponse 构建正在下载的列表响应

func BuildFinishedListResponse

func BuildFinishedListResponse(tasks []model.Download) Response

BuildFinishedListResponse 构建已完成任务条目

func BuildShareList

func BuildShareList(shares []model.Share, total int) Response

BuildShareList 构建我的分享列表响应

func BuildSiteConfig

func BuildSiteConfig(settings map[string]string, user *model.User) Response

BuildSiteConfig 站点全局设置

func BuildTaskList

func BuildTaskList(tasks []model.Task, total int) Response

BuildTaskList 构建任务列表响应

func BuildUserResponse

func BuildUserResponse(user model.User) Response

BuildUserResponse 序列化用户响应

func BuildUserStorageResponse

func BuildUserStorageResponse(user model.User) Response

BuildUserStorageResponse 序列化用户存储概况响应

func CheckLogin

func CheckLogin() Response

CheckLogin 检查登录

func DBErr

func DBErr(msg string, err error) Response

DBErr 数据库操作失败

func Err

func Err(errCode int, msg string, err error) Response

Err 通用错误处理

func NewResponseWithGobData

func NewResponseWithGobData(data interface{}) Response

NewResponseWithGobData 返回Data字段使用gob编码的Response

func ParamErr

func ParamErr(msg string, err error) Response

ParamErr 各种参数错误

func (*Response) GobDecode

func (r *Response) GobDecode(target interface{})

GobDecode 将 Response 正文解码至目标指针

type Share

type Share struct {
	Key        string        `json:"key"`
	Locked     bool          `json:"locked"`
	IsDir      bool          `json:"is_dir"`
	CreateDate time.Time     `json:"create_date,omitempty"`
	Downloads  int           `json:"downloads"`
	Views      int           `json:"views"`
	Expire     int64         `json:"expire"`
	Preview    bool          `json:"preview"`
	Creator    *shareCreator `json:"creator,omitempty"`
	Source     *shareSource  `json:"source,omitempty"`
}

Share 分享信息序列化

func BuildShareResponse

func BuildShareResponse(share *model.Share, unlocked bool) Share

BuildShareResponse 构建获取分享信息响应

type SiteConfig

type SiteConfig struct {
	SiteName             string `json:"title"`
	LoginCaptcha         bool   `json:"loginCaptcha"`
	RegCaptcha           bool   `json:"regCaptcha"`
	ForgetCaptcha        bool   `json:"forgetCaptcha"`
	EmailActive          bool   `json:"emailActive"`
	Themes               string `json:"themes"`
	DefaultTheme         string `json:"defaultTheme"`
	HomepageViewMethod   string `json:"home_view_method"`
	ShareViewMethod      string `json:"share_view_method"`
	Authn                bool   `json:"authn"`
	User                 User   `json:"user"`
	ReCaptchaKey         string `json:"captcha_ReCaptchaKey"`
	CaptchaType          string `json:"captcha_type"`
	TCaptchaCaptchaAppId string `json:"tcaptcha_captcha_app_id"`
	RegisterEnabled      bool   `json:"registerEnabled"`
}

SiteConfig 站点全局设置序列

type SlaveAria2Call

type SlaveAria2Call struct {
	Task         *model.Download        `json:"task"`
	GroupOptions map[string]interface{} `json:"group_options"`
	Files        []int                  `json:"files"`
}

SlaveAria2Call 从机有关Aria2的请求正文

type SlaveTransferReq

type SlaveTransferReq struct {
	Src    string        `json:"src"`
	Dst    string        `json:"dst"`
	Policy *model.Policy `json:"policy"`
}

SlaveTransferReq 从机中转任务创建请求

func (*SlaveTransferReq) Hash

func (s *SlaveTransferReq) Hash(id string) string

Hash 返回创建请求的唯一标识,保持创建请求幂等

type SlaveTransferResult

type SlaveTransferResult struct {
	Error string
}

type Sources

type Sources struct {
	URL    string `json:"url"`
	Name   string `json:"name"`
	Parent uint   `json:"parent"`
	Error  string `json:"error,omitempty"`
}

Sources 获取外链的结果响应

type UploadCallback

type UploadCallback struct {
	PicInfo string `json:"pic_info"`
}

UploadCallback 上传回调正文

type UploadCredential

type UploadCredential struct {
	SessionID   string   `json:"sessionID"`
	ChunkSize   uint64   `json:"chunkSize"` // 分块大小,0 为部分快
	Expires     int64    `json:"expires"`   // 上传凭证过期时间, Unix 时间戳
	UploadURLs  []string `json:"uploadURLs,omitempty"`
	Credential  string   `json:"credential,omitempty"`
	UploadID    string   `json:"uploadID,omitempty"`
	Callback    string   `json:"callback,omitempty"` // 回调地址
	Path        string   `json:"path,omitempty"`     // 存储路径
	AccessKey   string   `json:"ak,omitempty"`
	KeyTime     string   `json:"keyTime,omitempty"` // COS用有效期
	Policy      string   `json:"policy,omitempty"`
	CompleteURL string   `json:"completeURL,omitempty"`
	Url         string   `json:"url,omitempty"`
}

UploadCredential 返回给客户端的上传凭证

type UploadPolicy

type UploadPolicy struct {
	SavePath         string   `json:"save_path"`
	FileName         string   `json:"file_name"`
	AutoRename       bool     `json:"auto_rename"`
	MaxSize          uint64   `json:"max_size"`
	AllowedExtension []string `json:"allowed_extension"`
	CallbackURL      string   `json:"callback_url"`
}

UploadPolicy slave模式下传递的上传策略

type UploadSession

type UploadSession struct {
	Key            string     // 上传会话 GUID
	UID            uint       // 发起者
	VirtualPath    string     // 用户文件路径,不含文件名
	Name           string     // 文件名
	Size           uint64     // 文件大小
	SavePath       string     // 物理存储路径,包含物理文件名
	LastModified   *time.Time // 可选的文件最后修改日期
	Policy         model.Policy
	Callback       string // 回调 URL 地址
	CallbackSecret string // 回调 URL
	UploadURL      string
	UploadID       string
	Credential     string
	EncodePath     string
}

UploadSession 上传会话

type User

type User struct {
	ID             string    `json:"id"`
	Email          string    `json:"user_name"`
	Nickname       string    `json:"nickname"`
	Status         int       `json:"status"`
	Avatar         string    `json:"avatar"`
	CreatedAt      time.Time `json:"created_at"`
	PreferredTheme string    `json:"preferred_theme"`
	Anonymous      bool      `json:"anonymous"`
	Group          group     `json:"group"`
	Tags           []tag     `json:"tags"`
}

User 用户序列化器

func BuildUser

func BuildUser(user model.User) User

BuildUser 序列化用户

type WebAuthnCredentials

type WebAuthnCredentials struct {
	ID          []byte `json:"id"`
	FingerPrint string `json:"fingerprint"`
}

WebAuthnCredentials 外部验证器凭证

func BuildWebAuthnList

func BuildWebAuthnList(credentials []webauthn.Credential) []WebAuthnCredentials

BuildWebAuthnList 构建设置页面凭证列表

Jump to

Keyboard shortcuts

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