feat(explorer): manage created direct links / option to enable unique redirected direct links
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/cloudreve/Cloudreve/v4/ent"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/directlink"
|
||||
"github.com/cloudreve/Cloudreve/v4/ent/schema"
|
||||
"github.com/cloudreve/Cloudreve/v4/pkg/conf"
|
||||
"github.com/cloudreve/Cloudreve/v4/pkg/hashid"
|
||||
)
|
||||
@@ -16,6 +17,8 @@ type (
|
||||
GetByNameID(ctx context.Context, id int, name string) (*ent.DirectLink, error)
|
||||
// GetByID get direct link by id
|
||||
GetByID(ctx context.Context, id int) (*ent.DirectLink, error)
|
||||
// Delete delete direct link by id
|
||||
Delete(ctx context.Context, id int) error
|
||||
}
|
||||
LoadDirectLinkFile struct{}
|
||||
)
|
||||
@@ -60,6 +63,12 @@ func (d *directLinkClient) GetByNameID(ctx context.Context, id int, name string)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (d *directLinkClient) Delete(ctx context.Context, id int) error {
|
||||
ctx = schema.SkipSoftDelete(ctx)
|
||||
_, err := d.client.DirectLink.Delete().Where(directlink.ID(id)).Exec(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
func withDirectLinkEagerLoading(ctx context.Context, q *ent.DirectLinkQuery) *ent.DirectLinkQuery {
|
||||
if v, ok := ctx.Value(LoadDirectLinkFile{}).(bool); ok && v {
|
||||
q.WithFile(func(m *ent.FileQuery) {
|
||||
|
||||
@@ -192,7 +192,7 @@ type FileClient interface {
|
||||
// UnlinkEntity unlinks an entity from a file
|
||||
UnlinkEntity(ctx context.Context, entity *ent.Entity, file *ent.File, owner *ent.User) (StorageDiff, error)
|
||||
// CreateDirectLink creates a direct link for a file
|
||||
CreateDirectLink(ctx context.Context, fileID int, name string, speed int) (*ent.DirectLink, error)
|
||||
CreateDirectLink(ctx context.Context, fileID int, name string, speed int, reuse bool) (*ent.DirectLink, error)
|
||||
// CountByTimeRange counts files created in a given time range
|
||||
CountByTimeRange(ctx context.Context, start, end *time.Time) (int, error)
|
||||
// CountEntityByTimeRange counts entities created in a given time range
|
||||
@@ -322,13 +322,15 @@ func (f *fileClient) CountEntityByStoragePolicyID(ctx context.Context, storagePo
|
||||
return v[0].Count, v[0].Sum, nil
|
||||
}
|
||||
|
||||
func (f *fileClient) CreateDirectLink(ctx context.Context, file int, name string, speed int) (*ent.DirectLink, error) {
|
||||
// Find existed
|
||||
existed, err := f.client.DirectLink.
|
||||
Query().
|
||||
Where(directlink.FileID(file), directlink.Name(name), directlink.Speed(speed)).First(ctx)
|
||||
if err == nil {
|
||||
return existed, nil
|
||||
func (f *fileClient) CreateDirectLink(ctx context.Context, file int, name string, speed int, reuse bool) (*ent.DirectLink, error) {
|
||||
if reuse {
|
||||
// Find existed
|
||||
existed, err := f.client.DirectLink.
|
||||
Query().
|
||||
Where(directlink.FileID(file), directlink.Name(name), directlink.Speed(speed)).First(ctx)
|
||||
if err == nil {
|
||||
return existed, nil
|
||||
}
|
||||
}
|
||||
|
||||
return f.client.DirectLink.
|
||||
|
||||
@@ -206,6 +206,7 @@ const (
|
||||
GroupPermission_CommunityPlaceholder4
|
||||
GroupPermissionSetExplicitUser_placeholder
|
||||
GroupPermissionIgnoreFileOwnership // not used
|
||||
GroupPermissionUniqueRedirectDirectLink
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
Reference in New Issue
Block a user