github.com/fzfile/BaiduPCS-Go@v0.0.0-20200606205115-4408961cf336/baidupcs/recycle.go (about)

     1  package baidupcs
     2  
     3  import (
     4  	"github.com/fzfile/BaiduPCS-Go/baidupcs/pcserror"
     5  )
     6  
     7  type (
     8  	// RecycleFDInfo 回收站中文件/目录信息
     9  	RecycleFDInfo struct {
    10  		FsID     int64  `json:"fs_id"` // fs_id
    11  		Isdir    int    `json:"isdir"`
    12  		LeftTime int    `json:"leftTime"`        // 剩余时间
    13  		Path     string `json:"path"`            // 路径
    14  		Filename string `json:"server_filename"` // 文件名 或 目录名
    15  		Ctime    int64  `json:"server_ctime"`    // 创建日期
    16  		Mtime    int64  `json:"server_mtime"`    // 修改日期
    17  		MD5      string `json:"md5"`             // md5 值
    18  		Size     int64  `json:"size"`            // 文件大小 (目录为0)
    19  	}
    20  
    21  	// RecycleFDInfoList 回收站中文件/目录列表
    22  	RecycleFDInfoList []*RecycleFDInfo
    23  
    24  	recycleListJSON struct {
    25  		*pcserror.PanErrorInfo
    26  		List RecycleFDInfoList `json:"list"`
    27  	}
    28  
    29  	recycleRestoreJSON struct {
    30  		*pcserror.PCSErrInfo
    31  		Extra FsIDListJSON `json:"extra"`
    32  	}
    33  
    34  	// RecycleClearInfo 清空回收站的信息
    35  	RecycleClearInfo struct {
    36  		List    RecycleFDInfoList `json:"list"`
    37  		SussNum int               `json:"succNum"`
    38  	}
    39  
    40  	recycleClearJSON struct {
    41  		*pcserror.PCSErrInfo
    42  		Extra RecycleClearInfo `json:"extra"`
    43  	}
    44  )
    45  
    46  // RecycleList 列出回收站文件列表
    47  func (pcs *BaiduPCS) RecycleList(page int) (fdl RecycleFDInfoList, panError pcserror.Error) {
    48  	dataReadCloser, panError := pcs.PrepareRecycleList(page)
    49  	if panError != nil {
    50  		return
    51  	}
    52  
    53  	defer dataReadCloser.Close()
    54  
    55  	errInfo := pcserror.NewPanErrorInfo(OperationRecycleList)
    56  	jsonData := recycleListJSON{
    57  		PanErrorInfo: errInfo,
    58  	}
    59  
    60  	panError = pcserror.HandleJSONParse(OperationRecycleList, dataReadCloser, &jsonData)
    61  	if panError != nil {
    62  		return
    63  	}
    64  
    65  	return jsonData.List, nil
    66  }
    67  
    68  // RecycleRestore 还原回收站文件或目录
    69  func (pcs *BaiduPCS) RecycleRestore(fidList ...int64) (sussFsIDList []*FsIDJSON, pcsError pcserror.Error) {
    70  	dataReadCloser, pcsError := pcs.PrepareRecycleRestore(fidList...)
    71  	if pcsError != nil {
    72  		return
    73  	}
    74  
    75  	defer dataReadCloser.Close()
    76  
    77  	errInfo := pcserror.NewPCSErrorInfo(OperationRecycleRestore)
    78  	jsonData := recycleRestoreJSON{
    79  		PCSErrInfo: errInfo,
    80  	}
    81  
    82  	pcsError = pcserror.HandleJSONParse(OperationRecycleRestore, dataReadCloser, &jsonData)
    83  	return jsonData.Extra.List, pcsError
    84  }
    85  
    86  // RecycleDelete 删除回收站文件或目录
    87  func (pcs *BaiduPCS) RecycleDelete(fidList ...int64) (panError pcserror.Error) {
    88  	dataReadCloser, panError := pcs.PrepareRecycleDelete(fidList...)
    89  	if panError != nil {
    90  		return
    91  	}
    92  
    93  	defer dataReadCloser.Close()
    94  
    95  	panError = pcserror.DecodePanJSONError(OperationRecycleDelete, dataReadCloser)
    96  	return
    97  }
    98  
    99  // RecycleClear 清空回收站
   100  func (pcs *BaiduPCS) RecycleClear() (sussNum int, pcsError pcserror.Error) {
   101  	dataReadCloser, pcsError := pcs.PrepareRecycleClear()
   102  	if pcsError != nil {
   103  		return
   104  	}
   105  
   106  	defer dataReadCloser.Close()
   107  
   108  	errInfo := pcserror.NewPCSErrorInfo(OperationRecycleClear)
   109  	jsonData := recycleClearJSON{
   110  		PCSErrInfo: errInfo,
   111  	}
   112  
   113  	pcsError = pcserror.HandleJSONParse(OperationRecycleClear, dataReadCloser, &jsonData)
   114  	return jsonData.Extra.SussNum, pcsError
   115  }