mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Feat: generate share URL
This commit is contained in:
@@ -22,6 +22,7 @@ type system struct {
|
||||
Listen string `validate:"required"`
|
||||
Debug bool
|
||||
SessionSecret string
|
||||
HashIDSalt string `validate:"required"`
|
||||
}
|
||||
|
||||
// slave 作为slave存储端配置
|
||||
|
||||
33
pkg/hashid/hash.go
Normal file
33
pkg/hashid/hash.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package hashid
|
||||
|
||||
import "github.com/HFO4/cloudreve/pkg/conf"
|
||||
import "github.com/speps/go-hashids"
|
||||
|
||||
// ID类型
|
||||
const (
|
||||
ShareID = iota // 分享
|
||||
UserID // 用户
|
||||
)
|
||||
|
||||
// HashEncode 对给定数据计算HashID
|
||||
func HashEncode(v []int) (string, error) {
|
||||
hd := hashids.NewData()
|
||||
hd.Salt = conf.SystemConfig.HashIDSalt
|
||||
|
||||
h, err := hashids.NewWithData(hd)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
id, err := h.Encode(v)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return id, nil
|
||||
}
|
||||
|
||||
// HashID 计算数据库内主键对应的HashID
|
||||
func HashID(id uint, t int) string {
|
||||
v, _ := HashEncode([]int{int(id), t})
|
||||
return v
|
||||
}
|
||||
@@ -48,6 +48,8 @@ const (
|
||||
CodeCheckLogin = 401
|
||||
// CodeNoRightErr 未授权访问
|
||||
CodeNoRightErr = 403
|
||||
// CodeNotFound 资源未找到
|
||||
CodeNotFound = 404
|
||||
// CodeUploadFailed 上传出错
|
||||
CodeUploadFailed = 40002
|
||||
// CodeCreateFolderFailed 目录创建失败
|
||||
|
||||
@@ -4,15 +4,17 @@ import model "github.com/HFO4/cloudreve/models"
|
||||
|
||||
// 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"`
|
||||
User User `json:"user"`
|
||||
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"`
|
||||
User User `json:"user"`
|
||||
}
|
||||
|
||||
func checkSettingValue(setting map[string]string, key string) string {
|
||||
@@ -30,14 +32,16 @@ func BuildSiteConfig(settings map[string]string, user *model.User) Response {
|
||||
}
|
||||
return Response{
|
||||
Data: SiteConfig{
|
||||
SiteName: checkSettingValue(settings, "siteName"),
|
||||
LoginCaptcha: model.IsTrueVal(checkSettingValue(settings, "login_captcha")),
|
||||
RegCaptcha: model.IsTrueVal(checkSettingValue(settings, "reg_captcha")),
|
||||
ForgetCaptcha: model.IsTrueVal(checkSettingValue(settings, "forget_captcha")),
|
||||
EmailActive: model.IsTrueVal(checkSettingValue(settings, "email_active")),
|
||||
QQLogin: model.IsTrueVal(checkSettingValue(settings, "qq_login")),
|
||||
Themes: checkSettingValue(settings, "themes"),
|
||||
DefaultTheme: checkSettingValue(settings, "defaultTheme"),
|
||||
User: userRes,
|
||||
SiteName: checkSettingValue(settings, "siteName"),
|
||||
LoginCaptcha: model.IsTrueVal(checkSettingValue(settings, "login_captcha")),
|
||||
RegCaptcha: model.IsTrueVal(checkSettingValue(settings, "reg_captcha")),
|
||||
ForgetCaptcha: model.IsTrueVal(checkSettingValue(settings, "forget_captcha")),
|
||||
EmailActive: model.IsTrueVal(checkSettingValue(settings, "email_active")),
|
||||
QQLogin: model.IsTrueVal(checkSettingValue(settings, "qq_login")),
|
||||
Themes: checkSettingValue(settings, "themes"),
|
||||
DefaultTheme: checkSettingValue(settings, "defaultTheme"),
|
||||
ScoreEnabled: model.IsTrueVal(checkSettingValue(settings, "score_enabled")),
|
||||
ShareScoreRate: checkSettingValue(settings, "share_score_rate"),
|
||||
User: userRes,
|
||||
}}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user