mirror of https://github.com/cloudreve/Cloudreve
feat: fileshare custom password support (#2493)
* feat: fileshare custom password support
* fix: blank password check
* feat: backend share link password check
* Revert "feat: backend share link password check"
This reverts commit 22c7bb0b35
.
* feat: use go-playground/validator binding rule
pull/2498/head
parent
40644f5234
commit
9d28fde00c
|
@ -111,6 +111,7 @@ type (
|
||||||
CreateShareArgs struct {
|
CreateShareArgs struct {
|
||||||
ExistedShareID int
|
ExistedShareID int
|
||||||
IsPrivate bool
|
IsPrivate bool
|
||||||
|
Password string
|
||||||
RemainDownloads int
|
RemainDownloads int
|
||||||
Expire *time.Time
|
Expire *time.Time
|
||||||
ShareView bool
|
ShareView bool
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cloudreve/Cloudreve/v4/application/constants"
|
"github.com/cloudreve/Cloudreve/v4/application/constants"
|
||||||
|
@ -259,7 +260,10 @@ func (l *manager) CreateOrUpdateShare(ctx context.Context, path *fs.URI, args *C
|
||||||
|
|
||||||
password := ""
|
password := ""
|
||||||
if args.IsPrivate {
|
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{
|
props := &types.ShareProps{
|
||||||
|
|
|
@ -20,6 +20,7 @@ type (
|
||||||
ShareCreateService struct {
|
ShareCreateService struct {
|
||||||
Uri string `json:"uri" binding:"required"`
|
Uri string `json:"uri" binding:"required"`
|
||||||
IsPrivate bool `json:"is_private"`
|
IsPrivate bool `json:"is_private"`
|
||||||
|
Password string `json:"password" binding:"max=32,alphanum,omitempty"`
|
||||||
RemainDownloads int `json:"downloads"`
|
RemainDownloads int `json:"downloads"`
|
||||||
Expire int `json:"expire"`
|
Expire int `json:"expire"`
|
||||||
ShareView bool `json:"share_view"`
|
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{
|
share, err := m.CreateOrUpdateShare(c, uri, &manager.CreateShareArgs{
|
||||||
IsPrivate: service.IsPrivate,
|
IsPrivate: service.IsPrivate,
|
||||||
|
Password: service.Password,
|
||||||
RemainDownloads: service.RemainDownloads,
|
RemainDownloads: service.RemainDownloads,
|
||||||
Expire: expires,
|
Expire: expires,
|
||||||
ExistedShareID: existed,
|
ExistedShareID: existed,
|
||||||
|
|
Loading…
Reference in New Issue