Feat: list files for shared folder

This commit is contained in:
HFO4
2020-01-30 13:21:21 +08:00
parent a0c320b964
commit 0edbbfc9ea
7 changed files with 115 additions and 26 deletions

View File

@ -49,6 +49,30 @@ func ShareCanPreview() gin.HandlerFunc {
}
}
// CheckShareUnlocked 检查分享是否已解锁
func CheckShareUnlocked() gin.HandlerFunc {
return func(c *gin.Context) {
if shareCtx, ok := c.Get("share"); ok {
share := shareCtx.(*model.Share)
// 分享是否已解锁
if share.Password != "" {
sessionKey := fmt.Sprintf("share_unlock_%d", share.ID)
unlocked := util.GetSession(c, sessionKey) != nil
if !unlocked {
c.JSON(200, serializer.Err(serializer.CodeNoPermissionErr,
"无权访问此分享", nil))
c.Abort()
return
}
}
c.Next()
return
}
c.Abort()
}
}
// BeforeShareDownload 分享被下载前的检查
func BeforeShareDownload() gin.HandlerFunc {
return func(c *gin.Context) {
@ -66,18 +90,6 @@ func BeforeShareDownload() gin.HandlerFunc {
return
}
// 分享是否已解锁
if share.Password != "" {
sessionKey := fmt.Sprintf("share_unlock_%d", share.ID)
unlocked := util.GetSession(c, sessionKey) != nil
if !unlocked {
c.JSON(200, serializer.Err(serializer.CodeNoPermissionErr,
"无权访问此分享", nil))
c.Abort()
return
}
}
// 对积分、下载次数进行更新
err = share.DownloadBy(user, c)
if err != nil {