serializer

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 5, 2024 License: MIT Imports: 3 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 = 40011
	// CodeInvalidChunkIndex 无效的分片序号
	CodeInvalidChunkIndex = 40012
	// CodeInvalidContentLength 无效的正文长度
	CodeInvalidContentLength = 40013
	// CodePhoneRequired 未绑定手机
	CodePhoneRequired = 40010
	// 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
	// CodeEmailProviderBaned 邮箱后缀被禁用
	CodeEmailProviderBaned = 40031
	// CodeEmailExisted 邮箱已被使用
	CodeEmailExisted = 40032
	// CodeEmailSent 邮箱已重新发送
	CodeEmailSent = 40033
	// CodeUserCannotActivate 用户无法激活
	CodeUserCannotActivate = 40034
	// 存储策略不存在
	CodePolicyNotExist = 40035
	// 无法删除默认存储策略
	CodeDeleteDefaultPolicy = 40036
	// 存储策略下还有文件
	CodePolicyUsedByFiles = 40037
	// 存储策略绑定了用户组
	CodePolicyUsedByGroups = 40038
	// 用户组不存在
	CodeGroupNotFound = 40039
	// 对系统用户组执行非法操作
	CodeInvalidActionOnSystemGroup = 40040
	// 用户组正在被使用
	CodeGroupUsedByUser = 40041
	// 为初始用户更改用户组
	CodeChangeGroupForDefaultUser = 40042
	// 对系统用户执行非法操作
	CodeInvalidActionOnDefaultUser = 40043
	// 文件不存在
	CodeFileNotFound = 40044
	// 列取文件失败
	CodeListFilesError = 40045
	// 对系统节点进行非法操作
	CodeInvalidActionOnSystemNode = 40046
	// 创建文件系统出错
	CodeCreateFSError = 40047
	// 创建任务出错
	CodeCreateTaskError = 40048
	// 文件尺寸太大
	CodeFileTooLarge = 40049
	// 文件类型不允许
	CodeFileTypeNotAllowed = 40050
	// 用户容量不足
	CodeInsufficientCapacity = 40051
	// 对象名非法
	CodeIllegalObjectName = 40052
	// 不支持对根目录执行此操作
	CodeRootProtected = 40053
	// 当前目录下已经有同名文件正在上传中
	CodeConflictUploadOngoing = 40054
	// 文件信息不一致
	CodeMetaMismatch = 40055
	// 不支持该格式的压缩文件
	CodeUnsupportedArchiveType = 40056
	// 可用存储策略发生变化
	CodePolicyChanged = 40057
	// 分享链接无效
	CodeShareLinkNotFound = 40058
	// 不能转存自己的分享
	CodeSaveOwnShare = 40059
	// 从机无法向主机发送回调请求
	CodeSlavePingMaster = 40060
	// Cloudreve 版本不一致
	CodeVersionMismatch = 40061
	// 积分不足
	CodeInsufficientCredit = 40062
	// 用户组冲突
	CodeGroupConflict = 40063
	// 当前已处于此用户组中
	CodeGroupInvalid = 40064
	// 兑换码无效
	CodeInvalidGiftCode = 40065
	// 已绑定了QQ账号
	CodeQQBindConflict = 40066
	// QQ账号已被绑定其他账号
	CodeQQBindOtherAccount = 40067
	// QQ 未绑定对应账号
	CodeQQNotLinked = 40068
	// 密码不正确
	CodeIncorrectPassword = 40069
	// 分享无法预览
	CodeDisabledSharePreview = 40070
	// 签名无效
	CodeInvalidSign = 40071
	// 管理员无法购买用户组
	CodeFulfillAdminGroup = 40072
	// CodeDBError 数据库操作失败
	CodeDBError = 50001
	// CodeEncryptError 加密失败
	CodeEncryptError = 50002
	// CodeIOFailed IO操作失败
	CodeIOFailed = 50004
	// CodeInternalSetting 内部设置参数错误
	CodeInternalSetting = 50005
	// CodeCacheOperation 缓存操作失败
	CodeCacheOperation = 50006
	// CodeCallbackError 回调失败
	CodeCallbackError = 50007
	// 后台设置更新失败
	CodeUpdateSetting = 50008
	// 跨域策略添加失败
	CodeAddCORS = 50009
	// 节点不可用
	CodeNodeOffline = 50010
	// 文件元信息查询失败
	CodeQueryMetaFailed = 50011
	//CodeParamErr 各种奇奇怪怪的参数错误
	CodeParamErr = 40001
	// CodeNotSet 未定错误,后续尝试从error中获取
	CodeNotSet = -1
)

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

Variables

View Source
var CodeMap = map[int]string{
	CodeNotFullySuccess:            `未完全成功`,
	CodeCheckLogin:                 `未登录`,
	CodeNoPermissionErr:            `未授权访问`,
	CodeNotFound:                   `资源未找到`,
	CodeConflict:                   `资源冲突`,
	CodeUploadFailed:               `上传出错`,
	CodeCreateFolderFailed:         `目录创建失败`,
	CodeObjectExist:                `对象已存在`,
	CodeSignExpired:                `签名过期`,
	CodePolicyNotAllowed:           `当前存储策略不允许`,
	CodeGroupNotAllowed:            `用户组无法进行此操作`,
	CodeAdminRequired:              `非管理用户组`,
	CodeMasterNotFound:             `主机节点未注册`,
	CodeUploadSessionExpired:       `上传会话已过期`,
	CodeInvalidChunkIndex:          `无效的分片序号`,
	CodeInvalidContentLength:       `无效的正文长度`,
	CodePhoneRequired:              `未绑定手机`,
	CodeBatchSourceSize:            `超出批量获取外链限制`,
	CodeBatchAria2Size:             `超出最大 Aria2 任务数量限制`,
	CodeParentNotExist:             `父目录不存在`,
	CodeUserBaned:                  `用户被封禁`,
	CodeUserNotActivated:           `用户不活跃`,
	CodeFeatureNotEnabled:          `此功能未开启`,
	CodeCredentialInvalid:          `凭证无效`,
	CodeUserNotFound:               `用户不存在`,
	Code2FACodeErr:                 `二步验证代码错误`,
	CodeLoginSessionNotExist:       `登录会话不存在`,
	CodeInitializeAuthn:            `无法初始化 WebAuthn`,
	CodeWebAuthnCredentialError:    `WebAuthn 凭证无效`,
	CodeCaptchaError:               `验证码错误`,
	CodeCaptchaRefreshNeeded:       `验证码需要刷新`,
	CodeFailedSendEmail:            `邮件发送失败`,
	CodeInvalidTempLink:            `临时链接无效`,
	CodeTempLinkExpired:            `临时链接过期`,
	CodeEmailProviderBaned:         `邮箱后缀被禁用`,
	CodeEmailExisted:               `邮箱已被使用`,
	CodeEmailSent:                  `邮箱已重新发送`,
	CodeUserCannotActivate:         `用户无法激活`,
	CodePolicyNotExist:             `存储策略不存在`,
	CodeDeleteDefaultPolicy:        `无法删除默认存储策略`,
	CodePolicyUsedByFiles:          `存储策略下还有文件`,
	CodePolicyUsedByGroups:         `存储策略绑定了用户组`,
	CodeGroupNotFound:              `用户组不存在`,
	CodeInvalidActionOnSystemGroup: `对系统用户组执行非法操作`,
	CodeGroupUsedByUser:            `用户组正在被使用`,
	CodeChangeGroupForDefaultUser:  `为初始用户更改用户组`,
	CodeInvalidActionOnDefaultUser: `对系统用户执行非法操作`,
	CodeFileNotFound:               `文件不存在`,
	CodeListFilesError:             `列取文件失败`,
	CodeInvalidActionOnSystemNode:  `对系统节点进行非法操作`,
	CodeCreateFSError:              `创建文件系统出错`,
	CodeCreateTaskError:            `创建任务出错`,
	CodeFileTooLarge:               `文件尺寸太大`,
	CodeFileTypeNotAllowed:         `文件类型不允许`,
	CodeInsufficientCapacity:       `用户容量不足`,
	CodeIllegalObjectName:          `对象名非法`,
	CodeRootProtected:              `不支持对根目录执行此操作`,
	CodeConflictUploadOngoing:      `当前目录下已经有同名文件正在上传中`,
	CodeMetaMismatch:               `文件信息不一致`,
	CodeUnsupportedArchiveType:     `不支持该格式的压缩文件`,
	CodePolicyChanged:              `可用存储策略发生变化`,
	CodeShareLinkNotFound:          `分享链接无效`,
	CodeSaveOwnShare:               `不能转存自己的分享`,
	CodeSlavePingMaster:            `从机无法向主机发送回调请求`,
	CodeVersionMismatch:            `Cloudreve 版本不一致`,
	CodeInsufficientCredit:         `积分不足`,
	CodeGroupConflict:              `用户组冲突`,
	CodeGroupInvalid:               `当前已处于此用户组中`,
	CodeInvalidGiftCode:            `兑换码无效`,
	CodeQQBindConflict:             `已绑定了QQ账号`,
	CodeQQBindOtherAccount:         `QQ账号已被绑定其他账号`,
	CodeQQNotLinked:                `QQ 未绑定对应账号`,
	CodeIncorrectPassword:          `密码不正确`,
	CodeDisabledSharePreview:       `分享无法预览`,
	CodeInvalidSign:                `签名无效`,
	CodeFulfillAdminGroup:          `管理员无法购买用户组`,
	CodeDBError:                    `数据库操作失败`,
	CodeEncryptError:               `加密失败`,
	CodeIOFailed:                   `IO操作失败`,
	CodeInternalSetting:            `内部设置参数错误`,
	CodeCacheOperation:             `缓存操作失败`,
	CodeCallbackError:              `回调失败`,
	CodeUpdateSetting:              `后台设置更新失败`,
	CodeAddCORS:                    `跨域策略添加失败`,
	CodeNodeOffline:                `节点不可用`,
	CodeQueryMetaFailed:            `文件元信息查询失败`,
	CodeParamErr:                   `各种奇奇怪怪的参数错误`,
	CodeNotSet:                     `未定错误,后续尝试从error中获取`,
}

Functions

This section is empty.

Types

type AppError

type AppError struct {
	Code int
	Msg  string
}

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

func (AppError) Error

func (err AppError) Error() string

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

type CaptchaReq

type CaptchaReq struct {
	CaptchaCode string `json:"captchaCode"`
	Ticket      string `json:"ticket,omitempty"`
	Randstr     string `json:"randstr,omitempty"`
}

type DocPreviewSession

type DocPreviewSession struct {
	URL            string `json:"url"`
	AccessToken    string `json:"access_token,omitempty"`
	AccessTokenTTL int64  `json:"access_token_ttl,omitempty"`
}

DocPreviewSession 文档预览会话响应

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"`
	NodeName       string         `json:"node"`
}

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"`
	NodeName   string         `json:"node"`
}

FinishedListResponse 已完成任务条目

type GroupProducts

type GroupProducts struct {
	ID        int64    `json:"id"`
	Name      string   `json:"name"`
	GroupID   uint     `json:"group_id"`
	Time      int64    `json:"time"`
	Price     int      `json:"price"`
	Score     int      `json:"score"`
	Des       []string `json:"des"`
	Highlight bool     `json:"highlight"`
}

GroupProducts 用户组商品

type MountedFolders

type MountedFolders struct {
	ID         string `json:"id"`
	Name       string `json:"name"`
	PolicyName string `json:"policy_name"`
}

MountedFolders 已挂载的目录

type NodeOptions

type NodeOptions struct {
	Name string `json:"name"`
	ID   uint   `json:"id"`
}

type Object

type Object struct {
	ID            string    `json:"id"`
	Name          string    `json:"name"`
	Path          string    `json:"path"`
	Thumb         bool      `json:"thumb"`
	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 文件、目录列表

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 PackProduct

type PackProduct struct {
	ID    int64  `json:"id"`
	Name  string `json:"name"`
	Size  uint64 `json:"size"`
	Time  int64  `json:"time"`
	Price int    `json:"price"`
	Score int    `json:"score"`
}

PackProduct 容量包商品

type PolicyOptions

type PolicyOptions struct {
	Name string `json:"name"`
	ID   string `json:"id"`
}

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 ProductData

type ProductData struct {
	Packs      []PackProduct   `json:"packs"`
	Groups     []GroupProducts `json:"groups"`
	Alipay     bool            `json:"alipay"`
	Wechat     bool            `json:"wechat"`
	Payjs      bool            `json:"payjs"`
	Custom     bool            `json:"custom"`
	CustomName string          `json:"custom_name"`
	ScorePrice int             `json:"score_price"`
}

增值服务商品响应

type Quota

type Quota struct {
	Base  uint64         `json:"base"`
	Pack  uint64         `json:"pack"`
	Used  uint64         `json:"used"`
	Total uint64         `json:"total"`
	Packs []storagePacks `json:"packs"`
}

type Response

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

Response 基础序列化器

func (*Response[T]) Err

func (c *Response[T]) Err() error

实现错误检测接口

type Share

type Share struct {
	Key        string        `json:"key"`
	Locked     bool          `json:"locked"`
	IsDir      bool          `json:"is_dir"`
	Score      int           `json:"score"`
	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 分享信息序列化

type ShareList

type ShareList struct {
	Total int           `json:"total"`
	Items []myShareItem `json:"items"`
	User  struct {
		ID    string `json:"id"`
		Nick  string `json:"nick"`
		Group string `json:"group"`
		Date  string `json:"date"`
	} `json:"user"`
}

我的分享列表响应

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"`
	QQLogin              bool     `json:"QQLogin"`
	Themes               string   `json:"themes"`
	DefaultTheme         string   `json:"defaultTheme"`
	ScoreEnabled         bool     `json:"score_enabled"`
	ShareScoreRate       string   `json:"share_score_rate"`
	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"`
	SiteNotice           string   `json:"site_notice"`
	CaptchaType          string   `json:"captcha_type"`
	TCaptchaCaptchaAppId string   `json:"tcaptcha_captcha_app_id"`
	RegisterEnabled      bool     `json:"registerEnabled"`
	ReportEnabled        bool     `json:"report_enabled"`
	AppPromotion         bool     `json:"app_promotion"`
	WopiExts             []string `json:"wopi_exts"`
	AppFeedbackLink      string   `json:"app_feedback"`
	AppForumLink         string   `json:"app_forum"`
}

SiteConfig 站点全局设置序列

type Sources

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

Sources 获取外链的结果响应

type Storage

type Storage struct {
	Used  uint64 `json:"used"`
	Free  uint64 `json:"free"`
	Total uint64 `json:"total"`
}

type Task

type Task struct {
	Status     int       `json:"status"`
	Type       int       `json:"type"`
	CreateDate time.Time `json:"create_date"`
	Progress   int       `json:"progress"`
	Error      string    `json:"error"`
}

type TaskList

type TaskList struct {
	Total int    `json:"total"`
	Tasks []Task `json:"tasks"`
}

任务列表响应

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"`
}

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

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"`
	Score          int       `json:"score"`
	Anonymous      bool      `json:"anonymous"`
	Group          group     `json:"group"`
	Tags           []tag     `json:"tags"`
}

User 用户序列化器

type VolResponse

type VolResponse struct {
	Signature string `json:"signature"`
	Content   string `json:"content"`
}

VolResponse VOL query response

type WebAuthnCredentials

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

WebAuthnCredentials 外部验证器凭证

Jump to

Keyboard shortcuts

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