mirror of
https://gitee.com/zhangsken/aliyunpan.git
synced 2026-10-16 10:29:42 +08:00
support pulic and private aliyun ECS url for webdav file download and upload
This commit is contained in:
@@ -21,7 +21,6 @@ import (
|
||||
)
|
||||
|
||||
type FileDownloadStream struct {
|
||||
fileUrl string
|
||||
readOffset int64
|
||||
resp *http.Response
|
||||
timestamp int64
|
||||
@@ -48,6 +47,7 @@ type FileUploadStream struct {
|
||||
type PanClientProxy struct {
|
||||
PanUser *config.PanUser
|
||||
PanDriveId string
|
||||
PanTransferUrlType int
|
||||
|
||||
mutex sync.Mutex
|
||||
|
||||
@@ -85,6 +85,26 @@ func formatPathStyle(pathStr string) string {
|
||||
return pathStr
|
||||
}
|
||||
|
||||
// getDownloadFileUrl 获取文件下载URL
|
||||
func (p *PanClientProxy) getFileDownloadUrl(urlResult *aliyunpan.GetFileDownloadUrlResult) string {
|
||||
if urlResult == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
if p.PanTransferUrlType == 2 { // 阿里ECS内网链接
|
||||
return urlResult.InternalUrl
|
||||
}
|
||||
return urlResult.Url
|
||||
}
|
||||
|
||||
// getFileUploadUrl 获取文件上传URL
|
||||
func (p *PanClientProxy) getFileUploadUrl(urlResult aliyunpan.FileUploadPartInfoResult) string {
|
||||
if p.PanTransferUrlType == 2 { // 阿里ECS内网链接
|
||||
return urlResult.InternalUploadURL
|
||||
}
|
||||
return urlResult.UploadURL
|
||||
}
|
||||
|
||||
// DeleteCache 删除含有 dirs 的缓存
|
||||
func (p *PanClientProxy) deleteFilesDirectoriesListCache(dirs []string) {
|
||||
cache := p.fileDirectoryListCacheMap.LazyInitCachePoolOp(p.PanDriveId)
|
||||
@@ -232,7 +252,7 @@ func (p *PanClientProxy) cacheFileDownloadStream(sessionId, fileId string, offse
|
||||
// set to no timeout
|
||||
client.Timeout = 0
|
||||
apierr := p.PanUser.PanClient().DownloadFileData(
|
||||
urlResult.Url,
|
||||
p.getFileDownloadUrl(urlResult),
|
||||
aliyunpan.FileDownloadRange{
|
||||
Offset: offset,
|
||||
End: 0,
|
||||
@@ -660,7 +680,7 @@ func (p *PanClientProxy) UploadFilePart(userId, pathStr string, offset int64, bu
|
||||
Reader: uploadChunk,
|
||||
ChunkSize: uploadChunk.Size(),
|
||||
}
|
||||
e := p.PanUser.PanClient().UploadDataChunk(uploadPartInfo.UploadURL, cd)
|
||||
e := p.PanUser.PanClient().UploadDataChunk(p.getFileUploadUrl(uploadPartInfo), cd)
|
||||
if e != nil {
|
||||
// upload error
|
||||
// TODO: handle error, retry upload
|
||||
|
||||
@@ -22,7 +22,8 @@ type WebdavConfig struct {
|
||||
PanUserId string `json:"panUserId"`
|
||||
PanDriveId string `json:"panDriveId"`
|
||||
PanUser *config.PanUser `json:"-"`
|
||||
UploadChunkSize int `json:"uploadChunkSize"`
|
||||
UploadChunkSize int `json:"uploadChunkSize"` // 上传文件分片数据块大小,该数值不能太小,建议大于等于512KB
|
||||
TransferUrlType int `json:"transferUrlType"` // 上传/下载URL类别,1-默认,2-阿里云ECS
|
||||
|
||||
Address string `json:"address"`
|
||||
Port int `json:"port"`
|
||||
@@ -56,6 +57,7 @@ func (w *WebdavConfig) StartServer() {
|
||||
panClientProxy: &PanClientProxy{
|
||||
PanUser: w.PanUser,
|
||||
PanDriveId: w.PanDriveId,
|
||||
PanTransferUrlType: w.TransferUrlType,
|
||||
},
|
||||
fileInfo: wdfi,
|
||||
uploadChunkSize: w.UploadChunkSize,
|
||||
|
||||
Reference in New Issue
Block a user