mirror of https://github.com/cloudreve/Cloudreve
fix(share): share link should be marked as expired if the file is in trash bin (#2347)
parent
edd50147e7
commit
762811d50f
2
assets
2
assets
|
@ -1 +1 @@
|
|||
Subproject commit 8e96f4d3de2519f374dc6d49d2fb2a68d859c33f
|
||||
Subproject commit 614ed4ed590adcb61ed4e01a0536a0c473f3a5c9
|
|
@ -274,7 +274,7 @@ type Share struct {
|
|||
}
|
||||
|
||||
func BuildShare(s *ent.Share, base *url.URL, hasher hashid.Encoder, requester *ent.User, owner *ent.User,
|
||||
name string, t types.FileType, unlocked bool) *Share {
|
||||
name string, t types.FileType, unlocked bool, expired bool) *Share {
|
||||
redactLevel := user.RedactLevelAnonymous
|
||||
if !inventory.IsAnonymousUser(requester) {
|
||||
redactLevel = user.RedactLevelUser
|
||||
|
@ -284,7 +284,7 @@ func BuildShare(s *ent.Share, base *url.URL, hasher hashid.Encoder, requester *e
|
|||
ID: hashid.EncodeShareID(hasher, s.ID),
|
||||
Unlocked: unlocked,
|
||||
Owner: user.BuildUserRedacted(owner, redactLevel, hasher),
|
||||
Expired: inventory.IsShareExpired(s) != nil,
|
||||
Expired: inventory.IsShareExpired(s) != nil || expired,
|
||||
Url: BuildShareLink(s, hasher, base),
|
||||
CreatedAt: s.CreatedAt,
|
||||
Visited: s.Views,
|
||||
|
@ -374,7 +374,7 @@ func BuildExtendedInfo(ctx context.Context, u *ent.User, f fs.File, hasher hashi
|
|||
if u.ID == f.OwnerID() {
|
||||
// Only owner can see the shares settings.
|
||||
ext.Shares = lo.Map(extendedInfo.Shares, func(s *ent.Share, index int) Share {
|
||||
return *BuildShare(s, base, hasher, u, u, f.DisplayName(), f.Type(), true)
|
||||
return *BuildShare(s, base, hasher, u, u, f.DisplayName(), f.Type(), true, false)
|
||||
})
|
||||
|
||||
}
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
package share
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
|
||||
"github.com/cloudreve/Cloudreve/v4/ent"
|
||||
"github.com/cloudreve/Cloudreve/v4/inventory"
|
||||
"github.com/cloudreve/Cloudreve/v4/inventory/types"
|
||||
"github.com/cloudreve/Cloudreve/v4/pkg/filemanager/fs"
|
||||
"github.com/cloudreve/Cloudreve/v4/pkg/filemanager/fs/dbfs"
|
||||
"github.com/cloudreve/Cloudreve/v4/pkg/hashid"
|
||||
"github.com/cloudreve/Cloudreve/v4/service/explorer"
|
||||
"net/url"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
type ListShareResponse struct {
|
||||
|
@ -17,8 +21,23 @@ type ListShareResponse struct {
|
|||
func BuildListShareResponse(res *inventory.ListShareResult, hasher hashid.Encoder, base *url.URL, requester *ent.User, unlocked bool) *ListShareResponse {
|
||||
var infos []explorer.Share
|
||||
for _, share := range res.Shares {
|
||||
infos = append(infos, *explorer.BuildShare(share, base, hasher, requester, share.Edges.User, share.Edges.File.Name,
|
||||
types.FileType(share.Edges.File.Type), unlocked))
|
||||
expired := inventory.IsValidShare(share) != nil
|
||||
shareName := share.Edges.File.Name
|
||||
if share.Edges.File.FileChildren == 0 && len(share.Edges.File.Edges.Metadata) >= 0 {
|
||||
// For files in trash bin, read the real name from metadata
|
||||
restoreUri, found := lo.Find(share.Edges.File.Edges.Metadata, func(m *ent.Metadata) bool {
|
||||
return m.Name == dbfs.MetadataRestoreUri
|
||||
})
|
||||
if found {
|
||||
uri, err := fs.NewUriFromString(restoreUri.Value)
|
||||
if err == nil {
|
||||
shareName = uri.Name()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
infos = append(infos, *explorer.BuildShare(share, base, hasher, requester, share.Edges.User, shareName,
|
||||
types.FileType(share.Edges.File.Type), unlocked, expired))
|
||||
}
|
||||
|
||||
return &ListShareResponse{
|
||||
|
|
|
@ -68,7 +68,7 @@ func (s *ShareInfoService) Get(c *gin.Context) (*explorer.Share, error) {
|
|||
|
||||
base := dep.SettingProvider().SiteURL(c)
|
||||
res := explorer.BuildShare(share, base, dep.HashIDEncoder(), u, share.Edges.User, share.Edges.File.Name,
|
||||
types.FileType(share.Edges.File.Type), unlocked)
|
||||
types.FileType(share.Edges.File.Type), unlocked, false)
|
||||
|
||||
if s.OwnerExtended && share.Edges.User.ID == u.ID {
|
||||
// Add more information about the shared file
|
||||
|
@ -121,6 +121,7 @@ func (s *ListShareService) List(c *gin.Context) (*ListShareResponse, error) {
|
|||
|
||||
ctx := context.WithValue(c, inventory.LoadShareUser{}, true)
|
||||
ctx = context.WithValue(ctx, inventory.LoadShareFile{}, true)
|
||||
ctx = context.WithValue(ctx, inventory.LoadFileMetadata{}, true)
|
||||
res, err := shareClient.List(ctx, args)
|
||||
if err != nil {
|
||||
return nil, serializer.NewError(serializer.CodeDBError, "Failed to list shares", err)
|
||||
|
@ -150,6 +151,7 @@ func (s *ListShareService) ListInUserProfile(c *gin.Context, uid int) (*ListShar
|
|||
|
||||
ctx := context.WithValue(c, inventory.LoadShareUser{}, true)
|
||||
ctx = context.WithValue(ctx, inventory.LoadShareFile{}, true)
|
||||
ctx = context.WithValue(ctx, inventory.LoadFileMetadata{}, true)
|
||||
res, err := shareClient.List(ctx, args)
|
||||
if err != nil {
|
||||
return nil, serializer.NewError(serializer.CodeDBError, "Failed to list shares", err)
|
||||
|
|
Loading…
Reference in New Issue