mirror of https://github.com/cloudreve/Cloudreve
feat(profile): options to select why kind of share links to show in user's profile (#2453)
parent
bb3db2e326
commit
b0057fe92f
2
assets
2
assets
|
@ -1 +1 @@
|
|||
Subproject commit 8b2c8a7bdbde43a1f95ddaa4555e4304215c1e7c
|
||||
Subproject commit eb2cfac37d73e5bd3000eb66a3a0062509efe122
|
|
@ -16,8 +16,11 @@ type (
|
|||
Language string `json:"email_language,omitempty"`
|
||||
DisableViewSync bool `json:"disable_view_sync,omitempty"`
|
||||
FsViewMap map[string]ExplorerView `json:"fs_view_map,omitempty"`
|
||||
ShareLinksInProfile ShareLinksInProfileLevel `json:"share_links_in_profile,omitempty"`
|
||||
}
|
||||
|
||||
ShareLinksInProfileLevel string
|
||||
|
||||
PinedFile struct {
|
||||
Uri string `json:"uri"`
|
||||
Name string `json:"name,omitempty"`
|
||||
|
@ -334,3 +337,9 @@ const (
|
|||
CustomPropsTypeLink = "link"
|
||||
CustomPropsTypeRating = "rating"
|
||||
)
|
||||
|
||||
const (
|
||||
ProfilePublicShareOnly = ShareLinksInProfileLevel("")
|
||||
ProfileAllShare = ShareLinksInProfileLevel("all_share")
|
||||
ProfileHideShare = ShareLinksInProfileLevel("hide_share")
|
||||
)
|
||||
|
|
|
@ -278,6 +278,7 @@ type Share struct {
|
|||
Downloaded int `json:"downloaded,omitempty"`
|
||||
Expires *time.Time `json:"expires,omitempty"`
|
||||
Unlocked bool `json:"unlocked"`
|
||||
PasswordProtected bool `json:"password_protected,omitempty"`
|
||||
SourceType *types.FileType `json:"source_type,omitempty"`
|
||||
Owner user.User `json:"owner"`
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
|
@ -306,10 +307,11 @@ func BuildShare(s *ent.Share, base *url.URL, hasher hashid.Encoder, requester *e
|
|||
Unlocked: unlocked,
|
||||
Owner: user.BuildUserRedacted(owner, redactLevel, hasher),
|
||||
Expired: inventory.IsShareExpired(s) != nil || expired,
|
||||
Url: BuildShareLink(s, hasher, base),
|
||||
Url: BuildShareLink(s, hasher, base, unlocked),
|
||||
CreatedAt: s.CreatedAt,
|
||||
Visited: s.Views,
|
||||
SourceType: util.ToPtr(t),
|
||||
PasswordProtected: s.Password != "",
|
||||
}
|
||||
|
||||
if unlocked {
|
||||
|
@ -436,10 +438,13 @@ func BuildEntity(extendedInfo *fs.FileExtendedInfo, e fs.Entity, hasher hashid.E
|
|||
}
|
||||
}
|
||||
|
||||
func BuildShareLink(s *ent.Share, hasher hashid.Encoder, base *url.URL) string {
|
||||
func BuildShareLink(s *ent.Share, hasher hashid.Encoder, base *url.URL, unlocked bool) string {
|
||||
shareId := hashid.EncodeShareID(hasher, s.ID)
|
||||
if unlocked {
|
||||
return routes.MasterShareUrl(base, shareId, s.Password).String()
|
||||
}
|
||||
return routes.MasterShareUrl(base, shareId, "").String()
|
||||
}
|
||||
|
||||
func BuildStoragePolicy(sp *ent.StoragePolicy, hasher hashid.Encoder) *StoragePolicy {
|
||||
if sp == nil {
|
||||
|
|
|
@ -66,7 +66,7 @@ func (service *ShareCreateService) Upsert(c *gin.Context, existed int) (string,
|
|||
}
|
||||
|
||||
base := dep.SettingProvider().SiteURL(c)
|
||||
return explorer.BuildShareLink(share, dep.HashIDEncoder(), base), nil
|
||||
return explorer.BuildShareLink(share, dep.HashIDEncoder(), base, true), nil
|
||||
}
|
||||
|
||||
func DeleteShare(c *gin.Context, shareId int) error {
|
||||
|
|
|
@ -137,6 +137,16 @@ func (s *ListShareService) ListInUserProfile(c *gin.Context, uid int) (*ListShar
|
|||
hasher := dep.HashIDEncoder()
|
||||
shareClient := dep.ShareClient()
|
||||
|
||||
targetUser, err := dep.UserClient().GetActiveByID(c, uid)
|
||||
if err != nil {
|
||||
return nil, serializer.NewError(serializer.CodeDBError, "Failed to get user", err)
|
||||
}
|
||||
|
||||
if targetUser.Settings != nil && targetUser.Settings.ShareLinksInProfile == types.ProfileHideShare {
|
||||
return nil, serializer.NewError(serializer.CodeParamErr, "User has disabled share links in profile", nil)
|
||||
}
|
||||
|
||||
publicOnly := targetUser.Settings == nil || targetUser.Settings.ShareLinksInProfile == types.ProfilePublicShareOnly
|
||||
args := &inventory.ListShareArgs{
|
||||
PaginationArgs: &inventory.PaginationArgs{
|
||||
UseCursorPagination: true,
|
||||
|
@ -146,7 +156,7 @@ func (s *ListShareService) ListInUserProfile(c *gin.Context, uid int) (*ListShar
|
|||
OrderBy: s.OrderBy,
|
||||
},
|
||||
UserID: uid,
|
||||
PublicOnly: true,
|
||||
PublicOnly: publicOnly,
|
||||
}
|
||||
|
||||
ctx := context.WithValue(c, inventory.LoadShareUser{}, true)
|
||||
|
|
|
@ -29,6 +29,7 @@ type UserSettings struct {
|
|||
TwoFAEnabled bool `json:"two_fa_enabled"`
|
||||
Passkeys []Passkey `json:"passkeys,omitempty"`
|
||||
DisableViewSync bool `json:"disable_view_sync"`
|
||||
ShareLinksInProfile string `json:"share_links_in_profile"`
|
||||
}
|
||||
|
||||
func BuildUserSettings(u *ent.User, passkeys []*ent.Passkey, parser *uaparser.Parser) *UserSettings {
|
||||
|
@ -42,6 +43,7 @@ func BuildUserSettings(u *ent.User, passkeys []*ent.Passkey, parser *uaparser.Pa
|
|||
return BuildPasskey(item)
|
||||
}),
|
||||
DisableViewSync: u.Settings.DisableViewSync,
|
||||
ShareLinksInProfile: string(u.Settings.ShareLinksInProfile),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,6 +111,7 @@ type User struct {
|
|||
Pined []types.PinedFile `json:"pined,omitempty"`
|
||||
Language string `json:"language,omitempty"`
|
||||
DisableViewSync bool `json:"disable_view_sync,omitempty"`
|
||||
ShareLinksInProfile types.ShareLinksInProfileLevel `json:"share_links_in_profile,omitempty"`
|
||||
}
|
||||
|
||||
type Group struct {
|
||||
|
@ -165,6 +168,7 @@ func BuildUser(user *ent.User, idEncoder hashid.Encoder) User {
|
|||
Pined: user.Settings.Pined,
|
||||
Language: user.Settings.Language,
|
||||
DisableViewSync: user.Settings.DisableViewSync,
|
||||
ShareLinksInProfile: user.Settings.ShareLinksInProfile,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -197,6 +201,7 @@ func BuildUserRedacted(u *ent.User, level int, idEncoder hashid.Encoder) User {
|
|||
Nickname: userRaw.Nickname,
|
||||
Avatar: userRaw.Avatar,
|
||||
CreatedAt: userRaw.CreatedAt,
|
||||
ShareLinksInProfile: userRaw.ShareLinksInProfile,
|
||||
}
|
||||
|
||||
if userRaw.Group != nil {
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/cloudreve/Cloudreve/v4/application/dependency"
|
||||
"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/hashid"
|
||||
"github.com/cloudreve/Cloudreve/v4/pkg/request"
|
||||
"github.com/cloudreve/Cloudreve/v4/pkg/serializer"
|
||||
|
@ -221,6 +222,7 @@ type (
|
|||
TwoFAEnabled *bool `json:"two_fa_enabled" binding:"omitempty"`
|
||||
TwoFACode *string `json:"two_fa_code" binding:"omitempty"`
|
||||
DisableViewSync *bool `json:"disable_view_sync" binding:"omitempty"`
|
||||
ShareLinksInProfile *string `json:"share_links_in_profile" binding:"omitempty"`
|
||||
}
|
||||
PatchUserSettingParamsCtx struct{}
|
||||
)
|
||||
|
@ -267,6 +269,11 @@ func (s *PatchUserSetting) Patch(c *gin.Context) error {
|
|||
saveSetting = true
|
||||
}
|
||||
|
||||
if s.ShareLinksInProfile != nil {
|
||||
u.Settings.ShareLinksInProfile = types.ShareLinksInProfileLevel(*s.ShareLinksInProfile)
|
||||
saveSetting = true
|
||||
}
|
||||
|
||||
if s.CurrentPassword != nil && s.NewPassword != nil {
|
||||
if err := inventory.CheckPassword(u, *s.CurrentPassword); err != nil {
|
||||
return serializer.NewError(serializer.CodeIncorrectPassword, "Incorrect password", err)
|
||||
|
|
Loading…
Reference in New Issue