Documentation
¶
Index ¶
- func CalculateMD5(filePath string) (string, error)
- func CalculateSliceMD5(filePath string, sliceSize int64) ([]string, error)
- func FormatBytes(bytes int64) string
- func FormatDiskInfo(info *DiskInfoResponse) string
- func FormatFileInfo(fileInfo *FileInfo) string
- func FormatTime(unixTime int64) string
- func GetCopyErrorMessage(errno int) string
- func GetErrorMessage(errno int) string
- func GetMoveErrorMessage(errno int) string
- func GetRenameErrorMessage(errno int) string
- func GetSourceFileName(path string) string
- func MapFileType(isDir int) string
- func PrintError(message string)
- func PrintErrorAndExit(message string)
- func PrintSuccess(message string)
- type Client
- func (c *Client) Authorize(ctx context.Context) error
- func (c *Client) CopyFile(sourcePath, destPath string) error
- func (c *Client) CopyFiles(copyRequests []CopyRequest) error
- func (c *Client) CreateDir(remotePath string) error
- func (c *Client) DownloadFile(filePath string) (*http.Response, error)
- func (c *Client) DownloadFileToPath(filePath, localPath string) error
- func (c *Client) EnsureRemoteDirExists(remotePath string) error
- func (c *Client) GetAndDisplayFileInfo(filePath string) (*FileInfo, error)
- func (c *Client) GetDetailedFileInfo(filePath string) (*FileInfo, error)
- func (c *Client) GetDeviceCode() (*DeviceCodeResponse, error)
- func (c *Client) GetDeviceCodeForPoll(deviceCode string) (*DeviceCodeResponse, error)
- func (c *Client) GetDiskInfo() (*DiskInfoResponse, error)
- func (c *Client) GetFileInfo(filePath string) (*FileInfo, error)
- func (c *Client) GetFileInfoByPath(filePath string) (*FileInfo, error)
- func (c *Client) HasRefreshToken() bool
- func (c *Client) HasValidToken() bool
- func (c *Client) IsTokenExpired() bool
- func (c *Client) ListFiles(dirPath string) ([]FileInfo, error)
- func (c *Client) LoadTokens() error
- func (c *Client) MoveFile(sourcePath, destDir string) error
- func (c *Client) MoveFiles(moveRequests []MoveRequest) error
- func (c *Client) PollForToken(deviceCode string) (*TokenResponse, error)
- func (c *Client) ReadFileContent(filePath string) ([]byte, error)
- func (c *Client) RefreshToken() error
- func (c *Client) RemoveFile(filePath string) error
- func (c *Client) RemoveFiles(filePaths []string) error
- func (c *Client) RenameFile(sourcePath, newName string) error
- func (c *Client) RenameFiles(renameRequests []RenameRequest) error
- func (c *Client) SaveTokens() error
- func (c *Client) UploadFile(localFilePath, remoteFilePath string) error
- func (c *Client) Walk(rootPath string) (<-chan FileInfo, <-chan error)
- func (c *Client) WalkRecursive(path string, fileChan chan<- FileInfo, errChan chan<- error)
- type CopyInfo
- type CopyRequest
- type CopyResponse
- type CreateFileResponse
- type DeleteEntry
- type DeleteResponse
- type DeviceCodeResponse
- type DiskInfoResponse
- type FileInfo
- type ListFilesResponse
- type MoveInfo
- type MoveRequest
- type MoveResponse
- type PrecreateResponse
- type ProgressWriter
- type RenameInfo
- type RenameRequest
- type RenameResponse
- type TokenFile
- type TokenResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateMD5 ¶ added in v0.1.1
CalculateMD5 calculates the MD5 hash of a given file
func CalculateSliceMD5 ¶ added in v0.1.1
CalculateSliceMD5 calculates MD5 hashes for fixed-size slices of a file
func FormatBytes ¶
FormatBytes converts bytes to a human-readable format (e.g., KB, MB, GB)
func FormatDiskInfo ¶
func FormatDiskInfo(info *DiskInfoResponse) string
FormatDiskInfo formats the disk information in a human-readable way
func FormatFileInfo ¶
FormatFileInfo formats the file information in a human-readable way
func FormatTime ¶
FormatTime converts Unix timestamp to readable time format
func GetCopyErrorMessage ¶ added in v0.1.1
GetCopyErrorMessage returns a human-readable error message for common errno values
func GetErrorMessage ¶ added in v0.1.1
GetErrorMessage returns a human-readable error message for common errno values
func GetMoveErrorMessage ¶ added in v0.1.1
GetMoveErrorMessage returns a human-readable error message for common errno values
func GetRenameErrorMessage ¶ added in v0.1.1
GetRenameErrorMessage returns a human-readable error message for common errno values
func GetSourceFileName ¶ added in v0.1.1
GetSourceFileName extracts the filename from a path
func MapFileType ¶
MapFileType converts the isdir field to a readable file type
func PrintError ¶
func PrintError(message string)
PrintError prints an error message with consistent formatting
func PrintErrorAndExit ¶
func PrintErrorAndExit(message string)
PrintErrorAndExit prints an error message and exits with code 1
func PrintSuccess ¶
func PrintSuccess(message string)
PrintSuccess prints a success message with consistent formatting
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a Baidu Pan client
func (*Client) Authorize ¶
Authorize tries to load existing tokens first, and if not available or valid, performs device code authorization
func (*Client) CopyFile ¶
CopyFile copies a single file or directory from source path to destination directory in Baidu Pan
func (*Client) CopyFiles ¶
func (c *Client) CopyFiles(copyRequests []CopyRequest) error
CopyFiles copies multiple files based on the provided CopyRequest structs
func (*Client) DownloadFile ¶
DownloadFile downloads a file from Baidu Pan
func (*Client) DownloadFileToPath ¶
DownloadFileToPath downloads a file from Baidu Pan and saves it to the specified local path
func (*Client) EnsureRemoteDirExists ¶ added in v0.1.1
EnsureRemoteDirExists verifies the remote directory path is valid. Baidu Pan's API typically creates parent directories if they don't exist during upload, so this function primarily serves to validate the path format.
func (*Client) GetAndDisplayFileInfo ¶
GetAndDisplayFileInfo gets file information from Baidu Pan and returns formatted information This encapsulates the logic for getting file info from Baidu Pan and processing it
func (*Client) GetDetailedFileInfo ¶
GetDetailedFileInfo gets detailed information about a file using the meta API This is more efficient than listing files when you only need info about one file
func (*Client) GetDeviceCode ¶
func (c *Client) GetDeviceCode() (*DeviceCodeResponse, error)
GetDeviceCode initiates the device code flow
func (*Client) GetDeviceCodeForPoll ¶
func (c *Client) GetDeviceCodeForPoll(deviceCode string) (*DeviceCodeResponse, error)
GetDeviceCodeForPoll gets device code info specifically for polling (internal use)
func (*Client) GetDiskInfo ¶
func (c *Client) GetDiskInfo() (*DiskInfoResponse, error)
GetDiskInfo gets the user's cloud storage usage information
func (*Client) GetFileInfo ¶
GetFileInfo gets information about a specific file
func (*Client) GetFileInfoByPath ¶
GetFileInfoByPath gets information about a specific file or directory by its path This method uses the list API with a filter to get information about a single file
func (*Client) HasRefreshToken ¶
HasRefreshToken returns whether the client has a refresh token available
func (*Client) HasValidToken ¶
HasValidToken checks if there's a valid token in the file
func (*Client) IsTokenExpired ¶
IsTokenExpired checks if the token is expired or will expire soon (within 2 days)
func (*Client) LoadTokens ¶
LoadTokens loads the access token from a file
func (*Client) MoveFile ¶
MoveFile moves a single file or directory from source path to destination directory in Baidu Pan
func (*Client) MoveFiles ¶
func (c *Client) MoveFiles(moveRequests []MoveRequest) error
MoveFiles moves multiple files based on the provided MoveRequest structs
func (*Client) PollForToken ¶
func (c *Client) PollForToken(deviceCode string) (*TokenResponse, error)
PollForToken polls the token endpoint until the user completes authorization
func (*Client) ReadFileContent ¶
ReadFileContent reads the content of a file from Baidu Pan
func (*Client) RefreshToken ¶
RefreshToken attempts to refresh the access token using the refresh token
func (*Client) RemoveFile ¶
RemoveFile removes a single file or directory from Baidu Pan
func (*Client) RemoveFiles ¶
RemoveFiles removes multiple files or directories from Baidu Pan
func (*Client) RenameFile ¶
RenameFile renames a single file or directory in Baidu Pan
func (*Client) RenameFiles ¶
func (c *Client) RenameFiles(renameRequests []RenameRequest) error
RenameFiles renames multiple files based on the provided RenameRequest structs
func (*Client) SaveTokens ¶
SaveTokens saves the access token to a file
func (*Client) UploadFile ¶
UploadFile uploads a local file to Baidu Pan
type CopyInfo ¶
type CopyInfo struct {
Path string `json:"path"`
Dest string `json:"dest"`
NewName string `json:"newname"`
Errno int `json:"errno"`
}
CopyInfo represents the result for each copied file in the response
type CopyRequest ¶
type CopyRequest struct {
Path string `json:"path"`
Dest string `json:"dest"`
NewName string `json:"newname"`
}
CopyRequest represents the structure for a file to be copied
type CopyResponse ¶
type CopyResponse struct {
Errno int `json:"errno"`
Info []CopyInfo `json:"info"`
TaskID int64 `json:"taskid"`
RequestID int64 `json:"request_id"`
}
CopyResponse represents the response from the copy API
type CreateFileResponse ¶
type CreateFileResponse struct {
Errno int `json:"errno"`
FsID int64 `json:"fs_id"`
Path string `json:"path"`
CTime int64 `json:"ctime"`
MTime int64 `json:"mtime"`
MD5 string `json:"md5"`
Size int64 `json:"size"`
Isdir int `json:"isdir"`
Ifhassubdir int `json:"ifhassubdir"`
Category int `json:"category"`
ServerFilename string `json:"server_filename"`
ParentPath string `json:"parent_path"`
}
CreateFileResponse represents the response from the create file API
type DeleteEntry ¶
DeleteEntry represents the result for each file in the delete operation
type DeleteResponse ¶
type DeleteResponse struct {
Errno int `json:"errno"`
RequestID int64 `json:"request_id"`
List []DeleteEntry `json:"list"`
}
DeleteResponse represents the response from the delete API
type DeviceCodeResponse ¶
type DeviceCodeResponse struct {
DeviceCode string `json:"device_code"`
UserCode string `json:"user_code"`
VerificationURL string `json:"verification_url"`
ExpiresIn int `json:"expires_in"`
Interval int `json:"interval"`
QRCode string `json:"qrcode,omitempty"`
}
DeviceCodeResponse represents the response from device code endpoint
type DiskInfoResponse ¶
type DiskInfoResponse struct {
Errno int64 `json:"errno"`
Total int64 `json:"total"` // Total space size in bytes
Used int64 `json:"used"` // Used space size in bytes
Free int64 `json:"free"` // Free capacity in bytes
Expire bool `json:"expire"` // Whether capacity will expire within 7 days
RequestID int64 `json:"request_id"`
}
DiskInfoResponse represents the response from the disk info API
type FileInfo ¶
type FileInfo struct {
TkBindID int `json:"tkbind_id"`
OwnerType int `json:"owner_type"`
Category int `json:"category"`
IsScene int `json:"is_scene"`
FsID int64 `json:"fs_id"`
BlackTag int `json:"black_tag"`
ServerFilename string `json:"server_filename"`
ExtentInt2 int `json:"extent_int2"`
ServerAtime int64 `json:"server_atime"`
ServerCtime int64 `json:"server_ctime"`
ExtentInt8 int `json:"extent_int8"`
WpFile int `json:"wpfile"`
Unlist int `json:"unlist"`
LocalMtime int64 `json:"local_mtime"`
Size int64 `json:"size"`
OperID int64 `json:"oper_id"`
OwnerID int64 `json:"owner_id"`
FromType int `json:"from_type"`
Path string `json:"path"`
LocalCTime int64 `json:"local_ctime"`
PL int `json:"pl"`
RealCategory string `json:"real_category"`
IsDir int `json:"isdir"`
ExtentTinyInt7 int `json:"extent_tinyint7"`
ServerMtime int64 `json:"server_mtime"`
MD5 string `json:"md5,omitempty"`
}
FileInfo represents a file or directory in Baidu Pan
type ListFilesResponse ¶
type ListFilesResponse struct {
Errno int `json:"errno"`
GuidInfo string `json:"guid_info"`
List []FileInfo `json:"list"`
RequestID int64 `json:"request_id"`
Guid int `json:"guid"`
}
ListFilesResponse represents the response from the list files API
type MoveInfo ¶
type MoveInfo struct {
Path string `json:"path"`
Dest string `json:"dest"`
NewName string `json:"newname"`
Errno int `json:"errno"`
}
MoveInfo represents the result for each moved file in the response
type MoveRequest ¶
type MoveRequest struct {
Path string `json:"path"`
Dest string `json:"dest"`
NewName string `json:"newname"`
}
MoveRequest represents the structure for a file to be moved
type MoveResponse ¶
type MoveResponse struct {
Errno int `json:"errno"`
Info []MoveInfo `json:"info"`
TaskID int64 `json:"taskid"`
RequestID int64 `json:"request_id"`
}
MoveResponse represents the response from the move API
type PrecreateResponse ¶
type PrecreateResponse struct {
Errno int `json:"errno"`
UploadID string `json:"uploadid"`
BlockList []int `json:"block_list"`
RequestID int64 `json:"request_id"`
ReturnType int `json:"return_type"` // 1: need upload, 2: no need upload (file already exists and matches)
}
PrecreateResponse represents the response from the precreate API
type ProgressWriter ¶
type ProgressWriter struct {
// contains filtered or unexported fields
}
ProgressWriter wraps an io.Writer and reports progress
type RenameInfo ¶
RenameInfo represents the result for each renamed file in the response
type RenameRequest ¶
RenameRequest represents the structure for a file to be renamed
type RenameResponse ¶
type RenameResponse struct {
Errno int `json:"errno"`
Info []RenameInfo `json:"info"`
TaskID int64 `json:"taskid"`
RequestID int64 `json:"request_id"`
}
RenameResponse represents the response from the rename API
type TokenFile ¶
type TokenFile struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresIn int `json:"expires_in"`
UID string `json:"uid"`
CreatedAt time.Time `json:"created_at"` // Time when token was obtained
}
TokenFile represents the structure for storing tokens in a file
type TokenResponse ¶
type TokenResponse struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresIn int `json:"expires_in"`
Scope string `json:"scope"`
SessionKey string `json:"session_key"`
SessionSecret string `json:"session_secret"`
UID string `json:"uid"`
}
TokenResponse represents the access token response