Documentation
¶
Overview ¶
Package nextcloud provides a high-level client for Nextcloud WebDAV operations, including chunked uploads that bypass proxy body-size limits.
Index ¶
- func SaveCheckpoint(checkpoint Checkpoint, filePath string) error
- type BufferPool
- type Checkpoint
- type Client
- func (c *Client) ResumeUpload(checkpoint Checkpoint, config *Config) error
- func (c *Client) SetVerbose(verbose bool)
- func (c *Client) UploadDir(localDir, dstDir string, config *Config) error
- func (c *Client) UploadFile(localPath, dstPath string, config *Config) error
- func (c *Client) UploadFileResumable(localPath, dstPath string, config *Config) (*UploadController, error)
- func (c *Client) UploadFileWithContext(ctx context.Context, localPath, dstPath string, config *Config) error
- type Config
- type EventInfo
- type ProgressInfo
- type UploadController
- type UploadError
- type UploadEvent
- type UploadState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SaveCheckpoint ¶ added in v1.0.0
func SaveCheckpoint(checkpoint Checkpoint, filePath string) error
SaveCheckpoint saves a checkpoint to a file (JSON format)
Types ¶
type BufferPool ¶ added in v1.0.0
type BufferPool struct {
// contains filtered or unexported fields
}
BufferPool manages reusable byte buffers to reduce allocations
func NewBufferPool ¶ added in v1.0.0
func NewBufferPool(chunkSize int64, poolSize int) *BufferPool
NewBufferPool creates a new buffer pool with the specified chunk size and pool size
func (*BufferPool) Get ¶ added in v1.0.0
func (bp *BufferPool) Get() []byte
Get retrieves a buffer from the pool or creates a new one
func (*BufferPool) Put ¶ added in v1.0.0
func (bp *BufferPool) Put(buf []byte)
Put returns a buffer to the pool for reuse
type Checkpoint ¶ added in v1.0.0
type Checkpoint struct {
LocalPath string `json:"local_path"`
RemotePath string `json:"remote_path"`
UploadID string `json:"upload_id"`
FileSize int64 `json:"file_size"`
ChunkSize int64 `json:"chunk_size"`
BytesUploaded int64 `json:"bytes_uploaded"`
ChunksUploaded int `json:"chunks_uploaded"`
TotalChunks int `json:"total_chunks"`
Timestamp time.Time `json:"timestamp"`
Config *Config `json:"config,omitempty"`
}
Checkpoint represents a resumable upload checkpoint
func LoadCheckpoint ¶ added in v1.0.0
func LoadCheckpoint(filePath string) (*Checkpoint, error)
LoadCheckpoint loads a checkpoint from a file
type Client ¶
Client wraps a gowebdav.Client with Nextcloud-specific operations.
func (*Client) ResumeUpload ¶ added in v1.0.0
func (c *Client) ResumeUpload(checkpoint Checkpoint, config *Config) error
ResumeUpload resumes an upload from a checkpoint
func (*Client) SetVerbose ¶
SetVerbose enables or disables verbose logging.
func (*Client) UploadFile ¶
UploadFile uploads a single file using Nextcloud's chunked upload protocol. The dstPath is relative to the user's files directory.
func (*Client) UploadFileResumable ¶ added in v1.0.0
func (c *Client) UploadFileResumable(localPath, dstPath string, config *Config) (*UploadController, error)
UploadFileResumable uploads a file with built-in pause/resume support
type Config ¶
type Config struct {
ChunkSize int64 // Chunk size in bytes (default 10MB)
SkipExisting bool // Skip files that exist with same size
Verbose bool // Enable verbose logging
ProgressFunc func(info ProgressInfo) // Progress callback with detailed info
EventFunc func(info EventInfo) // Event callback for upload lifecycle
MaxRetries int // Maximum retry attempts for failed chunks (default 3)
BufferPool *BufferPool // Optional buffer pool for memory reuse
Controller *UploadController // Upload controller for pause/resume (optional)
CheckpointFunc func(cp Checkpoint) // Checkpoint callback for resume functionality
ResumeFromCheckpoint *Checkpoint // Resume from this checkpoint (optional)
}
Config holds options for upload operations.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns sensible defaults for upload operations.
type EventInfo ¶ added in v1.0.0
type EventInfo struct {
Event UploadEvent // Type of event
Filename string // Name of the file
Path string // Remote path
Message string // Optional message
Error error // Error if applicable
}
EventInfo contains information about upload events
type ProgressInfo ¶
type ProgressInfo struct {
Filename string // Name of the file being uploaded
Current int64 // Bytes uploaded so far
Total int64 // Total file size in bytes
Percentage float64 // Upload progress as percentage (0.0 to 100.0)
ChunkIndex int // Current chunk number (0-based)
TotalChunks int // Total number of chunks
}
ProgressInfo contains detailed progress information for uploads.
type UploadController ¶ added in v1.0.0
type UploadController struct {
// contains filtered or unexported fields
}
UploadController provides pause/resume functionality for uploads
func NewUploadController ¶ added in v1.0.0
func NewUploadController() *UploadController
NewUploadController creates a new upload controller
func (*UploadController) Cancel ¶ added in v1.0.0
func (uc *UploadController) Cancel()
Cancel cancels the upload
func (*UploadController) Pause ¶ added in v1.0.0
func (uc *UploadController) Pause()
Pause pauses the upload
func (*UploadController) Resume ¶ added in v1.0.0
func (uc *UploadController) Resume()
Resume resumes the upload
func (*UploadController) State ¶ added in v1.0.0
func (uc *UploadController) State() UploadState
State returns the current upload state
type UploadError ¶ added in v1.0.0
type UploadError struct {
Op string // Operation that failed
Path string // File path involved
Err error // Underlying error
Retries int // Number of retries attempted
}
UploadError represents errors that occur during upload
func (*UploadError) Error ¶ added in v1.0.0
func (e *UploadError) Error() string
func (*UploadError) Unwrap ¶ added in v1.0.0
func (e *UploadError) Unwrap() error
type UploadEvent ¶ added in v1.0.0
type UploadEvent string
UploadEvent represents different stages of the upload process
const ( EventUploadStarted UploadEvent = "upload_started" // Upload process initiated EventChunkUploaded UploadEvent = "chunk_uploaded" // Individual chunk uploaded EventChunksComplete UploadEvent = "chunks_complete" // All chunks uploaded, before move EventMoveStarted UploadEvent = "move_started" // Starting final move operation EventMoveComplete UploadEvent = "move_complete" // Move operation completed EventUploadComplete UploadEvent = "upload_complete" // Entire upload process finished EventUploadFailed UploadEvent = "upload_failed" // Upload failed EventUploadSkipped UploadEvent = "upload_skipped" // File skipped (already exists) EventUploadPaused UploadEvent = "upload_paused" // Upload paused EventUploadResumed UploadEvent = "upload_resumed" // Upload resumed from checkpoint )
type UploadState ¶ added in v1.0.0
type UploadState int
UploadState represents the current state of an upload
const ( StateRunning UploadState = iota StatePaused StateCancelled )