Feat: hash id decode and verification

This commit is contained in:
HFO4
2020-01-26 14:57:07 +08:00
parent 880d224169
commit 94b13393a9
7 changed files with 111 additions and 5 deletions

View File

@@ -197,8 +197,7 @@ func (policy *Policy) GetUploadURL() string {
var controller *url.URL
switch policy.Type {
case "local", "onedrive":
server = GetSiteURL()
controller, _ = url.Parse("/api/v3/file/upload")
return "/api/v3/file/upload"
case "remote":
controller, _ = url.Parse("/api/v3/slave/upload")
case "oss", "cos":

View File

@@ -1,6 +1,7 @@
package model
import (
"github.com/HFO4/cloudreve/pkg/hashid"
"github.com/HFO4/cloudreve/pkg/util"
"github.com/jinzhu/gorm"
"time"
@@ -29,3 +30,18 @@ func (share *Share) Create() (uint, error) {
}
return share.ID, nil
}
// GetShareByHashID 根据HashID查找分享
func GetShareByHashID(hashID string) *Share {
id, err := hashid.DecodeHashID(hashID, hashid.ShareID)
if err != nil {
return nil
}
var share Share
result := DB.First(&share, id)
if result.Error != nil {
return nil
}
return &share
}

View File

@@ -233,3 +233,17 @@ func (user *User) SetPassword(password string) error {
user.Password = salt + ":" + string(bs)
return nil
}
// NewAnonymousUser 返回一个匿名用户
// TODO 测试
func NewAnonymousUser() *User {
user := User{}
user.Group, _ = GetGroupByID(3)
return &user
}
// IsAnonymous 返回是否为未登录用户
// TODO 测试
func (user *User) IsAnonymous() bool {
return user.ID == 0
}