github.com/qjfoidnh/BaiduPCS-Go@v0.0.0-20231011165705-caa18a3765f3/internal/pcscommand/recycle.go (about)

     1  package pcscommand
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/qjfoidnh/BaiduPCS-Go/baidupcs"
     6  	"github.com/qjfoidnh/BaiduPCS-Go/pcstable"
     7  	"github.com/qjfoidnh/BaiduPCS-Go/pcsutil/converter"
     8  	"github.com/qjfoidnh/BaiduPCS-Go/pcsutil/pcstime"
     9  	"github.com/olekukonko/tablewriter"
    10  	"os"
    11  	"strconv"
    12  )
    13  
    14  // RunRecycleList 执行列出回收站文件列表
    15  func RunRecycleList(page int) {
    16  	if page < 1 {
    17  		page = 1
    18  	}
    19  
    20  	pcs := GetBaiduPCS()
    21  	fdl, err := pcs.RecycleList(page)
    22  	if err != nil {
    23  		fmt.Println(err)
    24  		return
    25  	}
    26  
    27  	tb := pcstable.NewTable(os.Stdout)
    28  	tb.SetHeader([]string{"#", "fs_id", "文件大小", "创建日期", "修改日期", "md5(截图请打码)", "剩余时间", "路径"})
    29  	tb.SetColumnAlignment([]int{tablewriter.ALIGN_DEFAULT, tablewriter.ALIGN_RIGHT, tablewriter.ALIGN_RIGHT, tablewriter.ALIGN_LEFT, tablewriter.ALIGN_LEFT, tablewriter.ALIGN_LEFT, tablewriter.ALIGN_DEFAULT, tablewriter.ALIGN_LEFT})
    30  	for k, file := range fdl {
    31  		if file.Isdir == 1 {
    32  			tb.Append([]string{strconv.Itoa(k), strconv.FormatInt(file.FsID, 10), "-", pcstime.FormatTime(file.Ctime), pcstime.FormatTime(file.Mtime), file.MD5, strconv.Itoa(file.LeftTime), file.Path + baidupcs.PathSeparator})
    33  			continue
    34  		}
    35  		tb.Append([]string{strconv.Itoa(k), strconv.FormatInt(file.FsID, 10), converter.ConvertFileSize(file.Size, 2), pcstime.FormatTime(file.Ctime), pcstime.FormatTime(file.Mtime), file.MD5, strconv.Itoa(file.LeftTime), file.Path})
    36  	}
    37  
    38  	tb.Render()
    39  }
    40  
    41  // RunRecycleRestore 执行还原回收站文件或目录
    42  func RunRecycleRestore(fidStrList ...string) {
    43  	var (
    44  		fidList = converter.SliceStringToInt64(fidStrList)
    45  		pcs     = GetBaiduPCS()
    46  		ex, err = pcs.RecycleRestore(fidList...)
    47  	)
    48  	if err != nil {
    49  		fmt.Println(err)
    50  		if len(ex) > 0 {
    51  			fmt.Printf("\n以下的 fs_id 还原成功, 数量: %d\n", len(ex))
    52  			for k := range ex {
    53  				fmt.Println(ex[k].FsID)
    54  			}
    55  		}
    56  		return
    57  	}
    58  
    59  	fmt.Printf("还原成功, 数量: %d\n", len(ex))
    60  }
    61  
    62  // RunRecycleDelete 执行删除回收站文件或目录
    63  func RunRecycleDelete(fidStrList ...string) {
    64  	var (
    65  		fidList = converter.SliceStringToInt64(fidStrList)
    66  		pcs     = GetBaiduPCS()
    67  		err     = pcs.RecycleDelete(fidList...)
    68  	)
    69  	if err != nil {
    70  		fmt.Println(err)
    71  		return
    72  	}
    73  
    74  	fmt.Printf("删除成功\n")
    75  }
    76  
    77  // RunRecycleClear 清空回收站
    78  func RunRecycleClear() {
    79  	pcs := GetBaiduPCS()
    80  	sussNum, err := pcs.RecycleClear()
    81  	if err != nil {
    82  		fmt.Println(err)
    83  		return
    84  	}
    85  	fmt.Printf("清空回收站成功, 数量: %d\n", sussNum)
    86  }