panupload

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2022 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Overview

Copyright (c) 2020 tickstep & chenall

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2020 tickstep & chenall

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2020 tickstep.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2020 tickstep & chenall

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2020 tickstep.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2020 tickstep.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2020 tickstep.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	// MaxUploadBlockSize 最大上传的文件分片大小
	MaxUploadBlockSize = 2 * converter.GB
	// MinUploadBlockSize 最小的上传的文件分片大小
	MinUploadBlockSize = 4 * converter.MB
	// MaxRapidUploadSize 秒传文件支持的最大文件大小
	MaxRapidUploadSize = 20 * converter.GB

	UploadingFileName = "aliyunpan_uploading.json"
)
View Source
const (
	StrUploadFailed = "上传文件失败"
)

Variables

View Source
var ResultLocalFileNotUpdated = &taskframework.TaskUnitRunResult{ResultCode: 1, Succeed: true, ResultMessage: "本地文件未更新,无需上传!"}
View Source
var ResultUpdateLocalDatabase = &taskframework.TaskUnitRunResult{ResultCode: 2, Succeed: true, ResultMessage: "本地文件和云端文件MD5一致,无需上传!"}

Functions

func NewPanUpload

func NewPanUpload(panClient *aliyunpan.PanClient, targetPath, driveId string, uploadOpEntity *aliyunpan.CreateFileUploadResult, useInternalUrl bool) uploader.MultiUpload

Types

type EmptyReaderLen64

type EmptyReaderLen64 struct {
}

func (EmptyReaderLen64) Len

func (e EmptyReaderLen64) Len() int64

func (EmptyReaderLen64) Read

func (e EmptyReaderLen64) Read(p []byte) (n int, err error)

type PanUpload

type PanUpload struct {
	// contains filtered or unexported fields
}

func (*PanUpload) CommitFile

func (pu *PanUpload) CommitFile() (cerr error)

func (*PanUpload) Precreate

func (pu *PanUpload) Precreate() (err error)

func (*PanUpload) UploadFile

func (pu *PanUpload) UploadFile(ctx context.Context, partseq int, partOffset int64, partEnd int64, r rio.ReaderLen64, uploadClient *requester.HTTPClient) (uploadDone bool, uperr error)

type StepUpload

type StepUpload int

StepUpload 上传步骤

const (
	// StepUploadInit 初始化步骤
	StepUploadInit StepUpload = iota
	// 上传前准备,创建上传任务
	StepUploadPrepareUpload
	// StepUploadRapidUpload 秒传步骤
	StepUploadRapidUpload
	// StepUploadUpload 正常上传步骤
	StepUploadUpload
)

type SyncDb

type SyncDb interface {
	//读取记录,返回值不会是nil
	Get(key string) (ufm *UploadedFileMeta)
	//删除单条记录
	Del(key string) error
	//根据前辍删除数据库记录,比如删除一个目录时可以连同子目录一起删除
	DelWithPrefix(prefix string) error
	Put(key string, value *UploadedFileMeta) error
	Close() error
	//读取数据库指定路径前辍的第一条记录(也作为循环获取的初始化,配置Next函数使用)
	First(prefix string) (*UploadedFileMeta, error)
	//获取指定路径前辍的的下一条记录
	Next(prefix string) (*UploadedFileMeta, error)
	//是否进行自动数据库清理
	//注: 清理规则,所有以 prefix 前辍开头并且未更新的记录都将被清理,只有在必要的时候才开启这个功能。
	AutoClean(prefix string, cleanFlag bool)
}

func OpenSyncDb

func OpenSyncDb(file string, bucket string) (SyncDb, error)

type UploadStatistic

type UploadStatistic struct {
	functions.Statistic
}

type UploadTaskUnit

type UploadTaskUnit struct {
	LocalFileChecksum *localfile.LocalFileEntity // 要上传的本地文件详情
	Step              StepUpload
	SavePath          string // 保存路径
	DriveId           string // 网盘ID,例如:文件网盘,相册网盘
	FolderCreateMutex *sync.Mutex
	FolderSyncDb      SyncDb //文件备份状态数据库

	PanClient         *aliyunpan.PanClient
	UploadingDatabase *UploadingDatabase // 数据库
	Parallel          int
	NoRapidUpload     bool  // 禁用秒传,无需计算SHA1,直接上传
	BlockSize         int64 // 分片大小

	UploadStatistic *UploadStatistic

	ShowProgress bool
	IsOverwrite  bool // 覆盖已存在的文件,如果同名文件已存在则移到回收站里

	// 是否使用内置链接
	UseInternalUrl bool

	// 全局速度统计
	GlobalSpeedsStat *speeds.Speeds
	// contains filtered or unexported fields
}

UploadTaskUnit 上传的任务单元

func (*UploadTaskUnit) OnCancel added in v0.1.4

func (utu *UploadTaskUnit) OnCancel(lastRunResult *taskframework.TaskUnitRunResult)

func (*UploadTaskUnit) OnComplete

func (utu *UploadTaskUnit) OnComplete(lastRunResult *taskframework.TaskUnitRunResult)

func (*UploadTaskUnit) OnFailed

func (utu *UploadTaskUnit) OnFailed(lastRunResult *taskframework.TaskUnitRunResult)

func (*UploadTaskUnit) OnRetry

func (utu *UploadTaskUnit) OnRetry(lastRunResult *taskframework.TaskUnitRunResult)

func (*UploadTaskUnit) OnSuccess

func (utu *UploadTaskUnit) OnSuccess(lastRunResult *taskframework.TaskUnitRunResult)

func (*UploadTaskUnit) RetryWait

func (utu *UploadTaskUnit) RetryWait() time.Duration

func (*UploadTaskUnit) Run

func (utu *UploadTaskUnit) Run() (result *taskframework.TaskUnitRunResult)

func (*UploadTaskUnit) SetTaskInfo

func (utu *UploadTaskUnit) SetTaskInfo(taskInfo *taskframework.TaskInfo)

type UploadedFileMeta

type UploadedFileMeta struct {
	IsFolder     bool   `json:"isFolder,omitempty"` // 是否目录
	Path         string `json:"-"`                  // 本地路径,不记录到数据库
	SHA1         string `json:"sha1,omitempty"`     // 文件的 SHA1
	FileId       string `json:"id,omitempty"`       //文件、目录ID
	ParentId     string `json:"parentId,omitempty"` //父文件夹ID
	Size         int64  `json:"length,omitempty"`   // 文件大小
	ModTime      int64  `json:"modtime,omitempty"`  // 修改日期
	LastSyncTime int64  `json:"synctime,omitempty"` //最后同步时间
}

type Uploading

type Uploading struct {
	*localfile.LocalFileMeta
	State *uploader.InstanceState `json:"state"`
}

Uploading 未完成上传的信息

type UploadingDatabase

type UploadingDatabase struct {
	UploadingList []*Uploading `json:"upload_state"`
	Timestamp     int64        `json:"timestamp"`
	// contains filtered or unexported fields
}

UploadingDatabase 未完成上传的数据库

func NewUploadingDatabase

func NewUploadingDatabase() (ud *UploadingDatabase, err error)

NewUploadingDatabase 初始化未完成上传的数据库, 从库中读取内容

func (*UploadingDatabase) Close

func (ud *UploadingDatabase) Close() error

Close 关闭数据库

func (*UploadingDatabase) Delete

func (ud *UploadingDatabase) Delete(meta *localfile.LocalFileMeta) bool

Delete 删除

func (*UploadingDatabase) Save

func (ud *UploadingDatabase) Save() error

Save 保存内容

func (*UploadingDatabase) Search

Search 搜索

func (*UploadingDatabase) UpdateUploading

func (ud *UploadingDatabase) UpdateUploading(meta *localfile.LocalFileMeta, state *uploader.InstanceState)

UpdateUploading 更新正在上传

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL