@@ -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
212216func 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
432517func 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
0 commit comments