Documentation
¶
Index ¶
- func ServerUploadLimitWaitN(ctx context.Context, n int) error
- type Additional
- type ArchiveDecompress
- type ArchiveDecompressResult
- type ArchiveGetter
- type ArchiveReader
- type Config
- type Copy
- type CopyResult
- type DirectUploader
- type Driver
- type GetRooter
- type Getter
- type IRootId
- type IRootPath
- type Info
- type Item
- type LinkCacheMode
- type LinkCacheModeResolver
- type Meta
- type Mkdir
- type MkdirResult
- type Move
- type MoveResult
- type Other
- type Progress
- type Put
- type PutResult
- type PutURL
- type PutURLResult
- type RateLimitFile
- type RateLimitReader
- type RateLimitWriter
- type Reader
- type ReaderUpdatingProgress
- type ReaderWithCtx
- type Reference
- type Remove
- type Rename
- type RenameResult
- type RootID
- type RootPath
- type SeedHashStream
- func (s *SeedHashStream) Add(io.Closer)
- func (s *SeedHashStream) AddIfCloser(any)
- func (s *SeedHashStream) CacheFullAndWriter(*model.UpdateProgress, io.Writer) (model.File, error)
- func (s *SeedHashStream) Close() error
- func (s *SeedHashStream) CreateTime() time.Time
- func (s *SeedHashStream) GetExist() model.Obj
- func (s *SeedHashStream) GetFile() model.File
- func (s *SeedHashStream) GetHash() utils.HashInfo
- func (s *SeedHashStream) GetID() string
- func (s *SeedHashStream) GetMimetype() string
- func (s *SeedHashStream) GetName() string
- func (s *SeedHashStream) GetPath() string
- func (s *SeedHashStream) GetSize() int64
- func (s *SeedHashStream) IsDir() bool
- func (s *SeedHashStream) IsForceStreamUpload() bool
- func (s *SeedHashStream) ModTime() time.Time
- func (s *SeedHashStream) NeedStore() bool
- func (s *SeedHashStream) RangeRead(http_range.Range) (io.Reader, error)
- func (s *SeedHashStream) Read([]byte) (int, error)
- func (s *SeedHashStream) SetExist(model.Obj)
- type SeedRapidUploadRequest
- type SeedRapidUploader
- type Select
- type SimpleReaderWithSize
- type UpdateProgress
- type WithDetails
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Additional ¶
type Additional interface{}
type ArchiveDecompress ¶
type ArchiveDecompressResult ¶
type ArchiveDecompressResult interface {
// ArchiveDecompress decompress an archive
// when args.PutIntoNewDir, the new sub-folder should be named the same to the archive but without the extension
// return each decompressed obj from the root path of the archive when args.PutIntoNewDir is false
// return only the newly created folder when args.PutIntoNewDir is true
// return errs.NotImplement to use internal archive tools to decompress
ArchiveDecompress(ctx context.Context, srcObj, dstDir model.Obj, args model.ArchiveDecompressArgs) ([]model.Obj, error)
}
type ArchiveGetter ¶
type ArchiveGetter interface {
// ArchiveGet get file by inner path
// return errs.NotImplement to use internal archive tools to get the children
// return errs.NotSupport if the folder structure should be acquired from model.ArchiveMeta.GetTree
ArchiveGet(ctx context.Context, obj model.Obj, args model.ArchiveInnerArgs) (model.Obj, error)
}
type ArchiveReader ¶
type ArchiveReader interface {
// GetArchiveMeta get the meta-info of an archive
// return errs.WrongArchivePassword if the meta-info is also encrypted but provided password is wrong or empty
// return errs.NotImplement to use internal archive tools to get the meta-info, such as the following cases:
// 1. the driver do not support the format of the archive but there may be an internal tool do
// 2. handling archives is a VIP feature, but the driver does not have VIP access
GetArchiveMeta(ctx context.Context, obj model.Obj, args model.ArchiveArgs) (model.ArchiveMeta, error)
// ListArchive list the children of model.ArchiveArgs.InnerPath in the archive
// return errs.NotImplement to use internal archive tools to list the children
// return errs.NotSupport if the folder structure should be acquired from model.ArchiveMeta.GetTree
ListArchive(ctx context.Context, obj model.Obj, args model.ArchiveInnerArgs) ([]model.Obj, error)
// Extract get url/filepath/reader of a file in the archive
// return errs.NotImplement to use internal archive tools to extract
Extract(ctx context.Context, obj model.Obj, args model.ArchiveInnerArgs) (*model.Link, error)
}
type Config ¶
type Config struct {
Name string `json:"name"`
LocalSort bool `json:"local_sort"`
OnlyProxy bool `json:"only_proxy"`
NoCache bool `json:"no_cache"`
NoUpload bool `json:"no_upload"`
// if need get message from user, such as validate code
NeedMs bool `json:"need_ms"`
DefaultRoot string `json:"default_root"`
CheckStatus bool `json:"-"`
//info,success,warning,danger
Alert string `json:"alert"`
// whether to support overwrite upload
NoOverwriteUpload bool `json:"-"`
ProxyRangeOption bool `json:"-"`
// if the driver returns Link without URL, this should be set to true
NoLinkURL bool `json:"-"`
// Link cache behaviour:
// - LinkCacheAuto: let driver decide per-path (implement driver.LinkCacheModeResolver)
// - LinkCacheNone: no extra info added to cache key (default)
// - flags (OR-able) can add more attributes to cache key (IP, UA, ...)
LinkCacheMode `json:"-"`
// if the driver only store indices of files (e.g. UrlTree)
OnlyIndices bool `json:"only_indices"`
// prefer proxy download even if direct link is available
PreferProxy bool `json:"prefer_proxy"`
}
func (Config) DefaultProxy ¶ added in v4.1.10
type CopyResult ¶
type DirectUploader ¶ added in v4.1.7
type DirectUploader interface {
// GetDirectUploadTools returns available frontend-direct upload tools
GetDirectUploadTools() []string
// GetDirectUploadInfo returns the information needed for direct upload from client to storage
// actualPath is the path relative to the storage root (after removing mount path prefix)
// return errs.NotImplement if the driver does not support the given direct upload tool
GetDirectUploadInfo(ctx context.Context, tool string, dstDir model.Obj, fileName string, fileSize int64) (any, error)
}
type LinkCacheMode ¶ added in v4.1.5
type LinkCacheMode int8
const ( LinkCacheAuto LinkCacheMode = -1 // Let the driver decide per-path (use driver.LinkCacheModeResolver) LinkCacheNone LinkCacheMode = 0 // No extra info added to cache key (default) )
const ( LinkCacheIP LinkCacheMode = 1 << iota // include client IP in cache key LinkCacheUA // include User-Agent in cache key )
type LinkCacheModeResolver ¶ added in v4.1.5
type LinkCacheModeResolver interface {
// ResolveLinkCacheMode returns the LinkCacheMode for the given path.
ResolveLinkCacheMode(path string) LinkCacheMode
}
type Meta ¶
type Meta interface {
Config() Config
// GetStorage just get raw storage, no need to implement, because model.Storage have implemented
GetStorage() *model.Storage
SetStorage(model.Storage)
// GetAddition Additional is used for unmarshal of JSON, so need return pointer
GetAddition() Additional
// Init If already initialized, drop first
Init(ctx context.Context) error
Drop(ctx context.Context) error
}
type MkdirResult ¶
type MoveResult ¶
type Progress ¶
func NewProgress ¶
func NewProgress(total int64, up UpdateProgress) *Progress
type Put ¶
type Put interface {
// Put a file (provided as a FileStreamer) into the driver
// Besides the most basic upload functionality, the following features also need to be implemented:
// 1. Canceling (when `<-ctx.Done()` returns), which can be supported by the following methods:
// (1) Use request methods that carry context, such as the following:
// a. http.NewRequestWithContext
// b. resty.Request.SetContext
// c. s3manager.Uploader.UploadWithContext
// d. utils.CopyWithCtx
// (2) Use a `driver.ReaderWithCtx` or `driver.NewLimitedUploadStream`
// (3) Use `utils.IsCanceled` to check if the upload has been canceled during the upload process,
// this is typically applicable to chunked uploads.
// 2. Submit upload progress (via `up`) in real-time. There are three recommended ways as follows:
// (1) Use `utils.CopyWithCtx`
// (2) Use `driver.ReaderUpdatingProgress`
// (3) Use `driver.Progress` with `io.TeeReader`
// 3. Slow down upload speed (via `stream.ServerUploadLimit`). It requires you to wrap the read stream
// in a `driver.RateLimitReader` or a `driver.RateLimitFile` after calculating the file's hash and
// before uploading the file or file chunks. Or you can directly call `driver.ServerUploadLimitWaitN`
// if your file chunks are sufficiently small (less than about 50KB).
// NOTE that the network speed may be significantly slower than the stream's read speed. Therefore, if
// you use a `errgroup.Group` to upload each chunk in parallel, you should use `Group.SetLimit` to
// limit the maximum number of upload threads, preventing excessive memory usage caused by buffering
// too many file chunks awaiting upload.
Put(ctx context.Context, dstDir model.Obj, file model.FileStreamer, up UpdateProgress) error
}
type PutResult ¶
type PutResult interface {
// Put a file (provided as a FileStreamer) into the driver and return the put obj
// Besides the most basic upload functionality, the following features also need to be implemented:
// 1. Canceling (when `<-ctx.Done()` returns), which can be supported by the following methods:
// (1) Use request methods that carry context, such as the following:
// a. http.NewRequestWithContext
// b. resty.Request.SetContext
// c. s3manager.Uploader.UploadWithContext
// d. utils.CopyWithCtx
// (2) Use a `driver.ReaderWithCtx` or `driver.NewLimitedUploadStream`
// (3) Use `utils.IsCanceled` to check if the upload has been canceled during the upload process,
// this is typically applicable to chunked uploads.
// 2. Submit upload progress (via `up`) in real-time. There are three recommended ways as follows:
// (1) Use `utils.CopyWithCtx`
// (2) Use `driver.ReaderUpdatingProgress`
// (3) Use `driver.Progress` with `io.TeeReader`
// 3. Slow down upload speed (via `stream.ServerUploadLimit`). It requires you to wrap the read stream
// in a `driver.RateLimitReader` or a `driver.RateLimitFile` after calculating the file's hash and
// before uploading the file or file chunks. Or you can directly call `driver.ServerUploadLimitWaitN`
// if your file chunks are sufficiently small (less than about 50KB).
// NOTE that the network speed may be significantly slower than the stream's read speed. Therefore, if
// you use a `errgroup.Group` to upload each chunk in parallel, you should use `Group.SetLimit` to
// limit the maximum number of upload threads, preventing excessive memory usage caused by buffering
// too many file chunks awaiting upload.
Put(ctx context.Context, dstDir model.Obj, file model.FileStreamer, up UpdateProgress) (model.Obj, error)
}
type PutURL ¶
type PutURL interface {
// PutURL directly put a URL into the storage
// Applicable to index-based drivers like URL-Tree or drivers that support uploading files as URLs
// Called when using SimpleHttp for offline downloading, skipping creating a download task
PutURL(ctx context.Context, dstDir model.Obj, name, url string) error
}
type PutURLResult ¶
type PutURLResult interface {
// PutURL directly put a URL into the storage
// Applicable to index-based drivers like URL-Tree or drivers that support uploading files as URLs
// Called when using SimpleHttp for offline downloading, skipping creating a download task
PutURL(ctx context.Context, dstDir model.Obj, name, url string) (model.Obj, error)
}
type RateLimitFile ¶
type RateLimitFile = stream.RateLimitFile
func NewLimitedUploadFile ¶
func NewLimitedUploadFile(ctx context.Context, f model.File) *RateLimitFile
type RateLimitReader ¶
type RateLimitReader = stream.RateLimitReader
func NewLimitedUploadStream ¶
func NewLimitedUploadStream(ctx context.Context, r io.Reader) *RateLimitReader
type RateLimitWriter ¶
type RateLimitWriter = stream.RateLimitWriter
type Reader ¶
type Reader interface {
// List files in the path
// if identify files by path, need to set ID with path,like path.Join(dir.GetID(), obj.GetName())
// if identify files by id, need to set ID with corresponding id
List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error)
// Link get url/filepath/reader of file
Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error)
}
type ReaderUpdatingProgress ¶
type ReaderUpdatingProgress = stream.ReaderUpdatingProgress
type ReaderWithCtx ¶
type ReaderWithCtx = stream.ReaderWithCtx
type RenameResult ¶
type RootPath ¶
type RootPath struct {
RootFolderPath string `json:"root_folder_path"`
}
func (RootPath) GetRootPath ¶
func (*RootPath) SetRootPath ¶
type SeedHashStream ¶ added in v4.2.8
type SeedHashStream struct {
// Source lazily opens the underlying content streamer. May be nil.
Source func() (model.FileStreamer, error)
// contains filtered or unexported fields
}
SeedHashStream is a model.FileStreamer that only carries file metadata and precomputed hashes; it never yields real content.
It exists so that hash-driven rapid upload (秒传/CAS) implementations can reuse the drivers' existing Put/RapidUpload code paths, which expect a model.FileStreamer but only read the name/size/hash. Drivers that additionally need the real content (e.g. to compute a leading proof hash) should supply Source, which is exposed via GetReadCloser-like lazy opening.
func NewSeedHashStream ¶ added in v4.2.8
func NewSeedHashStream(req *SeedRapidUploadRequest) *SeedHashStream
NewSeedHashStream builds a hash-only streamer from a rapid-upload request.
func (*SeedHashStream) Add ¶ added in v4.2.8
func (s *SeedHashStream) Add(io.Closer)
func (*SeedHashStream) AddIfCloser ¶ added in v4.2.8
func (s *SeedHashStream) AddIfCloser(any)
func (*SeedHashStream) CacheFullAndWriter ¶ added in v4.2.8
func (s *SeedHashStream) CacheFullAndWriter(*model.UpdateProgress, io.Writer) (model.File, error)
CacheFullAndWriter reports that the content cannot be materialized.
func (*SeedHashStream) Close ¶ added in v4.2.8
func (s *SeedHashStream) Close() error
func (*SeedHashStream) CreateTime ¶ added in v4.2.8
func (s *SeedHashStream) CreateTime() time.Time
func (*SeedHashStream) GetExist ¶ added in v4.2.8
func (s *SeedHashStream) GetExist() model.Obj
func (*SeedHashStream) GetFile ¶ added in v4.2.8
func (s *SeedHashStream) GetFile() model.File
func (*SeedHashStream) GetHash ¶ added in v4.2.8
func (s *SeedHashStream) GetHash() utils.HashInfo
func (*SeedHashStream) GetID ¶ added in v4.2.8
func (s *SeedHashStream) GetID() string
func (*SeedHashStream) GetMimetype ¶ added in v4.2.8
func (s *SeedHashStream) GetMimetype() string
func (*SeedHashStream) GetName ¶ added in v4.2.8
func (s *SeedHashStream) GetName() string
func (*SeedHashStream) GetPath ¶ added in v4.2.8
func (s *SeedHashStream) GetPath() string
func (*SeedHashStream) GetSize ¶ added in v4.2.8
func (s *SeedHashStream) GetSize() int64
func (*SeedHashStream) IsDir ¶ added in v4.2.8
func (s *SeedHashStream) IsDir() bool
func (*SeedHashStream) IsForceStreamUpload ¶ added in v4.2.8
func (s *SeedHashStream) IsForceStreamUpload() bool
func (*SeedHashStream) ModTime ¶ added in v4.2.8
func (s *SeedHashStream) ModTime() time.Time
func (*SeedHashStream) NeedStore ¶ added in v4.2.8
func (s *SeedHashStream) NeedStore() bool
func (*SeedHashStream) RangeRead ¶ added in v4.2.8
func (s *SeedHashStream) RangeRead(http_range.Range) (io.Reader, error)
RangeRead returns an empty reader, since no content is available.
func (*SeedHashStream) Read ¶ added in v4.2.8
func (s *SeedHashStream) Read([]byte) (int, error)
Read returns EOF: the stream carries hashes only, no content.
func (*SeedHashStream) SetExist ¶ added in v4.2.8
func (s *SeedHashStream) SetExist(model.Obj)
type SeedRapidUploadRequest ¶ added in v4.2.8
type SeedRapidUploadRequest struct {
// Name is the target file name.
Name string
// Size is the total file size in bytes.
Size int64
// Whole holds whole-file hashes indexed by algorithm (e.g. utils.MD5,
// utils.SHA1). It must never be nil; individual entries may be empty.
Whole *utils.HashInfo
// SliceSize is the per-slice/piece size in bytes (0 when unknown).
SliceSize int64
// SliceMD5s is the ordered per-slice MD5 list (used by 189pc-style CAS).
SliceMD5s []string
// SliceSHA1s is the ordered per-slice SHA1 list (used by SHA1-piece drives).
SliceSHA1s []string
// Open lazily yields the file content as a model.FileStreamer. Drivers whose
// rapid-upload protocol needs partial or full content (e.g. a leading
// pre-hash or a proof-code) may call it; hash-only drivers may ignore it.
// Open may be nil when no content source is available, in which case
// drivers that strictly require content must fail gracefully.
Open func() (model.FileStreamer, error)
}
SeedRapidUploadRequest carries everything a driver needs to attempt a hash-driven rapid upload (秒传/CAS) without transferring the full content.
It is populated from a parsed transfer seed, so that any cloud drive supporting hash-based rapid upload can be used as a seed save target.
type SeedRapidUploader ¶ added in v4.2.8
type SeedRapidUploader interface {
// RapidUploadByHashes attempts a rapid upload of a file into dstDir.
//
// Implementations should return errs.NotImplement (or a descriptive error)
// when the required hash is missing, the file does not exist remotely, or
// the rapid upload cannot be confirmed.
RapidUploadByHashes(ctx context.Context, dstDir model.Obj, req *SeedRapidUploadRequest, overwrite bool) (model.Obj, error)
// RapidHashAlgos reports the whole-file hash algorithms accepted by
// RapidUploadByHashes (e.g. utils.MD5, utils.SHA1).
RapidHashAlgos() []utils.HashType
// RapidHashNeedsPieces reports whether RapidUploadByHashes relies on
// per-slice hashes (CAS slice MD5s / SHA1 pieces) for this driver.
RapidHashNeedsPieces() bool
}
SeedRapidUploader is an optional capability interface implemented by drivers that can perform a "rapid upload" (秒传/CAS) driven by precomputed hashes instead of a full content transfer.
It generalizes the previous hard-coded 189pc-specific CAS path so that any cloud drive supporting hash-based rapid upload (e.g. 189pc via MD5+slice MD5, 115/aliyundrive_open via SHA1) can be used as a transfer-seed save target.
type SimpleReaderWithSize ¶
type SimpleReaderWithSize = stream.SimpleReaderWithSize
type UpdateProgress ¶
type UpdateProgress = model.UpdateProgress
type WithDetails ¶ added in v4.1.4
type WithDetails interface {
// GetDetails get storage details (total space, free space, etc.)
GetDetails(ctx context.Context) (*model.StorageDetails, error)
}