Skip to content

Commit e4318c4

Browse files
committed
feat(fs): add visibility support for the make directory configuration.
1 parent 2819e02 commit e4318c4

File tree

13 files changed

+193
-55
lines changed

13 files changed

+193
-55
lines changed

drivers/189_share/driver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (d *Cloud189Share) Move(ctx context.Context, srcObj, dstDir model.Obj) erro
107107
}
108108

109109
func (d *Cloud189Share) Rename(ctx context.Context, srcObj model.Obj, newName string) error {
110-
return virtual_file.Rename(d.ID, srcObj.GetPath(), srcObj.GetID(), newName)
110+
return virtual_file.Rename(d.ID, srcObj, newName)
111111
}
112112

113113
func (d *Cloud189Share) Copy(ctx context.Context, srcObj, dstDir model.Obj) error {

drivers/aliyundrive/driver.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import (
77
"encoding/base64"
88
"encoding/hex"
99
"fmt"
10-
"github.com/OpenListTeam/OpenList/v4/drivers/aliyundrive_open"
11-
"github.com/OpenListTeam/OpenList/v4/drivers/virtual_file"
12-
"github.com/OpenListTeam/OpenList/v4/internal/op"
1310
"io"
1411
"math"
1512
"math/big"
@@ -18,6 +15,10 @@ import (
1815
"path/filepath"
1916
"time"
2017

18+
"github.com/OpenListTeam/OpenList/v4/drivers/aliyundrive_open"
19+
"github.com/OpenListTeam/OpenList/v4/drivers/virtual_file"
20+
"github.com/OpenListTeam/OpenList/v4/internal/op"
21+
2122
"github.com/OpenListTeam/OpenList/v4/drivers/base"
2223
"github.com/OpenListTeam/OpenList/v4/internal/conf"
2324
"github.com/OpenListTeam/OpenList/v4/internal/driver"
@@ -169,7 +170,7 @@ func (d *AliDrive) Move(ctx context.Context, srcObj, dstDir model.Obj) error {
169170

170171
func (d *AliDrive) Rename(ctx context.Context, srcObj model.Obj, newName string) error {
171172

172-
return virtual_file.Rename(d.ID, srcObj.GetPath(), srcObj.GetID(), newName)
173+
return virtual_file.Rename(d.ID, srcObj, newName)
173174

174175
}
175176

drivers/pikpak_share/driver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func (d *PikPakShare) Move(ctx context.Context, srcObj, dstDir model.Obj) error
178178
}
179179

180180
func (d *PikPakShare) Rename(ctx context.Context, srcObj model.Obj, newName string) error {
181-
return virtual_file.Rename(d.ID, srcObj.GetPath(), srcObj.GetID(), newName)
181+
return virtual_file.Rename(d.ID, srcObj, newName)
182182
}
183183

184184
func (d *PikPakShare) MkdirConfig() []driver.Item {

drivers/pornhub/driver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func (d *Pornhub) MkdirConfig() []driver.Item {
194194
{
195195
Name: "type",
196196
Type: conf.TypeSelect,
197-
Default: "",
197+
Default: "1",
198198
Options: "0,1,2",
199199
Help: "0:播放列表;1:演员;2:明星",
200200
Required: true,

drivers/quark_share/driver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (d *QuarkShare) Move(ctx context.Context, srcObj, dstDir model.Obj) error {
136136
}
137137

138138
func (d *QuarkShare) Rename(ctx context.Context, srcObj model.Obj, newName string) error {
139-
return virtual_file.Rename(d.ID, srcObj.GetPath(), srcObj.GetID(), newName)
139+
return virtual_file.Rename(d.ID, srcObj, newName)
140140
}
141141

142142
func (d *QuarkShare) Copy(ctx context.Context, srcObj, dstDir model.Obj) error {

drivers/virtual_file/util.go

Lines changed: 119 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,22 @@ func MakeDir(storageId uint, parentDir model.Obj, param string) error {
187187
req.DirType = model.VirtualDirection
188188
}
189189

190+
if req.Name == "" {
191+
return errors.New("empty dir name")
192+
}
193+
190194
if parentDir.GetName() == "root" {
191195
req.Parent = ""
192196
} else if virDir, ok := parentDir.(*model.ObjVirtualDir); ok && virDir.DirType == model.VirtualDirection {
193197
req.Parent = fmt.Sprintf("%d", virDir.ID)
194198
} else {
195-
return errors.New("不允许在此目录下新增文件夹")
199+
return errors.New("can't make the new dir under this dir")
196200
}
197201

198202
virtualFiles := db.QueryVirtualFiles(storageId, req.Parent)
199203
for _, file := range virtualFiles {
200204
if file.Name == req.Name {
201-
return errors.New("文件夹已存在")
205+
return errors.New("the file already exists")
202206
}
203207
}
204208

@@ -210,15 +214,19 @@ func MakeDir(storageId uint, parentDir model.Obj, param string) error {
210214
}
211215

212216
func GetMkdirConfig() []driver.Item {
217+
subscriptionCondition := driver.VisibilityCondition{
218+
Field: "dirType",
219+
Value: "0",
220+
}
221+
orderRenameCondition := driver.VisibilityCondition{
222+
Field: "type",
223+
Value: "0",
224+
}
225+
regexpRenameCondition := driver.VisibilityCondition{
226+
Field: "type",
227+
Value: "1",
228+
}
213229
return []driver.Item{
214-
{
215-
Name: "controlText",
216-
Type: conf.TypeText,
217-
Default: "",
218-
Options: "",
219-
Help: "控制文本,用于便捷的生成其他属性信息",
220-
Required: true,
221-
},
222230
{
223231
Name: "dirType",
224232
Type: conf.TypeSelect,
@@ -236,32 +244,98 @@ func GetMkdirConfig() []driver.Item {
236244
Required: true,
237245
},
238246
{
239-
Name: "shareId",
240-
Type: conf.TypeString,
241-
Default: "",
242-
Options: "",
243-
Help: "分享ID",
247+
Name: "shareId",
248+
Type: conf.TypeString,
249+
Default: "",
250+
Options: "",
251+
Help: "分享ID",
252+
VisibleOn: subscriptionCondition,
244253
},
245254
{
246-
Name: "parentDir",
247-
Type: conf.TypeString,
248-
Default: "0",
249-
Options: "",
250-
Help: "挂载的根文件夹ID",
255+
Name: "parentDir",
256+
Type: conf.TypeString,
257+
Default: "0",
258+
Options: "",
259+
Help: "挂载的根文件夹ID",
260+
VisibleOn: subscriptionCondition,
251261
},
252262
{
253-
Name: "sharePwd",
254-
Type: conf.TypeString,
255-
Default: "",
256-
Options: "",
257-
Help: "分享密码",
263+
Name: "sharePwd",
264+
Type: conf.TypeString,
265+
Default: "",
266+
Options: "",
267+
Help: "分享密码",
268+
VisibleOn: subscriptionCondition,
269+
},
270+
{
271+
Name: "minFileSize",
272+
Type: conf.TypeNumber,
273+
Default: "0",
274+
Options: "",
275+
Help: "最小文件大小,小于此大小的文件不会展示",
276+
VisibleOn: subscriptionCondition,
258277
},
259278
{
260-
Name: "minSize",
261-
Type: conf.TypeString,
262-
Default: "0",
279+
Name: "replace",
280+
Type: conf.TypeArray,
281+
Default: "",
263282
Options: "",
264-
Help: "最小文件大小",
283+
Help: "替换类型",
284+
Children: []driver.Item{
285+
{
286+
Name: "type",
287+
Type: conf.TypeSelect,
288+
Default: "1",
289+
Options: "0,1",
290+
Help: "0:顺序重命名;1:正则重命名",
291+
Required: true,
292+
},
293+
{
294+
Name: "oldNameRegexp",
295+
Type: conf.TypeString,
296+
Default: "",
297+
Options: "",
298+
Help: "原文件名匹配正则表达式",
299+
Required: false,
300+
VisibleOn: regexpRenameCondition,
301+
},
302+
{
303+
Name: "sourceName",
304+
Type: conf.TypeString,
305+
Default: "",
306+
Options: "",
307+
Help: "替换的正则表达式",
308+
Required: false,
309+
VisibleOn: regexpRenameCondition,
310+
},
311+
{
312+
Name: "startNum",
313+
Type: conf.TypeNumber,
314+
Default: "1",
315+
Options: "",
316+
Help: "开始编号",
317+
Required: false,
318+
VisibleOn: orderRenameCondition,
319+
},
320+
{
321+
Name: "start",
322+
Type: conf.TypeNumber,
323+
Default: "0",
324+
Options: "",
325+
Help: "替换的起始索引,小于此索引的数据不会被替换",
326+
Required: false,
327+
VisibleOn: orderRenameCondition,
328+
}, {
329+
Name: "end",
330+
Type: conf.TypeNumber,
331+
Default: "-1",
332+
Options: "",
333+
Help: "替换的终止索引,大于此索引的数据不会被替换。-1为替换至列表结束",
334+
Required: false,
335+
VisibleOn: orderRenameCondition,
336+
},
337+
},
338+
VisibleOn: subscriptionCondition,
265339
},
266340
}
267341
}
@@ -405,8 +479,19 @@ func Move(storageId uint, srcObj model.Obj, targetDir model.Obj) error {
405479

406480
}
407481

408-
func Rename(storageId uint, dir, oldName, newName string) error {
482+
func Rename(storageId uint, srcObj model.Obj, newName string) error {
409483

484+
if virDir, ok := srcObj.(*model.ObjVirtualDir); ok {
485+
var req model.VirtualFileInfo
486+
err := utils.Json.Unmarshal([]byte(newName), &req)
487+
if err != nil {
488+
return err
489+
}
490+
virDir.VirtualFileInfo = req
491+
return db.UpdateVirtualFile(virDir.VirtualFile)
492+
}
493+
494+
dir, oldName := srcObj.GetPath(), srcObj.GetID()
410495
_, err := strconv.Atoi(oldName)
411496
if err == nil {
412497
virtualFiles, err1 := db.QueryVirtualFilesById(storageId, []string{oldName})
@@ -431,12 +516,12 @@ func Rename(storageId uint, dir, oldName, newName string) error {
431516

432517
func tryReplace(replaceItem *model.ReplaceItem, index int, oldName string, nameSetter model.SetName) bool {
433518

434-
if replaceItem.SourceName == "" {
435-
return false
436-
}
437-
438519
if replaceItem.Type == 0 {
439520

521+
if replaceItem.SourceName == "" {
522+
return false
523+
}
524+
440525
// 不在给定的重命名规则中
441526
if index < replaceItem.Start || (replaceItem.End != -1 && index > replaceItem.End) {
442527
return false

internal/conf/const.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const (
66
TypeBool = "bool"
77
TypeText = "text"
88
TypeNumber = "number"
9+
TypeGroup = "group"
10+
TypeArray = "array"
911
)
1012

1113
const (

internal/db/virtual_file.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ func QueryVirtualFilesById(storageId uint, ids []string) ([]model.VirtualFile, e
3131
func QueryVirtualFilm(storageId uint, name string) model.VirtualFile {
3232

3333
file := model.VirtualFile{
34-
StorageId: storageId,
35-
Name: name,
34+
VirtualFileInfo: model.VirtualFileInfo{
35+
StorageId: storageId,
36+
Name: name,
37+
},
3638
}
3739

3840
db.Where(file).Take(&file)

internal/driver/item.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@ type Additional interface{}
55
type Select string
66

77
type Item struct {
8-
Name string `json:"name"`
9-
Type string `json:"type"`
10-
Default string `json:"default"`
11-
Options string `json:"options"`
12-
Required bool `json:"required"`
13-
Help string `json:"help"`
8+
Name string `json:"name"`
9+
Type string `json:"type"`
10+
Default string `json:"default"`
11+
Options string `json:"options"`
12+
Required bool `json:"required"`
13+
Help string `json:"help"`
14+
Children []Item `json:"children"`
15+
VisibleOn VisibilityCondition `json:"visibleOn"`
16+
}
17+
18+
type VisibilityCondition struct {
19+
Field string `json:"field"`
20+
OP string `json:"op"`
21+
Value any `json:"value"`
1422
}
1523

1624
type Info struct {

internal/model/film.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import (
44
"database/sql/driver"
55
"encoding/json"
66
"errors"
7-
"gorm.io/gorm"
87
"time"
8+
9+
"gorm.io/gorm"
910
)
1011

1112
type Film struct {
@@ -53,8 +54,7 @@ const (
5354
VirtualDirection
5455
)
5556

56-
type VirtualFile struct {
57-
ID uint `gorm:"primarykey"`
57+
type VirtualFileInfo struct {
5858
DirType uint `json:"dirType"`
5959
Parent string `json:"parent"`
6060
StorageId uint `json:"storage_id"`
@@ -70,6 +70,15 @@ type VirtualFile struct {
7070
Replace []ReplaceItem `json:"replace" gorm:"type:json;serializer:json"`
7171
}
7272

73+
type VirtualFile struct {
74+
ID uint `gorm:"primarykey"`
75+
VirtualFileInfo
76+
}
77+
78+
func (d *VirtualFile) GetInfo() VirtualFileInfo {
79+
return d.VirtualFileInfo
80+
}
81+
7382
type ReplaceItem struct {
7483
// 替换类型: 0:顺序重命名;1:正则重命名;
7584
Type int `json:"type"`

0 commit comments

Comments
 (0)