mirror of
https://github.com/tickstep/aliyunpan.git
synced 2025-01-23 14:32:14 +08:00
support use the internal download upload url for aliyun ECS
This commit is contained in:
parent
25b51dd763
commit
a28ed463e7
@ -217,6 +217,10 @@ func CmdConfig() cli.Command {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if c.IsSet("transfer_url_type") {
|
||||
config.Config.TransferUrlType = c.Int("transfer_url_type")
|
||||
}
|
||||
|
||||
if c.IsSet("savedir") {
|
||||
config.Config.SaveDir = c.String("savedir")
|
||||
}
|
||||
@ -263,6 +267,11 @@ func CmdConfig() cli.Command {
|
||||
Name: "max_upload_rate",
|
||||
Usage: "限制最大上传速度, 0代表不限制",
|
||||
},
|
||||
cli.IntFlag{
|
||||
Name: "transfer_url_type",
|
||||
Usage: "上传下载URL类别,1-默认,2-阿里云ECS",
|
||||
Value: 1,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "savedir",
|
||||
Usage: "下载文件的储存目录",
|
||||
|
@ -44,6 +44,7 @@ type (
|
||||
NoCheck bool
|
||||
ShowProgress bool
|
||||
DriveId string
|
||||
UseInternalUrl bool // 是否使用内置链接
|
||||
}
|
||||
|
||||
// LocateDownloadOption 获取下载链接可选参数
|
||||
@ -208,6 +209,7 @@ func RunDownload(paths []string, options *DownloadOptions) {
|
||||
MaxRate: config.Config.MaxDownloadRate,
|
||||
InstanceStateStorageFormat: downloader.InstanceStateStorageFormatJSON,
|
||||
ShowProgress: options.ShowProgress,
|
||||
UseInternalUrl: config.Config.TransferUrlType == 2,
|
||||
}
|
||||
if cfg.CacheSize == 0 {
|
||||
cfg.CacheSize = int(DownloadCacheSize)
|
||||
|
@ -62,6 +62,7 @@ type (
|
||||
DriveId string
|
||||
ExcludeNames []string // 排除的文件名,包括文件夹和文件。即这些文件/文件夹不进行上传,支持正则表达式
|
||||
BlockSize int64 // 分片大小
|
||||
UseInternalUrl bool // 是否使用内置链接
|
||||
}
|
||||
)
|
||||
|
||||
@ -259,10 +260,10 @@ func RunUpload(localPaths []string, savePath string, opt *UploadOptions) {
|
||||
if opt.Parallel <= 0 {
|
||||
opt.Parallel = 1
|
||||
}
|
||||
|
||||
if opt.MaxRetry < 0 {
|
||||
opt.MaxRetry = DefaultUploadMaxRetry
|
||||
}
|
||||
opt.UseInternalUrl = config.Config.TransferUrlType == 2
|
||||
|
||||
savePath = activeUser.PathJoin(opt.DriveId, savePath)
|
||||
_, err1 := activeUser.PanClient().FileInfoByPath(opt.DriveId, savePath)
|
||||
@ -409,6 +410,7 @@ func RunUpload(localPaths []string, savePath string, opt *UploadOptions) {
|
||||
ShowProgress: opt.ShowProgress,
|
||||
IsOverwrite: opt.IsOverwrite,
|
||||
FolderSyncDb: db,
|
||||
UseInternalUrl: opt.UseInternalUrl,
|
||||
}, opt.MaxRetry)
|
||||
|
||||
fmt.Printf("%s [%s] 加入上传队列: %s\n", time.Now().Format("2006-01-02 15:04:05"), taskinfo.Id(), file)
|
||||
|
@ -69,6 +69,7 @@ type PanConfig struct {
|
||||
|
||||
MaxDownloadRate int64 `json:"maxDownloadRate"` // 限制最大下载速度,单位 B/s, 即字节/每秒
|
||||
MaxUploadRate int64 `json:"maxUploadRate"` // 限制最大上传速度,单位 B/s, 即字节/每秒
|
||||
TransferUrlType int `json:"transferUrlType"` // 上传/下载URL类别,1-默认,2-阿里云ECS
|
||||
|
||||
SaveDir string `json:"saveDir"` // 下载储存路径
|
||||
|
||||
|
@ -79,6 +79,7 @@ func (c *PanConfig) PrintTable() {
|
||||
[]string{"max_download_load", strconv.Itoa(c.MaxDownloadLoad), "1 ~ 5", "同时进行下载文件的最大数量"},
|
||||
[]string{"max_download_rate", showMaxRate(c.MaxDownloadRate), "", "限制最大下载速度, 0代表不限制"},
|
||||
[]string{"max_upload_rate", showMaxRate(c.MaxUploadRate), "", "限制最大上传速度, 0代表不限制"},
|
||||
[]string{"transfer_url_type", strconv.Itoa(c.TransferUrlType), "1-默认,2-阿里云ECS", "上传下载URL类别。除非在阿里云ECS服务器中使用,不然请设置1"},
|
||||
[]string{"savedir", c.SaveDir, "", "下载文件的储存目录"},
|
||||
[]string{"proxy", c.Proxy, "", "设置代理, 支持 http/socks5 代理,例如:http://127.0.0.1:8888"},
|
||||
[]string{"local_addrs", c.LocalAddrs, "", "设置本地网卡地址, 多个地址用逗号隔开"},
|
||||
|
@ -38,6 +38,7 @@ type Config struct {
|
||||
InstanceStatePath string // 断点续传信息路径
|
||||
TryHTTP bool // 是否尝试使用 http 连接
|
||||
ShowProgress bool // 是否展示下载进度条
|
||||
UseInternalUrl bool // 是否使用内置链接
|
||||
}
|
||||
|
||||
//NewConfig 返回默认配置
|
||||
|
@ -389,7 +389,11 @@ func (der *Downloader) Execute() error {
|
||||
client.SetKeepAlive(true)
|
||||
client.SetTimeout(10 * time.Minute)
|
||||
|
||||
worker := NewWorker(k, der.driveId, der.fileInfo.FileId, durl.Url, writer)
|
||||
realUrl := durl.Url
|
||||
if der.config.UseInternalUrl {
|
||||
realUrl = durl.InternalUrl
|
||||
}
|
||||
worker := NewWorker(k, der.driveId, der.fileInfo.FileId, realUrl, writer)
|
||||
worker.SetClient(client)
|
||||
worker.SetPanClient(der.panClient)
|
||||
worker.SetWriteMutex(writeMu)
|
||||
|
@ -37,6 +37,7 @@ type (
|
||||
|
||||
// 网盘上传参数
|
||||
uploadOpEntity *aliyunpan.CreateFileUploadResult
|
||||
useInternalUrl bool
|
||||
}
|
||||
|
||||
UploadedFileMeta struct {
|
||||
@ -69,12 +70,13 @@ func (e EmptyReaderLen64) Len() int64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func NewPanUpload(panClient *aliyunpan.PanClient, targetPath, driveId string, uploadOpEntity *aliyunpan.CreateFileUploadResult) uploader.MultiUpload {
|
||||
func NewPanUpload(panClient *aliyunpan.PanClient, targetPath, driveId string, uploadOpEntity *aliyunpan.CreateFileUploadResult, useInternalUrl bool) uploader.MultiUpload {
|
||||
return &PanUpload{
|
||||
panClient: panClient,
|
||||
targetPath: targetPath,
|
||||
driveId: driveId,
|
||||
uploadOpEntity: uploadOpEntity,
|
||||
useInternalUrl: useInternalUrl,
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,7 +156,11 @@ func (pu *PanUpload) UploadFile(ctx context.Context, partseq int, partOffset int
|
||||
}
|
||||
|
||||
// 上传一个分片数据
|
||||
apiError := pu.panClient.UploadFileData(pu.uploadOpEntity.PartInfoList[partseq].UploadURL, uploadFunc)
|
||||
uploadUrl := pu.uploadOpEntity.PartInfoList[partseq].UploadURL
|
||||
if pu.useInternalUrl {
|
||||
uploadUrl = pu.uploadOpEntity.PartInfoList[partseq].InternalUploadURL
|
||||
}
|
||||
apiError := pu.panClient.UploadFileData(uploadUrl, uploadFunc)
|
||||
|
||||
if respErr != nil {
|
||||
if respErr.Err == uploadUrlExpired {
|
||||
@ -173,7 +179,11 @@ func (pu *PanUpload) UploadFile(ctx context.Context, partseq int, partOffset int
|
||||
|
||||
// 获取新的上传URL重试一次
|
||||
pu.uploadOpEntity.PartInfoList[partseq] = guur.PartInfoList[0]
|
||||
apiError = pu.panClient.UploadFileData(pu.uploadOpEntity.PartInfoList[partseq].UploadURL, uploadFunc)
|
||||
uploadUrl := pu.uploadOpEntity.PartInfoList[partseq].UploadURL
|
||||
if pu.useInternalUrl {
|
||||
uploadUrl = pu.uploadOpEntity.PartInfoList[partseq].InternalUploadURL
|
||||
}
|
||||
apiError = pu.panClient.UploadFileData(uploadUrl, uploadFunc)
|
||||
} else if respErr.Err == uploadPartAlreadyExist {
|
||||
// already upload
|
||||
// success
|
||||
|
@ -64,6 +64,9 @@ type (
|
||||
|
||||
ShowProgress bool
|
||||
IsOverwrite bool // 覆盖已存在的文件,如果同名文件已存在则移到回收站里
|
||||
|
||||
// 是否使用内置链接
|
||||
UseInternalUrl bool
|
||||
}
|
||||
)
|
||||
|
||||
@ -147,7 +150,7 @@ func (utu *UploadTaskUnit) upload() (result *taskframework.TaskUnitRunResult) {
|
||||
// 阿里云盘默认就是分片上传,每一个分片对应一个part_info
|
||||
// 但是不支持分片同时上传,必须单线程,并且按照顺序从1开始一个一个上传
|
||||
muer := uploader.NewMultiUploader(
|
||||
NewPanUpload(utu.PanClient, utu.SavePath, utu.DriveId, utu.LocalFileChecksum.UploadOpEntity),
|
||||
NewPanUpload(utu.PanClient, utu.SavePath, utu.DriveId, utu.LocalFileChecksum.UploadOpEntity, utu.UseInternalUrl),
|
||||
rio.NewFileReaderAtLen64(utu.LocalFileChecksum.GetFile()), &uploader.MultiUploaderConfig{
|
||||
Parallel: utu.Parallel,
|
||||
BlockSize: utu.BlockSize,
|
||||
|
Loading…
Reference in New Issue
Block a user