diff --git a/pkg/filemanager/manager/manager.go b/pkg/filemanager/manager/manager.go index b53f78e..5dcda16 100644 --- a/pkg/filemanager/manager/manager.go +++ b/pkg/filemanager/manager/manager.go @@ -111,6 +111,7 @@ type ( CreateShareArgs struct { ExistedShareID int IsPrivate bool + Password string RemainDownloads int Expire *time.Time ShareView bool diff --git a/pkg/filemanager/manager/operation.go b/pkg/filemanager/manager/operation.go index 1b44b62..fe97b4c 100644 --- a/pkg/filemanager/manager/operation.go +++ b/pkg/filemanager/manager/operation.go @@ -4,6 +4,7 @@ import ( "context" "encoding/gob" "fmt" + "strings" "time" "github.com/cloudreve/Cloudreve/v4/application/constants" @@ -259,7 +260,10 @@ func (l *manager) CreateOrUpdateShare(ctx context.Context, path *fs.URI, args *C password := "" if args.IsPrivate { - password = util.RandString(8, util.RandomLowerCases) + password = args.Password + if strings.TrimSpace(password) == "" { + password = util.RandString(8, util.RandomLowerCases) + } } props := &types.ShareProps{ diff --git a/service/share/manage.go b/service/share/manage.go index 715fc00..f3c3fdf 100644 --- a/service/share/manage.go +++ b/service/share/manage.go @@ -20,6 +20,7 @@ type ( ShareCreateService struct { Uri string `json:"uri" binding:"required"` IsPrivate bool `json:"is_private"` + Password string `json:"password" binding:"max=32,alphanum,omitempty"` RemainDownloads int `json:"downloads"` Expire int `json:"expire"` ShareView bool `json:"share_view"` @@ -52,6 +53,7 @@ func (service *ShareCreateService) Upsert(c *gin.Context, existed int) (string, share, err := m.CreateOrUpdateShare(c, uri, &manager.CreateShareArgs{ IsPrivate: service.IsPrivate, + Password: service.Password, RemainDownloads: service.RemainDownloads, Expire: expires, ExistedShareID: existed,