bdpan

package module
v0.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2023 License: MIT Imports: 29 Imported by: 3

README

bdpan

TODO

  • [ ] 删除可使用 fsid
  • [ x ] 下载目录支持异步
  • [ ] bdpan 支持重命名
  • [ ] bdpan 缓存
  • [ ] 分析大小
  • [ ] 优化 backup 的速度
  • [ x ] 优化下载速度
  • 使用新的交互界面

Documentation

Index

Constants

View Source
const (
	DefaultUploadDir = "/apps/bdpan/"
	EnvDownloadDir   = "BDPAN_DOWNLOAD_DIR"
)
View Source
const (
	OndupFail      string = "fail"
	OndupNewCopy          = "newcopy"
	OndupOverwrite        = "overwrite"
	OndupSkip             = "skip"

	AsyncSync int32 = iota
	AsyncSelfAdaptation
	AsyncAsync

	OperaMove FileManageOpera = iota
	OperaCopy
	OperaDelete
)
View Source
const (
	// FRAGMENT_MAX_SIZE int64 = 4 * 1024 * 1024
	FRAGMENT_MAX_SIZE int64 = 4 * (1 << 20) // 4 M
)

Variables

View Source
var (
	// 当前目录
	PwdDir, _ = os.Getwd()
	// 默认下载目录
	DefaultDownloadDir, _ = homedir.Expand("~/Downloads")
)
View Source
var ErrAccessFail error = errors.New("身份验证失败")
View Source
var ErrAccessTokenFail error = errors.New("access token 失效")
View Source
var ErrApiFrequent error = errors.New("接口请求过于频繁,注意控制")
View Source
var ErrParamError error = errors.New("参数错误")
View Source
var ErrPathExists error = errors.New("文件已存在")
View Source
var ErrPathNotFound error = errors.New("文件或目录不存在")
View Source
var ErrUserNoUse error = errors.New("不允许接入用户数据")
View Source
var (
	Log *logrus.Logger
)

Functions

func AddCredentail

func AddCredentail(c Credential) error

func CleanCache

func CleanCache() error

func CopyFile

func CopyFile(path, toPath string) error

func CreateAccessTokenByDeviceCode

func CreateAccessTokenByDeviceCode() error

func DeleteFile

func DeleteFile(path string) error

func DeleteSyncModel

func DeleteSyncModel(id string) error

func Do2HTTPRequest

func Do2HTTPRequest(url string, body io.Reader, headers map[string]string) (string, int, error)

func Do2HTTPRequestToBytes

func Do2HTTPRequestToBytes(url string, body io.Reader, headers map[string]string) ([]byte, int, error)

func GetClient

func GetClient() *sdk.APIClient

func GetDefaultDownloadDir

func GetDefaultDownloadDir() string

func GetFileBytes added in v0.3.2

func GetFileBytes(fsid uint64) ([]byte, error)
func GetFileDLink(fsid uint64) (string, error)

func GetKey

func GetKey() ([]byte, error)

func GetLogger

func GetLogger() *logrus.Logger

func GetModels

func GetModels() (m map[string]*SyncModel)

func GetUriBytes

func GetUriBytes(uri string, rangeStart, rangeEnd int) ([]byte, error)

func IsLoggerDebug

func IsLoggerDebug() bool

func JoinCache

func JoinCache(elem ...string) string

func JoinDownload

func JoinDownload(elem ...string) string

func JoinStoage

func JoinStoage(elem ...string) string

func LogInfoString

func LogInfoString(w io.Writer, s string)

func MoveFile

func MoveFile(path, toPath string) error

func NewRespError

func NewRespError(r *http.Response) error

func PanInfo

func PanInfo() (*openapi.Quotaresponse, error)

func PrintFileInfoList

func PrintFileInfoList(files []*FileInfoDto)

func PrintSyncModelList

func PrintSyncModelList()

func PromptConfirm

func PromptConfirm(confirm string) bool

func PromptSelect

func PromptSelect(
	label string, actions []*SelectItem, hasSearch bool, limit int,
	selectFunc SelectFunc,
) (err error)

func RefreshAccessToken

func RefreshAccessToken() error

func SaveModels

func SaveModels(m map[string]*SyncModel) error

func ScheRefreshAccessToken

func ScheRefreshAccessToken() error

func SetLogLevel

func SetLogLevel(level logrus.Level)

func SetOutputFile

func SetOutputFile()

设置日志输出文件

func SplitFile

func SplitFile(path, tmpdir string, fragmentSize int64) ([]string, error)

func TaskUploadDir

func TaskUploadDir(from, to string, isSync bool, isRecursion bool, isIncludeHide bool) error

func WalkDir

func WalkDir(dir string, isRecursion bool, fn func(file *FileInfoDto) error) error

Types

type AccessToken

type AccessToken struct {
	ExpiresIn        int32  `json:"expires_in,omitempty"`
	AccessToken      string `json:"access_token,omitempty"`
	RefreshToken     string `json:"refresh_token,omitempty"`
	RefreshTimestamp int64  `json:"refresh_timestamp,omitempty"`
}

func GetConfigAccessToken

func GetConfigAccessToken() (*AccessToken, error)

func (AccessToken) Print

func (t AccessToken) Print()

type Config

type Config struct {
	LoginAppId string `json:"login_app_id,omitempty"`
}

func GetConfig

func GetConfig() (*Config, error)

func NewConfig

func NewConfig(loginAppId string) *Config

type Credential

type Credential struct {
	AppId     string `json:"app_id,omitempty"`
	AppKey    string `json:"app_key,omitempty"`
	SecretKey string `json:"secret_key,omitempty"`
	SignKey   string `json:"sign_key,omitempty"`
	// contains filtered or unexported fields
}

func GetConfigCredentail

func GetConfigCredentail() (*Credential, error)

func GetCredentail

func GetCredentail(appId string) (*Credential, error)

func GetCredentails

func GetCredentails() ([]*Credential, error)

func (*Credential) GetAccessToken

func (c *Credential) GetAccessToken() (*AccessToken, error)

type DownloadTaskInfo

type DownloadTaskInfo struct {
	From     string
	FromFile *FileInfoDto
	To       string
}

type DownloadTasker

type DownloadTasker struct {
	*tasker.Tasker
	// 迁移的地址
	From     string
	FromFile *FileInfoDto
	Froms    []string
	// To       string
	Path        string
	Dir         string
	IsSync      bool // 是否同步执行
	IsRecursion bool
	// contains filtered or unexported fields
}

func NewDownloadTasker

func NewDownloadTasker(file *FileInfoDto) *DownloadTasker

func (*DownloadTasker) AfterRun

func (m *DownloadTasker) AfterRun() error

func (*DownloadTasker) BeforeRun

func (m *DownloadTasker) BeforeRun() error

func (*DownloadTasker) Build

func (m *DownloadTasker) Build() error

func (*DownloadTasker) BuildTasks

func (d *DownloadTasker) BuildTasks() error

func (*DownloadTasker) Exec

func (m *DownloadTasker) Exec() error

func (DownloadTasker) RunTask

func (d DownloadTasker) RunTask(task *tasker.Task) error

type Downloader

type Downloader struct {
	Path           string
	Dir            string
	Out            io.Writer
	IsNotCover     bool
	DisableLog     bool
	UseProgressBar bool
	// contains filtered or unexported fields
}

func NewDownloader

func NewDownloader() *Downloader

func (*Downloader) DownloadFile

func (d *Downloader) DownloadFile(file *FileInfoDto) error

func (*Downloader) DownloadFileWithPath

func (d *Downloader) DownloadFileWithPath(file *FileInfoDto, path string) error

func (*Downloader) EnableVerbose

func (d *Downloader) EnableVerbose() *Downloader

func (*Downloader) Exec

func (d *Downloader) Exec() error

func (*Downloader) SetPath

func (d *Downloader) SetPath(path string) *Downloader

type ErrorResponse

type ErrorResponse struct {
	Errno            int32  `json:"errno,omitempty"`
	Erro             string `json:"error"`
	ErrorDescription string `json:"error_description"`
	ErrorCode        int    `json:"error_code"`
	ErrorMsg         string `json:"error_msg"`
	// contains filtered or unexported fields
}

func NewErrorResponse

func NewErrorResponse(r *http.Response) *ErrorResponse

func (ErrorResponse) Err

func (e ErrorResponse) Err() error

func (ErrorResponse) Error

func (e ErrorResponse) Error() string

func (ErrorResponse) IsError

func (e ErrorResponse) IsError() bool

func (ErrorResponse) Print

func (e ErrorResponse) Print()

type FileInfoDto

type FileInfoDto struct {
	FSID           uint64            `json:"fs_id"`
	Path           string            `json:"path"`
	Size           int               `json:"size"`
	FileType       int               `json:"isdir"`
	Filename       string            `json:"filename"`
	ServerFilename string            `json:"server_filename"`
	Category       int               `json:"category"`
	Dlink          string            `json:"dlink"`
	MD5            string            `json:"md5"`
	Thumbs         map[string]string `json:"thumbs"`
	ServerCTime    int64             `json:"server_ctime"`
	ServerMTime    int64             `json:"server_mtime"`
	LocalCTime     int64             `json:"local_ctime"`
	LocalMTime     int64             `json:"local_mtime"`
}

func GetDirAllFiles

func GetDirAllFiles(dir string) ([]*FileInfoDto, error)

func GetFileByFSID

func GetFileByFSID(fsid uint64) (*FileInfoDto, error)

func GetFileByPath

func GetFileByPath(path string) (*FileInfoDto, error)

func GetFilesByFSIDS

func GetFilesByFSIDS(fsids []uint64) ([]*FileInfoDto, error)

func SearchFiles

func SearchFiles(dir, key string) ([]*FileInfoDto, error)

TODO: 暂时用遍历的方式查找文件,后期需要改为搜索

func UploadFile

func UploadFile(fromPath, toPath string) (*FileInfoDto, error)

func (FileInfoDto) BuildPretty

func (f FileInfoDto) BuildPretty() []pretty.Field

func (FileInfoDto) GetCategory

func (f FileInfoDto) GetCategory() string

func (FileInfoDto) GetFileType

func (f FileInfoDto) GetFileType() string

func (FileInfoDto) GetFileTypeEmoji

func (f FileInfoDto) GetFileTypeEmoji() string

func (FileInfoDto) GetFileTypeIcon

func (f FileInfoDto) GetFileTypeIcon() string

func (FileInfoDto) GetFilename

func (f FileInfoDto) GetFilename() string

func (FileInfoDto) GetLocalCTime

func (f FileInfoDto) GetLocalCTime() string

func (FileInfoDto) GetLocalMTime

func (f FileInfoDto) GetLocalMTime() string

func (FileInfoDto) GetPretty

func (f FileInfoDto) GetPretty() string

func (FileInfoDto) GetServerCTime

func (f FileInfoDto) GetServerCTime() string

func (FileInfoDto) GetServerMTime

func (f FileInfoDto) GetServerMTime() string

func (FileInfoDto) GetSize

func (f FileInfoDto) GetSize() string

func (FileInfoDto) IsDir

func (f FileInfoDto) IsDir() bool

func (FileInfoDto) PrettyPrint

func (f FileInfoDto) PrettyPrint()

type FileInfoRequest

type FileInfoRequest struct {
	// contains filtered or unexported fields
}

func NewFileInfoRequest

func NewFileInfoRequest(fsids []uint64) FileInfoRequest

func (FileInfoRequest) Execute

func (r FileInfoRequest) Execute() (*FileListResponse, error)

func (FileInfoRequest) FSID

func (r FileInfoRequest) FSID(fsid uint64) FileInfoRequest

func (FileInfoRequest) FSIDs

func (r FileInfoRequest) FSIDs(fsids []uint64) FileInfoRequest
func (r FileInfoRequest) GetDlink() string

func (FileInfoRequest) GetFSID

func (r FileInfoRequest) GetFSID() string

type FileListAllRequest

type FileListAllRequest struct {
	// contains filtered or unexported fields
}

func NewFileListAllRequest

func NewFileListAllRequest(path string) FileListAllRequest

func (FileListAllRequest) Desc

func (FileListAllRequest) Execute

func (FileListAllRequest) GetWeb

func (r FileListAllRequest) GetWeb() string

func (FileListAllRequest) Limit

func (FileListAllRequest) Order

func (FileListAllRequest) Path

func (FileListAllRequest) Recursion

func (FileListAllRequest) Start

func (FileListAllRequest) Web

type FileListAllResponse

type FileListAllResponse struct {
	Errno   int32          `json:"errno"`
	Errmsg  string         `json:"errmsg"`
	HasMore int            `json:"has_more"`
	Cursor  int            `json:"cursor"`
	List    []*FileInfoDto `json:"list"`
}

type FileListRequest

type FileListRequest struct {
	// contains filtered or unexported fields
}

func NewFileListRequest

func NewFileListRequest() FileListRequest

func (FileListRequest) Desc

func (FileListRequest) Dir

func (FileListRequest) Execute

func (r FileListRequest) Execute() (*FileListResponse, error)

func (FileListRequest) GetStart

func (r FileListRequest) GetStart() string

func (FileListRequest) GetWeb

func (r FileListRequest) GetWeb() string

func (FileListRequest) Limit

func (FileListRequest) Order

func (FileListRequest) Page

func (r FileListRequest) Page(page int) FileListRequest

func (FileListRequest) Web

func (r FileListRequest) Web(web int) FileListRequest

type FileListResponse

type FileListResponse struct {
	Response
	GuidInfo string         `json:"guid_info"`
	Errmsg   string         `json:"errmsg"`
	List     []*FileInfoDto `json:"list"`
}

func NewFileListResponse

func NewFileListResponse(r *http.Response) (*FileListResponse, error)

func (FileListResponse) Print

func (f FileListResponse) Print()

type FileManageOpera

type FileManageOpera int

type FileManagerFile

type FileManagerFile struct {
	Path    string `json:"path,omitempty"`
	Newname string `json:"newname,omitempty"`
	Dest    string `json:"dest,omitempty"`
	Ondup   string `json:"ondup,omitempty"`
}

func NewFileManagerFile

func NewFileManagerFile(path, dest, newname, ondup string) *FileManagerFile

type FileManagerInfo

type FileManagerInfo struct {
	ErrorResponse
	Path string `json:"path,omitempty"`
}

type FileManagerRequest

type FileManagerRequest struct {
	Filelist []*FileManagerFile
	// 0 同步,1 自适应,2 异步
	Async int32
	// 全局ondup,遇到重复文件的处理策略,
	// fail(默认,直接返回失败)、newcopy(重命名文件)、overwrite、skip
	Ondup string
	// 文件操作参数,可实现文件复制、移动、重命名、删除,依次对应的参数值为:copy、move、rename、delete
	Opera FileManageOpera
}

func NewFileManagerRequest

func NewFileManagerRequest(opera FileManageOpera, filelist []*FileManagerFile) *FileManagerRequest

func (FileManagerRequest) Execute

func (fm FileManagerRequest) Execute() (*FileManagerResponse, error)

func (FileManagerRequest) GetFilelistString

func (fm FileManagerRequest) GetFilelistString() string

func (*FileManagerRequest) SetOndup

func (f *FileManagerRequest) SetOndup(ondup string) *FileManagerRequest

type FileManagerResponse

type FileManagerResponse struct {
	Response
	Info      []FileManagerInfo `json:"info,omitempty"`
	RequestId int64             `json:"request_id,omitempty"`
	Taskid    int64             `json:"taskid,omitempty"`
}

type FileSearchRequest

type FileSearchRequest struct {
	// contains filtered or unexported fields
}

func NewFileSearchRequest

func NewFileSearchRequest(key string) FileSearchRequest

func (FileSearchRequest) Dir

func (FileSearchRequest) Execute

func (r FileSearchRequest) Execute() (*FileListResponse, error)

func (FileSearchRequest) GetRecursion

func (f FileSearchRequest) GetRecursion() string

func (FileSearchRequest) Recursion

func (f FileSearchRequest) Recursion(r int) FileSearchRequest

type IResponse

type IResponse interface {
	IsError() bool
	Err() error
}

type Icon

type Icon struct {
	Name  string `json:"name"`
	Icon  string `json:"icon"`
	Color string `json:"color"`
}

func GetDefaultFileIcon

func GetDefaultFileIcon() Icon

func GetIconByExt

func GetIconByExt(ext string) (Icon, bool)

func GetIconByPath

func GetIconByPath(path string) (Icon, bool)

type LogFormatter

type LogFormatter struct {
	*logrus.TextFormatter
}

func (*LogFormatter) Format

func (f *LogFormatter) Format(entry *logrus.Entry) ([]byte, error)

type Response

type Response struct {
	ErrorResponse
}

type SelectAction

type SelectAction int
const (
	ActionSystem SelectAction = iota + 100
	ActionDelete
	ActionBack
)

type SelectFunc

type SelectFunc func(index int, s string) error

type SelectItem

type SelectItem struct {
	Name   string
	Icon   string
	Action SelectAction
	Desc   string
	Info   interface{}
}

type SyncMode

type SyncMode int
const (
	ModeBackup SyncMode = iota
	ModeSync
)

type SyncModel

type SyncModel struct {
	ID           string
	Remote       string
	Local        string
	Hash         string
	Mode         SyncMode
	HasHide      bool
	CreateTime   time.Time
	LastSyncTime time.Time
}

func MustGetModel

func MustGetModel(id string) (m *SyncModel)

func NewSyncModel

func NewSyncModel(local, remote string, mode SyncMode) *SyncModel

func (*SyncModel) Backup

func (s *SyncModel) Backup() error

func (SyncModel) BuildPretty

func (s SyncModel) BuildPretty() []pretty.Field

func (SyncModel) Desc

func (s SyncModel) Desc() string

func (*SyncModel) Exec

func (s *SyncModel) Exec() error

func (SyncModel) GetCreateTime

func (s SyncModel) GetCreateTime() string

func (SyncModel) GetLastSyncTime

func (s SyncModel) GetLastSyncTime() string

func (SyncModel) GetMode

func (s SyncModel) GetMode() string

func (SyncModel) IsBackup

func (s SyncModel) IsBackup() bool

type SyncModelSlice

type SyncModelSlice []*SyncModel

func (SyncModelSlice) GetWriter

func (s SyncModelSlice) GetWriter() io.Writer

func (SyncModelSlice) Len

func (s SyncModelSlice) Len() int

func (SyncModelSlice) Less

func (s SyncModelSlice) Less(i, j int) bool

func (SyncModelSlice) List

func (s SyncModelSlice) List() []pretty.Pretty

func (SyncModelSlice) Swap

func (s SyncModelSlice) Swap(i, j int)

type UFTaskInfo

type UFTaskInfo struct {
	Index int
	From  string
	To    string
}

type UploadFileRequest

type UploadFileRequest struct {
	// contains filtered or unexported fields
}

func NewUploadFileRequest

func NewUploadFileRequest(fromPath, toPath string) *UploadFileRequest

func (UploadFileRequest) Execute

func (r UploadFileRequest) Execute() (*UploadFileResponse, error)

func (UploadFileRequest) FromPath

func (r UploadFileRequest) FromPath(path string) UploadFileRequest

func (UploadFileRequest) GetPartseq

func (r UploadFileRequest) GetPartseq() string

func (*UploadFileRequest) IsSync

func (*UploadFileRequest) RType

func (UploadFileRequest) ToPath

func (UploadFileRequest) Type

type UploadFileResponse

type UploadFileResponse struct {
	Response
	FileInfoDto
}

type UploadFragmentTasker

type UploadFragmentTasker struct {
	*tasker.Tasker
	Request   *UploadFileRequest
	Token     *AccessToken
	UploadId  string
	TmpDir    string
	Fragments []string
	To        string
	IsSync    bool
}

func (*UploadFragmentTasker) AfterRun

func (u *UploadFragmentTasker) AfterRun() error

func (*UploadFragmentTasker) BeforeRun

func (u *UploadFragmentTasker) BeforeRun() error

func (*UploadFragmentTasker) Build

func (u *UploadFragmentTasker) Build() error

func (*UploadFragmentTasker) BuildTasks

func (u *UploadFragmentTasker) BuildTasks() error

func (*UploadFragmentTasker) Exec

func (u *UploadFragmentTasker) Exec() error

func (UploadFragmentTasker) RunTask

func (u UploadFragmentTasker) RunTask(task *tasker.Task) error

type UploadTaskInfo

type UploadTaskInfo struct {
	From string
	To   string
}

type UploadTasker

type UploadTasker struct {
	*tasker.Tasker
	// 迁移的地址
	From          string
	To            string
	IsSync        bool
	IsRecursion   bool // 是否递归子文件夹文件
	IsIncludeHide bool // 是否上传隐藏文件
	// contains filtered or unexported fields
}

func NewUploadDirTasker

func NewUploadDirTasker(from, to string) (*UploadTasker, error)

func NewUploadTasker

func NewUploadTasker(from, to string) (*UploadTasker, error)

func (*UploadTasker) AfterRun

func (m *UploadTasker) AfterRun() error

func (*UploadTasker) BeforeRun

func (u *UploadTasker) BeforeRun() error

func (*UploadTasker) BuildTasks

func (m *UploadTasker) BuildTasks() error

func (*UploadTasker) Exec

func (u *UploadTasker) Exec() error

func (*UploadTasker) GetExistFileMap added in v0.3.3

func (u *UploadTasker) GetExistFileMap() (map[string]FileInfoDto, error)

func (UploadTasker) RunTask

func (m UploadTasker) RunTask(task *tasker.Task) error

func (*UploadTasker) SetRegexp

func (u *UploadTasker) SetRegexp(pattern string) *UploadTasker

type UserInfoDto

type UserInfoDto struct {
	openapi.Uinforesponse
}

func UserInfo

func UserInfo() (*UserInfoDto, error)

func (UserInfoDto) GetVipName

func (u UserInfoDto) GetVipName() string

Directories

Path Synopsis
cmd
Package godler provides ...
Package godler provides ...

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL