forked from TrueCloudLab/rclone
pikpak: improve getFile() usage
Previously, `getFile()` was called indiscriminately during uploads, moves, and download link generation. This could lead to users with download limit causing subsequent operations like uploads and moves to fail. This PR optimizes the use of getFile(), by only calling it when it's strictly necessary.
This commit is contained in:
parent
a0dacf4930
commit
b2f6aac754
2 changed files with 21 additions and 15 deletions
|
@ -53,7 +53,7 @@ const (
|
||||||
PhaseTypePending = "PHASE_TYPE_PENDING"
|
PhaseTypePending = "PHASE_TYPE_PENDING"
|
||||||
UploadTypeForm = "UPLOAD_TYPE_FORM"
|
UploadTypeForm = "UPLOAD_TYPE_FORM"
|
||||||
UploadTypeResumable = "UPLOAD_TYPE_RESUMABLE"
|
UploadTypeResumable = "UPLOAD_TYPE_RESUMABLE"
|
||||||
ListLimit = 100
|
ListLimit = 500
|
||||||
)
|
)
|
||||||
|
|
||||||
// ------------------------------------------------------------
|
// ------------------------------------------------------------
|
||||||
|
@ -156,6 +156,7 @@ type FileList struct {
|
||||||
NextPageToken string `json:"next_page_token"`
|
NextPageToken string `json:"next_page_token"`
|
||||||
Version string `json:"version,omitempty"`
|
Version string `json:"version,omitempty"`
|
||||||
VersionOutdated bool `json:"version_outdated,omitempty"`
|
VersionOutdated bool `json:"version_outdated,omitempty"`
|
||||||
|
SyncTime Time `json:"sync_time"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// File is a basic element representing a single file object
|
// File is a basic element representing a single file object
|
||||||
|
@ -165,14 +166,14 @@ type FileList struct {
|
||||||
// 2) the other from File.Medias[].Link.URL.
|
// 2) the other from File.Medias[].Link.URL.
|
||||||
// Empirically, 2) is less restrictive to multiple concurrent range-requests
|
// Empirically, 2) is less restrictive to multiple concurrent range-requests
|
||||||
// for a single file, i.e. supports for higher `--multi-thread-streams=N`.
|
// for a single file, i.e. supports for higher `--multi-thread-streams=N`.
|
||||||
// However, it is not generally applicable as it is only for meadia.
|
// However, it is not generally applicable as it is only for media.
|
||||||
type File struct {
|
type File struct {
|
||||||
Apps []*FileApp `json:"apps,omitempty"`
|
Apps []*FileApp `json:"apps,omitempty"`
|
||||||
Audit *FileAudit `json:"audit,omitempty"`
|
Audit *FileAudit `json:"audit,omitempty"`
|
||||||
Collection string `json:"collection,omitempty"` // TODO
|
Collection string `json:"collection,omitempty"` // TODO
|
||||||
CreatedTime Time `json:"created_time,omitempty"`
|
CreatedTime Time `json:"created_time,omitempty"`
|
||||||
DeleteTime Time `json:"delete_time,omitempty"`
|
DeleteTime Time `json:"delete_time,omitempty"`
|
||||||
FileCategory string `json:"file_category,omitempty"`
|
FileCategory string `json:"file_category,omitempty"` // "AUDIO", "VIDEO"
|
||||||
FileExtension string `json:"file_extension,omitempty"`
|
FileExtension string `json:"file_extension,omitempty"`
|
||||||
FolderType string `json:"folder_type,omitempty"`
|
FolderType string `json:"folder_type,omitempty"`
|
||||||
Hash string `json:"hash,omitempty"` // sha1 but NOT a valid file hash. looks like a torrent hash
|
Hash string `json:"hash,omitempty"` // sha1 but NOT a valid file hash. looks like a torrent hash
|
||||||
|
@ -191,11 +192,14 @@ type File struct {
|
||||||
ParentID string `json:"parent_id,omitempty"`
|
ParentID string `json:"parent_id,omitempty"`
|
||||||
Phase string `json:"phase,omitempty"`
|
Phase string `json:"phase,omitempty"`
|
||||||
Revision int `json:"revision,omitempty,string"`
|
Revision int `json:"revision,omitempty,string"`
|
||||||
|
ReferenceEvents []interface{} `json:"reference_events"`
|
||||||
|
ReferenceResource interface{} `json:"reference_resource"`
|
||||||
Size int64 `json:"size,omitempty,string"`
|
Size int64 `json:"size,omitempty,string"`
|
||||||
SortName string `json:"sort_name,omitempty"`
|
SortName string `json:"sort_name,omitempty"`
|
||||||
Space string `json:"space,omitempty"`
|
Space string `json:"space,omitempty"`
|
||||||
SpellName []interface{} `json:"spell_name,omitempty"` // TODO maybe list of something?
|
SpellName []interface{} `json:"spell_name,omitempty"` // TODO maybe list of something?
|
||||||
Starred bool `json:"starred,omitempty"`
|
Starred bool `json:"starred,omitempty"`
|
||||||
|
Tags []interface{} `json:"tags"`
|
||||||
ThumbnailLink string `json:"thumbnail_link,omitempty"`
|
ThumbnailLink string `json:"thumbnail_link,omitempty"`
|
||||||
Trashed bool `json:"trashed,omitempty"`
|
Trashed bool `json:"trashed,omitempty"`
|
||||||
UserID string `json:"user_id,omitempty"`
|
UserID string `json:"user_id,omitempty"`
|
||||||
|
@ -241,7 +245,8 @@ type Media struct {
|
||||||
IsOrigin bool `json:"is_origin,omitempty"`
|
IsOrigin bool `json:"is_origin,omitempty"`
|
||||||
ResolutionName string `json:"resolution_name,omitempty"`
|
ResolutionName string `json:"resolution_name,omitempty"`
|
||||||
IsVisible bool `json:"is_visible,omitempty"`
|
IsVisible bool `json:"is_visible,omitempty"`
|
||||||
Category string `json:"category,omitempty"`
|
Category string `json:"category,omitempty"` // "category_origin"
|
||||||
|
Audio interface{} `json:"audio"` // TODO: undiscovered yet
|
||||||
}
|
}
|
||||||
|
|
||||||
// FileParams includes parameters for instant open
|
// FileParams includes parameters for instant open
|
||||||
|
@ -395,6 +400,7 @@ type Quota struct {
|
||||||
UsageInTrash int64 `json:"usage_in_trash,omitempty,string"` // bytes in trash but this seems not working
|
UsageInTrash int64 `json:"usage_in_trash,omitempty,string"` // bytes in trash but this seems not working
|
||||||
PlayTimesLimit string `json:"play_times_limit,omitempty"` // maybe in seconds
|
PlayTimesLimit string `json:"play_times_limit,omitempty"` // maybe in seconds
|
||||||
PlayTimesUsage string `json:"play_times_usage,omitempty"` // maybe in seconds
|
PlayTimesUsage string `json:"play_times_usage,omitempty"` // maybe in seconds
|
||||||
|
IsUnlimited bool `json:"is_unlimited,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Share is a response to RequestShare
|
// Share is a response to RequestShare
|
||||||
|
|
|
@ -1016,21 +1016,24 @@ func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object,
|
||||||
}
|
}
|
||||||
dstObj.id = srcObj.id
|
dstObj.id = srcObj.id
|
||||||
|
|
||||||
var info *api.File
|
|
||||||
if srcLeaf != dstLeaf {
|
if srcLeaf != dstLeaf {
|
||||||
// Rename
|
// Rename
|
||||||
info, err = f.renameObject(ctx, srcObj.id, dstLeaf)
|
info, err := f.renameObject(ctx, srcObj.id, dstLeaf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("move: couldn't rename moved file: %w", err)
|
return nil, fmt.Errorf("move: couldn't rename moved file: %w", err)
|
||||||
}
|
}
|
||||||
|
err = dstObj.setMetaData(info)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Update info
|
// Update info
|
||||||
info, err = f.getFile(ctx, dstObj.id)
|
err = dstObj.readMetaData(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("move: couldn't update moved file: %w", err)
|
return nil, fmt.Errorf("move: couldn't locate moved file: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return dstObj, dstObj.setMetaData(info)
|
return dstObj, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy objects
|
// copy objects
|
||||||
|
@ -1143,7 +1146,7 @@ func (f *Fs) uploadByForm(ctx context.Context, in io.Reader, name string, size i
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Fs) uploadByResumable(ctx context.Context, in io.Reader, resumable *api.Resumable, options ...fs.OpenOption) (err error) {
|
func (f *Fs) uploadByResumable(ctx context.Context, in io.Reader, resumable *api.Resumable) (err error) {
|
||||||
p := resumable.Params
|
p := resumable.Params
|
||||||
endpoint := strings.Join(strings.Split(p.Endpoint, ".")[1:], ".") // "mypikpak.com"
|
endpoint := strings.Join(strings.Split(p.Endpoint, ".")[1:], ".") // "mypikpak.com"
|
||||||
|
|
||||||
|
@ -1206,7 +1209,7 @@ func (f *Fs) upload(ctx context.Context, in io.Reader, leaf, dirID, sha1Str stri
|
||||||
if uploadType == api.UploadTypeForm && newfile.Form != nil {
|
if uploadType == api.UploadTypeForm && newfile.Form != nil {
|
||||||
err = f.uploadByForm(ctx, in, req.Name, size, newfile.Form, options...)
|
err = f.uploadByForm(ctx, in, req.Name, size, newfile.Form, options...)
|
||||||
} else if uploadType == api.UploadTypeResumable && newfile.Resumable != nil {
|
} else if uploadType == api.UploadTypeResumable && newfile.Resumable != nil {
|
||||||
err = f.uploadByResumable(ctx, in, newfile.Resumable, options...)
|
err = f.uploadByResumable(ctx, in, newfile.Resumable)
|
||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("unable to proceed upload: %+v", newfile)
|
return nil, fmt.Errorf("unable to proceed upload: %+v", newfile)
|
||||||
}
|
}
|
||||||
|
@ -1214,10 +1217,7 @@ func (f *Fs) upload(ctx context.Context, in io.Reader, leaf, dirID, sha1Str stri
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to upload: %w", err)
|
return nil, fmt.Errorf("failed to upload: %w", err)
|
||||||
}
|
}
|
||||||
// refresh uploaded file info
|
return newfile.File, nil
|
||||||
// Compared to `newfile.File` this upgrades several fields...
|
|
||||||
// audit, links, modified_time, phase, revision, and web_content_link
|
|
||||||
return f.getFile(ctx, newfile.File.ID)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put the object
|
// Put the object
|
||||||
|
|
Loading…
Reference in a new issue