Documentation
¶
Overview ¶
Package pikpak provides a complete Go SDK for the PikPak cloud storage API.
PikPak is a cloud storage service that supports file storage, offline downloads (including magnet links and torrents), and media streaming.
Basic Usage ¶
Create a new client and authenticate:
client := pikpak.NewClient(
pikpak.WithCredentials("your-email@example.com", "your-password"),
pikpak.WithPlatform(pikpak.PlatformWeb),
)
if err := client.Init(); err != nil {
log.Fatal(err)
}
File Operations ¶
List files in root directory:
files, err := client.GetRootFiles()
if err != nil {
log.Fatal(err)
}
for _, f := range files.Files {
fmt.Printf("%s: %s\n", f.Name, f.ID)
}
Offline Downloads ¶
Add a magnet link for offline download:
task, err := client.OfflineDownload(
"magnet:?xt=urn:btih:...",
"", // parent folder ID (empty for root)
"", // filename (auto-detected for magnets)
)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Download started: %s\n", task.ID)
Uploading Files ¶
Upload a file:
file, err := os.Open("myfile.txt")
if err != nil {
log.Fatal(err)
}
defer file.Close()
stat, _ := file.Stat()
uploadedFile, err := client.UploadFile(
context.Background(),
"", // parent folder ID
stat.Name(),
file,
stat.Size(),
func(uploaded, total int64) {
fmt.Printf("Progress: %d/%d\n", uploaded, total)
},
)
Token Persistence ¶
Save and restore tokens for persistent sessions:
// Save tokens after login
client := pikpak.NewClient(
pikpak.WithCredentials(email, password),
pikpak.WithTokenRefreshCallback(func(access, refresh string) {
// Save to database or file
saveTokens(access, refresh)
}),
)
// Restore tokens on next run
client := pikpak.NewClient(
pikpak.WithRefreshToken(savedRefreshToken),
pikpak.WithAccessToken(savedAccessToken),
)
client.Init()
Package pikpak provides a Go SDK for the PikPak cloud storage API.
Index ¶
- Constants
- Variables
- func BuildAndroidUserAgent(...) string
- func CalculateGCID(reader io.Reader, size int64) (string, error)
- func FormatBytes(bytes int64) string
- func GenerateDeviceID(username, password string) string
- func GenerateDeviceSign(deviceID, packageName string) string
- func GetAction(method, url string) string
- func GetCaptchaSign(clientID, clientVersion, packageName, deviceID string, algorithms []string) (timestamp, sign string)
- func GetMD5(s string) string
- func GetSHA1(s string) string
- func IsAuthError(err error) bool
- func IsCaptchaError(err error) bool
- func IsNotFoundError(err error) bool
- func IsRateLimitError(err error) bool
- func IsValidEmail(s string) bool
- func IsValidPhoneNumber(s string) bool
- func ParseTime(s string) (time.Time, error)
- type AboutResponse
- type BatchResponse
- type CaptchaTokenRequest
- type CaptchaTokenResponse
- type Client
- func (c *Client) CancelOfflineTask(taskID string) error
- func (c *Client) Copy(fileIDs []string, destParentID string) error
- func (c *Client) CopyFile(fileID, destParentID string) error
- func (c *Client) CopyFolder(folderID, destParentID string) error
- func (c *Client) CreateFolder(parentID, name string) (*File, error)
- func (c *Client) CreateFolderPath(path string, parentID string) (string, error)
- func (c *Client) CreateShare(fileIDs []string, password string, expirationDays int) (*ShareInfo, error)
- func (c *Client) CreateUploadTask(parentID, name, gcidHash string, size int64) (*UploadTaskData, error)
- func (c *Client) Delete(fileIDs []string) error
- func (c *Client) DeleteFile(fileID string) error
- func (c *Client) DeleteFolder(folderID string) error
- func (c *Client) DeleteOfflineTask(taskID string, deleteFiles bool) error
- func (c *Client) DeleteOfflineTasks(taskIDs []string, deleteFiles bool) error
- func (c *Client) DeleteShare(shareID string) error
- func (c *Client) EmptyTrash() error
- func (c *Client) GetAbout() (*AboutResponse, error)
- func (c *Client) GetAccessToken() string
- func (c *Client) GetAllRootFiles() ([]File, error)
- func (c *Client) GetCompletedTasks() ([]OfflineTask, error)
- func (c *Client) GetDownloadURL(fileID string) (string, error)
- func (c *Client) GetFailedTasks() ([]OfflineTask, error)
- func (c *Client) GetFile(fileID string) (*File, error)
- func (c *Client) GetFileWithMediaLink(fileID string) (*File, error)
- func (c *Client) GetFolderByPath(path string) (*File, error)
- func (c *Client) GetFolderContents(folderID string) ([]File, error)
- func (c *Client) GetInvites() ([]Invite, error)
- func (c *Client) GetMediaURL(fileID string) (string, error)
- func (c *Client) GetOfflineTask(taskID string) (*OfflineTask, error)
- func (c *Client) GetPendingTasks() ([]OfflineTask, error)
- func (c *Client) GetQuota() (used, total int64, err error)
- func (c *Client) GetRefreshToken() string
- func (c *Client) GetRootFiles() (*Files, error)
- func (c *Client) GetRunningTasks() ([]OfflineTask, error)
- func (c *Client) GetShare(shareID string) (*ShareResp, error)
- func (c *Client) GetStorageUsage() (*StorageUsage, error)
- func (c *Client) GetUserID() string
- func (c *Client) GetUserInfo() (*UserInfo, error)
- func (c *Client) GetVIPInfo() (*VIPInfo, error)
- func (c *Client) Init() error
- func (c *Client) IsAuthenticated() bool
- func (c *Client) ListAllFiles(parentID string) ([]File, error)
- func (c *Client) ListAllOfflineTasks(phases []string) ([]OfflineTask, error)
- func (c *Client) ListFiles(parentID string, opts *ListOptions) (*Files, error)
- func (c *Client) ListOfflineTasks(opts *OfflineListOptions) ([]OfflineTask, error)
- func (c *Client) ListStarred(pageToken string, pageSize int) (*Files, error)
- func (c *Client) ListTrash(pageToken string, pageSize int) (*Files, error)
- func (c *Client) Login() error
- func (c *Client) Move(fileIDs []string, destParentID string) error
- func (c *Client) MoveFile(fileID, destParentID string) error
- func (c *Client) MoveFolder(folderID, destParentID string) error
- func (c *Client) OfflineDownload(url, parentID, fileName string) (*OfflineTask, error)
- func (c *Client) OfflineDownloadMagnet(magnetLink, parentID string) (*OfflineTask, error)
- func (c *Client) OfflineDownloadTorrent(torrentURL, parentID string) (*OfflineTask, error)
- func (c *Client) RapidUpload(parentID, name, gcidHash string, size int64) (*File, error)
- func (c *Client) RefreshToken() error
- func (c *Client) Rename(fileID, newName string) error
- func (c *Client) RenameFolder(folderID, newName string) error
- func (c *Client) RetryOfflineTask(taskID string) error
- func (c *Client) SaveSharedFile(shareID, fileID, parentID string, passCodeToken string) error
- func (c *Client) Search(query string, pageToken string, pageSize int) (*Files, error)
- func (c *Client) SetUserID(userID string)
- func (c *Client) ShareFile(fileID string) (*ShareInfo, error)
- func (c *Client) ShareFileWithExpiration(fileID string, expirationDays int) (*ShareInfo, error)
- func (c *Client) ShareFileWithPassword(fileID, password string) (*ShareInfo, error)
- func (c *Client) Star(fileIDs []string) error
- func (c *Client) StarFile(fileID string) error
- func (c *Client) Trash(fileIDs []string) error
- func (c *Client) TrashFile(fileID string) error
- func (c *Client) TrashFolder(folderID string) error
- func (c *Client) Unstar(fileIDs []string) error
- func (c *Client) UnstarFile(fileID string) error
- func (c *Client) Untrash(fileIDs []string) error
- func (c *Client) UntrashFile(fileID string) error
- func (c *Client) UploadFile(ctx context.Context, parentID, name string, reader io.Reader, size int64, ...) (*File, error)
- func (c *Client) UploadFileWithRetry(ctx context.Context, parentID, name string, reader io.ReadSeeker, size int64, ...) (*File, error)
- func (c *Client) UploadFromURL(url, parentID, fileName string) (*OfflineTask, error)
- func (c *Client) WaitForTask(taskID string, checkInterval int) (*OfflineTask, error)
- type ClientOption
- func WithAccessToken(accessToken string) ClientOption
- func WithCaptchaToken(captchaToken string) ClientOption
- func WithCredentials(username, password string) ClientOption
- func WithDeviceID(deviceID string) ClientOption
- func WithPlatform(platform Platform) ClientOption
- func WithProxy(proxyURL string) ClientOption
- func WithRefreshToken(refreshToken string) ClientOption
- func WithTimeout(timeout time.Duration) ClientOption
- func WithTokenRefreshCallback(callback func(accessToken, refreshToken string)) ClientOption
- func WithUserAgent(userAgent string) ClientOption
- type DownloadOptions
- type ErrResp
- type File
- type Files
- type Invite
- type InviteInfo
- type ListOptions
- type Media
- type OfflineDownloadOptions
- type OfflineDownloadResp
- type OfflineListOptions
- type OfflineListResp
- type OfflineParams
- type OfflineTask
- type Platform
- type ReferenceResource
- type S3Params
- type ShareInfo
- type ShareResp
- type StorageUsage
- type TokenResponse
- type TrashResponse
- type UploadOptions
- type UploadProgressFunc
- type UploadTaskData
- type UserInfo
- type VIPInfo
Constants ¶
const ( AndroidClientID = "YNxT9w7GMdWvEOKa" AndroidClientSecret = "dbw2OtmVEeuUvIptb1Coyg" AndroidClientVersion = "1.53.2" AndroidPackageName = "com.pikcloud.pikpak" AndroidSdkVersion = "2.0.6.206003" )
Android client constants
const ( WebClientID = "YUMx5nI8ZU8Ap8pm" WebClientSecret = "dbw2OtmVEeuUvIptb1Coyg" WebClientVersion = "2.0.0" WebPackageName = "mypikpak.com" WebSdkVersion = "8.0.3" )
Web client constants
const ( PCClientID = "YvtoWO6GNHiuCl7x" PCClientSecret = "1NIH5R1IEe2pAxZE3hv3uA" PCClientVersion = "undefined" PCPackageName = "mypikpak.com" PCSdkVersion = "8.0.3" )
PC client constants
const ( APIBaseURL = "https://api-drive.mypikpak.net" UserBaseURL = "https://user.mypikpak.net" )
API base URLs
const ( EndpointFiles = "/drive/v1/files" EndpointAbout = "/drive/v1/about" EndpointTasks = "/drive/v1/tasks" EndpointAuth = "/v1/auth" EndpointCaptcha = "/v1/shield/captcha/init" EndpointFileBatchTrash = "/drive/v1/files:batchTrash" EndpointFileBatchMove = "/drive/v1/files:batchMove" EndpointFileBatchCopy = "/drive/v1/files:batchCopy" )
API endpoints
const ( OSSUserAgent = "aliyun-sdk-android/2.9.13(Linux/Android 14/M2004j7ac;UKQ1.231108.001)" OSSSecurityTokenHeaderName = "X-OSS-Security-Token" )
OSS constants
const ( DefaultWebUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36" DefaultPCUserAgent = "" /* 158-byte string literal not displayed */ )
Default user agents
const ( ErrorCodeAccessTokenExpired = 4122 ErrorCodeAccessTokenInvalid = 4121 ErrorCodeCaptchaTokenExpired = 9 ErrorCodeTooManyRequests = 10 ErrorCodeRefreshTokenInvalid = 4126 )
Error codes
const ( KindFile = "drive#file" KindFolder = "drive#folder" )
File kinds
const ( UploadTypeResumable = "UPLOAD_TYPE_RESUMABLE" UploadTypeURL = "UPLOAD_TYPE_URL" )
Upload types
const ( ThumbnailSizeLarge = "SIZE_LARGE" ThumbnailSizeMedium = "SIZE_MEDIUM" ThumbnailSizeSmall = "SIZE_SMALL" )
Thumbnail sizes
const ( PhaseTypeRunning = "PHASE_TYPE_RUNNING" PhaseTypeError = "PHASE_TYPE_ERROR" PhaseTypeComplete = "PHASE_TYPE_COMPLETE" PhaseTypePending = "PHASE_TYPE_PENDING" )
OfflinePhase constants for offline task phases.
const (
CaptchaRedirectURI = "xlaccsdk01://xbase.cloud/callback?state=harbor"
)
Captcha redirect URI
Variables ¶
var ( ErrNotAuthenticated = errors.New("client is not authenticated") ErrInvalidCredentials = errors.New("invalid username or password") ErrTokenExpired = errors.New("access token has expired") ErrRefreshTokenInvalid = errors.New("refresh token is invalid") ErrCaptchaRequired = errors.New("captcha verification required") ErrRateLimited = errors.New("rate limited, please try again later") ErrFileNotFound = errors.New("file not found") ErrFolderNotFound = errors.New("folder not found") ErrTaskNotFound = errors.New("task not found") ErrUploadFailed = errors.New("upload failed") ErrDownloadFailed = errors.New("download failed") ErrInvalidPath = errors.New("invalid path") ErrInvalidFileID = errors.New("invalid file ID") ErrOperationNotAllowed = errors.New("operation not allowed") ErrQuotaExceeded = errors.New("storage quota exceeded") ErrFileTooLarge = errors.New("file too large") ErrInvalidHash = errors.New("invalid file hash") ErrNetworkError = errors.New("network error") ErrServerError = errors.New("server error") )
Common errors
var AndroidAlgorithms = []string{
"SOP04dGzk0TNO7t7t9ekDbAmx+eq0OI1ovEx",
"nVBjhYiND4hZ2NCGyV5beamIr7k6ifAsAbl",
"Ddjpt5B/Cit6ED2a6cXgxY9lkEIOw4yC1GDF28KrA",
"VVCogcmSNIVvgV6U+AochorydiSymi68YVNGiz",
"u5uj5sM62gpJOsB/1Gu/zsfgfZO",
"dXYIiBOAHZgzSruaQ2Nhrqc2im",
"z5jUTBSIpBN9g4qSJGlidNAutX6",
"KJE2oveZ34du/g1tiimm",
}
AndroidAlgorithms contains the algorithms for Android client signature
var PCAlgorithms = []string{
"KHBJ07an7ROXDoK7Db",
"G6n399rSWkl7WcQmw5rpQInurc1DkLmLqE",
"JZD1A3M4x+jBFN62hkr7VDhkkZxb9g3rWqRZqFAAb",
"fQnw/AmSlbbI91Ik15gpddGgyU7U",
"/Dv9JdPYSj3sHiWjouR95NTQff",
"yGx2zuTjbWENZqecNI+edrQgqmZKP",
"ljrbSzdHLwbqcRn",
"lSHAsqCkGDGxQqqwrVu",
"TsWXI81fD1",
"vk7hBjawK/rOSrSWajtbMk95nfgf3",
}
PCAlgorithms contains the algorithms for PC client signature
var WebAlgorithms = []string{
"C9qPpZLN8uRTaTiUMWYS9cQvWOE",
"+r6CQVxjzJV6LCV",
"F",
"pFJRC",
"9WXYIDGrwTCz2OiVlgZa9qpECPD6olt",
"/750aCr4lm/Sly/c",
"RB+DT/gZCrbV",
"",
"CyLsf7hdkIRxRm215hl",
"7xHvLi2tOYP0Y92b",
"ZGTXXxu8E/MIWaEDB+Sm/",
"1UI3",
"E7fP5Pfijd+7K+t6Tg/NhuLq0eEUVChpJSkrKxpO",
"ihtqpG6FMt65+Xk+tWUH2",
"NhXXU9rg4XXdzo7u5o",
}
WebAlgorithms contains the algorithms for Web client signature
Functions ¶
func BuildAndroidUserAgent ¶
func BuildAndroidUserAgent(deviceID, clientID, appName, sdkVersion, clientVersion, packageName, userID string) string
BuildAndroidUserAgent builds the user agent string for Android client.
func CalculateGCID ¶
CalculateGCID calculates the GCID hash for a file. GCID is a custom hash used by PikPak for file deduplication.
func FormatBytes ¶
FormatBytes formats bytes into human readable string.
func GenerateDeviceID ¶
GenerateDeviceID generates a device ID from username and password.
func GenerateDeviceSign ¶
GenerateDeviceSign generates a device signature for the API.
func GetCaptchaSign ¶
func GetCaptchaSign(clientID, clientVersion, packageName, deviceID string, algorithms []string) (timestamp, sign string)
GetCaptchaSign generates a captcha signature.
func IsAuthError ¶
IsAuthError returns true if the error is an authentication error.
func IsCaptchaError ¶
IsCaptchaError returns true if the error is a captcha verification error.
func IsNotFoundError ¶
IsNotFoundError returns true if the error is a not found error.
func IsRateLimitError ¶
IsRateLimitError returns true if the error is a rate limit error.
func IsValidEmail ¶
IsValidEmail checks if the string is a valid email format.
func IsValidPhoneNumber ¶
IsValidPhoneNumber checks if the string looks like a phone number.
Types ¶
type AboutResponse ¶
type AboutResponse struct {
Quota struct {
Limit string `json:"limit"`
Usage string `json:"usage"`
UsageInTrash string `json:"usage_in_trash"`
IsUnlimited bool `json:"is_unlimited"`
Complimentary string `json:"complimentary"`
} `json:"quota"`
ExpiresAt string `json:"expires_at"`
UserType int `json:"user_type"`
}
AboutResponse represents account quota information.
func (*AboutResponse) GetQuotaLimit ¶
func (a *AboutResponse) GetQuotaLimit() int64
GetQuotaLimit returns the quota limit as int64 bytes.
func (*AboutResponse) GetQuotaUsage ¶
func (a *AboutResponse) GetQuotaUsage() int64
GetQuotaUsage returns the quota usage as int64 bytes.
func (*AboutResponse) GetQuotaUsageInTrash ¶
func (a *AboutResponse) GetQuotaUsageInTrash() int64
GetQuotaUsageInTrash returns the trash usage as int64 bytes.
type BatchResponse ¶
type BatchResponse struct {
TaskID string `json:"task_id"`
}
BatchResponse represents a batch operation response.
type CaptchaTokenRequest ¶
type CaptchaTokenRequest struct {
Action string `json:"action"`
CaptchaToken string `json:"captcha_token"`
ClientID string `json:"client_id"`
DeviceID string `json:"device_id"`
Meta map[string]string `json:"meta"`
RedirectURI string `json:"redirect_uri"`
}
CaptchaTokenRequest represents a captcha token request.
type CaptchaTokenResponse ¶
type CaptchaTokenResponse struct {
CaptchaToken string `json:"captcha_token"`
ExpiresIn int64 `json:"expires_in"`
URL string `json:"url"`
}
CaptchaTokenResponse represents a captcha token response.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func MustNewClient ¶
func MustNewClient(opts ...ClientOption) *Client
MustNewClient creates a new PikPak client and panics on error.
func NewClient ¶
func NewClient(opts ...ClientOption) (*Client, error)
NewClient creates a new PikPak client with the given options. Returns an error if credentials are provided but invalid (empty username or password).
func (*Client) CancelOfflineTask ¶
CancelOfflineTask cancels an offline download task (same as delete without deleting files).
func (*Client) CopyFolder ¶
CopyFolder copies a folder to a new parent.
func (*Client) CreateFolder ¶
CreateFolder creates a new folder.
func (*Client) CreateFolderPath ¶
CreateFolderPath creates folders recursively based on path. Returns the ID of the final folder.
func (*Client) CreateShare ¶
func (c *Client) CreateShare(fileIDs []string, password string, expirationDays int) (*ShareInfo, error)
CreateShare creates a share link for files.
func (*Client) CreateUploadTask ¶
func (c *Client) CreateUploadTask(parentID, name, gcidHash string, size int64) (*UploadTaskData, error)
CreateUploadTask creates an upload task (for resumable upload).
func (*Client) DeleteFile ¶
DeleteFile permanently deletes a single file.
func (*Client) DeleteFolder ¶
DeleteFolder permanently deletes a folder.
func (*Client) DeleteOfflineTask ¶
DeleteOfflineTask deletes a single offline download task.
func (*Client) DeleteOfflineTasks ¶
DeleteOfflineTasks deletes offline download tasks.
func (*Client) DeleteShare ¶
DeleteShare deletes a share link.
func (*Client) GetAbout ¶
func (c *Client) GetAbout() (*AboutResponse, error)
GetAbout gets account quota and usage information.
func (*Client) GetAccessToken ¶
GetAccessToken returns the current access token.
func (*Client) GetAllRootFiles ¶
GetAllRootFiles lists all files in the root directory, handling pagination.
func (*Client) GetCompletedTasks ¶
func (c *Client) GetCompletedTasks() ([]OfflineTask, error)
GetCompletedTasks gets all completed offline tasks.
func (*Client) GetDownloadURL ¶
GetDownloadURL gets the download URL for a file.
func (*Client) GetFailedTasks ¶
func (c *Client) GetFailedTasks() ([]OfflineTask, error)
GetFailedTasks gets all failed offline tasks.
func (*Client) GetFileWithMediaLink ¶
GetFileWithMediaLink gets a file with its media streaming link.
func (*Client) GetFolderByPath ¶
GetFolderByPath finds a folder by its path from root.
func (*Client) GetFolderContents ¶
GetFolderContents gets all contents of a folder by ID.
func (*Client) GetInvites ¶
GetInvites gets invite codes (placeholder).
func (*Client) GetMediaURL ¶
GetMediaURL gets the media streaming URL for a file.
func (*Client) GetOfflineTask ¶
func (c *Client) GetOfflineTask(taskID string) (*OfflineTask, error)
GetOfflineTask gets a specific offline task by ID.
func (*Client) GetPendingTasks ¶
func (c *Client) GetPendingTasks() ([]OfflineTask, error)
GetPendingTasks gets all pending offline tasks.
func (*Client) GetRefreshToken ¶
GetRefreshToken returns the current refresh token.
func (*Client) GetRootFiles ¶
GetRootFiles lists files in the root directory.
func (*Client) GetRunningTasks ¶
func (c *Client) GetRunningTasks() ([]OfflineTask, error)
GetRunningTasks gets all running offline tasks.
func (*Client) GetStorageUsage ¶
func (c *Client) GetStorageUsage() (*StorageUsage, error)
GetStorageUsage returns detailed storage usage information.
func (*Client) GetUserInfo ¶
GetUserInfo gets user information (placeholder - implement based on API).
func (*Client) GetVIPInfo ¶
GetVIPInfo gets VIP subscription information.
func (*Client) IsAuthenticated ¶
IsAuthenticated returns true if the client has authentication tokens.
func (*Client) ListAllFiles ¶
ListAllFiles lists all files in a directory, handling pagination automatically.
func (*Client) ListAllOfflineTasks ¶
func (c *Client) ListAllOfflineTasks(phases []string) ([]OfflineTask, error)
ListAllOfflineTasks lists all offline download tasks, handling pagination.
func (*Client) ListFiles ¶
func (c *Client) ListFiles(parentID string, opts *ListOptions) (*Files, error)
ListFiles lists files in a directory.
func (*Client) ListOfflineTasks ¶
func (c *Client) ListOfflineTasks(opts *OfflineListOptions) ([]OfflineTask, error)
ListOfflineTasks lists offline download tasks.
func (*Client) ListStarred ¶
ListStarred lists starred files.
func (*Client) MoveFolder ¶
MoveFolder moves a folder to a new parent.
func (*Client) OfflineDownload ¶
func (c *Client) OfflineDownload(url, parentID, fileName string) (*OfflineTask, error)
OfflineDownload adds a URL to be downloaded by PikPak.
func (*Client) OfflineDownloadMagnet ¶
func (c *Client) OfflineDownloadMagnet(magnetLink, parentID string) (*OfflineTask, error)
OfflineDownloadMagnet adds a magnet link to be downloaded.
func (*Client) OfflineDownloadTorrent ¶
func (c *Client) OfflineDownloadTorrent(torrentURL, parentID string) (*OfflineTask, error)
OfflineDownloadTorrent adds a torrent by URL to be downloaded.
func (*Client) RapidUpload ¶
RapidUpload attempts to rapid upload (秒传) a file using its GCID hash. If the file already exists on PikPak servers, it will be instantly available.
func (*Client) RefreshToken ¶
RefreshToken refreshes the access token using the refresh token.
func (*Client) RenameFolder ¶
RenameFolder renames a folder.
func (*Client) RetryOfflineTask ¶
RetryOfflineTask retries a failed offline download task.
func (*Client) SaveSharedFile ¶
SaveSharedFile saves a shared file to your drive.
func (*Client) ShareFileWithExpiration ¶
ShareFileWithExpiration creates a share link with expiration.
func (*Client) ShareFileWithPassword ¶
ShareFileWithPassword creates a password-protected share link.
func (*Client) TrashFolder ¶
TrashFolder moves a folder to trash.
func (*Client) UnstarFile ¶
UnstarFile unstars a single file.
func (*Client) UntrashFile ¶
UntrashFile restores a single file from trash.
func (*Client) UploadFile ¶
func (c *Client) UploadFile(ctx context.Context, parentID, name string, reader io.Reader, size int64, progress UploadProgressFunc) (*File, error)
UploadFile uploads a file to PikPak. If the file already exists (based on GCID), it will be instantly uploaded.
func (*Client) UploadFileWithRetry ¶
func (c *Client) UploadFileWithRetry(ctx context.Context, parentID, name string, reader io.ReadSeeker, size int64, progress UploadProgressFunc, maxRetries int) (*File, error)
UploadFileWithRetry uploads a file with automatic retry on failure.
func (*Client) UploadFromURL ¶
func (c *Client) UploadFromURL(url, parentID, fileName string) (*OfflineTask, error)
UploadFromURL uploads a file from a URL (essentially offline download to a specific folder).
func (*Client) WaitForTask ¶
func (c *Client) WaitForTask(taskID string, checkInterval int) (*OfflineTask, error)
WaitForTask waits for an offline task to complete. Returns the completed task or an error if it fails.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption is a function that configures a Client.
func WithAccessToken ¶
func WithAccessToken(accessToken string) ClientOption
WithAccessToken sets an existing access token.
func WithCaptchaToken ¶
func WithCaptchaToken(captchaToken string) ClientOption
func WithCredentials ¶
func WithCredentials(username, password string) ClientOption
WithCredentials sets username and password for authentication.
func WithDeviceID ¶
func WithDeviceID(deviceID string) ClientOption
WithDeviceID sets a custom device ID.
func WithPlatform ¶
func WithPlatform(platform Platform) ClientOption
WithPlatform sets the platform for the client.
func WithProxy ¶
func WithProxy(proxyURL string) ClientOption
WithProxy sets a proxy for HTTP requests.
func WithRefreshToken ¶
func WithRefreshToken(refreshToken string) ClientOption
WithRefreshToken sets an existing refresh token.
func WithTimeout ¶
func WithTimeout(timeout time.Duration) ClientOption
WithTimeout sets the HTTP client timeout.
func WithTokenRefreshCallback ¶
func WithTokenRefreshCallback(callback func(accessToken, refreshToken string)) ClientOption
WithTokenRefreshCallback sets a callback for when tokens are refreshed.
func WithUserAgent ¶
func WithUserAgent(userAgent string) ClientOption
WithUserAgent sets a custom user agent.
type DownloadOptions ¶
DownloadOptions represents options for downloading files.
type ErrResp ¶
type ErrResp struct {
ErrorCode int64 `json:"error_code"`
ErrorMsg string `json:"error"`
ErrorDescription string `json:"error_description"`
}
ErrResp represents an error response from PikPak API.
type File ¶
type File struct {
ID string `json:"id"`
Kind string `json:"kind"`
Name string `json:"name"`
CreatedTime time.Time `json:"created_time"`
ModifiedTime time.Time `json:"modified_time"`
Hash string `json:"hash"`
Size string `json:"size"`
ParentID string `json:"parent_id"`
MimeType string `json:"mime_type"`
ThumbnailLink string `json:"thumbnail_link"`
WebContentLink string `json:"web_content_link"`
Medias []Media `json:"medias"`
Trashed bool `json:"trashed"`
Phase string `json:"phase"`
}
File represents a file or folder in PikPak.
type Invite ¶
type Invite struct {
Code string `json:"code"`
Used bool `json:"used"`
ExpiresAt string `json:"expires_at"`
}
Invite represents an invite.
type InviteInfo ¶
InviteInfo represents invite code information.
type ListOptions ¶
type ListOptions struct {
ParentID string
PageToken string
PageSize int
Filters map[string]interface{}
ThumbnailSize string
WithAudit bool
}
ListOptions represents options for listing files.
func DefaultListOptions ¶
func DefaultListOptions() *ListOptions
DefaultListOptions returns default list options.
type Media ¶
type Media struct {
MediaID string `json:"media_id"`
MediaName string `json:"media_name"`
Video struct {
Height int `json:"height"`
Width int `json:"width"`
Duration int `json:"duration"`
BitRate int `json:"bit_rate"`
FrameRate int `json:"frame_rate"`
VideoCodec string `json:"video_codec"`
AudioCodec string `json:"audio_codec"`
VideoType string `json:"video_type"`
} `json:"video"`
Link struct {
URL string `json:"url"`
Token string `json:"token"`
Expire time.Time `json:"expire"`
} `json:"link"`
NeedMoreQuota bool `json:"need_more_quota"`
VipTypes []interface{} `json:"vip_types"`
RedirectLink string `json:"redirect_link"`
IconLink string `json:"icon_link"`
IsDefault bool `json:"is_default"`
Priority int `json:"priority"`
IsOrigin bool `json:"is_origin"`
ResolutionName string `json:"resolution_name"`
IsVisible bool `json:"is_visible"`
Category string `json:"category"`
}
Media represents media information for a file.
type OfflineDownloadOptions ¶
OfflineDownloadOptions represents options for offline download.
type OfflineDownloadResp ¶
type OfflineDownloadResp struct {
File *string `json:"file"`
Task OfflineTask `json:"task"`
UploadType string `json:"upload_type"`
URL struct {
Kind string `json:"kind"`
} `json:"url"`
}
OfflineDownloadResp represents offline download response.
type OfflineListOptions ¶
type OfflineListOptions struct {
PageToken string
PageSize int
Phases []string // e.g., ["PHASE_TYPE_RUNNING", "PHASE_TYPE_COMPLETE"]
}
OfflineListOptions represents options for listing offline tasks.
func DefaultOfflineListOptions ¶
func DefaultOfflineListOptions() *OfflineListOptions
DefaultOfflineListOptions returns default offline list options.
type OfflineListResp ¶
type OfflineListResp struct {
ExpiresIn int64 `json:"expires_in"`
NextPageToken string `json:"next_page_token"`
Tasks []OfflineTask `json:"tasks"`
}
OfflineListResp represents offline download list response.
type OfflineParams ¶
type OfflineParams struct {
Age string `json:"age"`
MIMEType *string `json:"mime_type,omitempty"`
PredictType string `json:"predict_type"`
URL string `json:"url"`
}
OfflineParams represents offline task parameters.
type OfflineTask ¶
type OfflineTask struct {
Callback string `json:"callback"`
CreatedTime string `json:"created_time"`
FileID string `json:"file_id"`
FileName string `json:"file_name"`
FileSize string `json:"file_size"`
IconLink string `json:"icon_link"`
ID string `json:"id"`
Kind string `json:"kind"`
Message string `json:"message"`
Name string `json:"name"`
Params OfflineParams `json:"params"`
Phase string `json:"phase"` // PHASE_TYPE_RUNNING, PHASE_TYPE_ERROR, PHASE_TYPE_COMPLETE, PHASE_TYPE_PENDING
Progress int64 `json:"progress"`
ReferenceResource ReferenceResource `json:"reference_resource"`
Space string `json:"space"`
StatusSize int64 `json:"status_size"`
Statuses []string `json:"statuses"`
ThirdTaskID string `json:"third_task_id"`
Type string `json:"type"`
UpdatedTime string `json:"updated_time"`
UserID string `json:"user_id"`
}
OfflineTask represents an offline download task.
func (*OfflineTask) GetFileSize ¶
func (t *OfflineTask) GetFileSize() int64
GetFileSize returns the file size as int64.
func (*OfflineTask) IsComplete ¶
func (t *OfflineTask) IsComplete() bool
IsComplete returns true if the task is complete.
func (*OfflineTask) IsError ¶
func (t *OfflineTask) IsError() bool
IsError returns true if the task has an error.
func (*OfflineTask) IsPending ¶
func (t *OfflineTask) IsPending() bool
IsPending returns true if the task is pending.
func (*OfflineTask) IsRunning ¶
func (t *OfflineTask) IsRunning() bool
IsRunning returns true if the task is running.
type ReferenceResource ¶
type ReferenceResource struct {
Type string `json:"@type"`
Audit interface{} `json:"audit"`
Hash string `json:"hash"`
IconLink string `json:"icon_link"`
ID string `json:"id"`
Kind string `json:"kind"`
Medias []Media `json:"medias"`
MIMEType string `json:"mime_type"`
Name string `json:"name"`
Params map[string]interface{} `json:"params"`
ParentID string `json:"parent_id"`
Phase string `json:"phase"`
Size string `json:"size"`
Space string `json:"space"`
Starred bool `json:"starred"`
Tags []string `json:"tags"`
ThumbnailLink string `json:"thumbnail_link"`
}
ReferenceResource represents referenced resource in offline task.
type S3Params ¶
type S3Params struct {
AccessKeyID string `json:"access_key_id"`
AccessKeySecret string `json:"access_key_secret"`
Bucket string `json:"bucket"`
Endpoint string `json:"endpoint"`
Expiration time.Time `json:"expiration"`
Key string `json:"key"`
SecurityToken string `json:"security_token"`
}
S3Params represents S3/OSS upload parameters.
type StorageUsage ¶
GetStorageUsage returns storage usage statistics.
type TokenResponse ¶
type TokenResponse struct {
TokenType string `json:"token_type"`
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresIn int64 `json:"expires_in"`
Sub string `json:"sub"`
UserID string `json:"user_id"`
}
TokenResponse represents an authentication token response.
type TrashResponse ¶
type TrashResponse struct {
TaskID string `json:"task_id"`
}
TrashResponse represents a trash operation response.
type UploadOptions ¶
UploadOptions represents options for uploading files.
type UploadProgressFunc ¶
type UploadProgressFunc func(uploaded, total int64)
UploadProgressFunc is a callback function for upload progress.
type UploadTaskData ¶
type UploadTaskData struct {
UploadType string `json:"upload_type"`
Resumable *struct {
Kind string `json:"kind"`
Params S3Params `json:"params"`
Provider string `json:"provider"`
} `json:"resumable"`
File File `json:"file"`
}
UploadTaskData represents upload task response.