mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Feat: hash id decode and verification
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user