mirror of
https://github.com/qjfoidnh/BaiduPCS-Go.git
synced 2026-06-04 09:54:22 +08:00
@@ -99,8 +99,8 @@ const (
|
||||
OperationGetRapidUploadInfo = "获取文件秒传信息"
|
||||
// OperationFixMD5 修复文件md5
|
||||
OperationFixMD5 = "修复文件md5"
|
||||
// OperrationMatchPathByShellPattern 通配符匹配文件路径
|
||||
OperrationMatchPathByShellPattern = "通配符匹配文件路径"
|
||||
// OperationMatchPathByShellPattern 通配符匹配文件路径
|
||||
OperationMatchPathByShellPattern = "通配符匹配文件路径"
|
||||
|
||||
// PCSBaiduCom pcs api地址
|
||||
PCSBaiduCom = "pcs.baidu.com"
|
||||
|
||||
@@ -357,7 +357,7 @@ func (pcs *BaiduPCS) recurseMatchPathByShellPattern(index int, patternSlice *[]s
|
||||
|
||||
// MatchPathByShellPattern 通配符匹配文件路径, pattern 为绝对路径
|
||||
func (pcs *BaiduPCS) MatchPathByShellPattern(pattern string) (pcspaths []string, pcsError pcserror.Error) {
|
||||
errInfo := pcserror.NewPCSErrorInfo(OperrationMatchPathByShellPattern)
|
||||
errInfo := pcserror.NewPCSErrorInfo(OperationMatchPathByShellPattern)
|
||||
errInfo.ErrType = pcserror.ErrTypeOthers
|
||||
|
||||
patternSlice := strings.Split(escaper.Escape(path.Clean(pattern), []rune{'['}), PathSeparator) // 转义中括号
|
||||
|
||||
@@ -53,21 +53,21 @@ const (
|
||||
)
|
||||
|
||||
// DecodePCSJSONError 解析PCS JSON的错误
|
||||
func DecodePCSJSONError(opreation string, data io.Reader) Error {
|
||||
errInfo := NewPCSErrorInfo(opreation)
|
||||
return HandleJSONParse(opreation, data, errInfo)
|
||||
func DecodePCSJSONError(operation string, data io.Reader) Error {
|
||||
errInfo := NewPCSErrorInfo(operation)
|
||||
return HandleJSONParse(operation, data, errInfo)
|
||||
}
|
||||
|
||||
// DecodePanJSONError 解析Pan JSON的错误
|
||||
func DecodePanJSONError(opreation string, data io.Reader) Error {
|
||||
errInfo := NewPanErrorInfo(opreation)
|
||||
return HandleJSONParse(opreation, data, errInfo)
|
||||
func DecodePanJSONError(operation string, data io.Reader) Error {
|
||||
errInfo := NewPanErrorInfo(operation)
|
||||
return HandleJSONParse(operation, data, errInfo)
|
||||
}
|
||||
|
||||
// DecodeXPanJSONError 解析XPan JSON的错误
|
||||
func DecodeXPanJSONError(opreation string, data io.Reader) Error {
|
||||
errInfo := NewXPanErrorInfo(opreation)
|
||||
return HandleJSONParse(opreation, data, errInfo)
|
||||
func DecodeXPanJSONError(operation string, data io.Reader) Error {
|
||||
errInfo := NewXPanErrorInfo(operation)
|
||||
return HandleJSONParse(operation, data, errInfo)
|
||||
}
|
||||
|
||||
// HandleJSONParse 处理解析json
|
||||
|
||||
@@ -34,12 +34,12 @@ func handleRespClose(resp *http.Response) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleRespStatusError(opreation string, resp *http.Response) pcserror.Error {
|
||||
//errInfo := pcserror.NewPCSErrorInfo(opreation)
|
||||
func handleRespStatusError(operation string, resp *http.Response) pcserror.Error {
|
||||
//errInfo := pcserror.NewPCSErrorInfo(operation)
|
||||
// http 响应错误处理
|
||||
switch resp.StatusCode / 100 {
|
||||
case 4, 5:
|
||||
errInfo := pcserror.DecodePCSJSONError(opreation, resp.Body)
|
||||
errInfo := pcserror.DecodePCSJSONError(operation, resp.Body)
|
||||
resp.Body.Close()
|
||||
errInfo.SetRemoteError()
|
||||
//errInfo.SetNetError(fmt.Errorf("http 响应错误, %s", resp.Status))
|
||||
@@ -138,7 +138,7 @@ func (pcs *BaiduPCS) PrepareFilesDirectoriesBatchMeta(paths ...string) (dataRead
|
||||
|
||||
// 表单上传
|
||||
mr := multipartreader.NewMultipartReader()
|
||||
mr.AddFormFeild("param", bytes.NewReader(sendData))
|
||||
mr.AddFormField("param", bytes.NewReader(sendData))
|
||||
mr.CloseMultipart()
|
||||
|
||||
dataReadCloser, pcsError = pcs.sendReqReturnReadCloser(reqTypePCS, OperationFilesDirectoriesMeta, http.MethodPost, pcsURL.String(), mr, nil)
|
||||
@@ -231,7 +231,7 @@ func (pcs *BaiduPCS) PrepareRemove(paths ...string) (dataReadCloser io.ReadClose
|
||||
|
||||
// 表单上传
|
||||
mr := multipartreader.NewMultipartReader()
|
||||
mr.AddFormFeild("param", bytes.NewReader(sendData))
|
||||
mr.AddFormField("param", bytes.NewReader(sendData))
|
||||
mr.CloseMultipart()
|
||||
|
||||
dataReadCloser, pcsError = pcs.sendReqReturnReadCloser(reqTypePCS, OperationRemove, http.MethodPost, pcsURL.String(), mr, nil)
|
||||
@@ -259,7 +259,7 @@ func (pcs *BaiduPCS) prepareCpMvOp(op string, cpmvJSON ...*CpMvJSON) (dataReadCl
|
||||
case OperationMove, OperationRename:
|
||||
method = "move"
|
||||
default:
|
||||
panic("Unknown opreation: " + op)
|
||||
panic("Unknown operation: " + op)
|
||||
}
|
||||
|
||||
sendData, err := (&CpMvListJSON{
|
||||
@@ -275,7 +275,7 @@ func (pcs *BaiduPCS) prepareCpMvOp(op string, cpmvJSON ...*CpMvJSON) (dataReadCl
|
||||
|
||||
// 表单上传
|
||||
mr := multipartreader.NewMultipartReader()
|
||||
mr.AddFormFeild("param", bytes.NewReader(sendData))
|
||||
mr.AddFormField("param", bytes.NewReader(sendData))
|
||||
mr.CloseMultipart()
|
||||
|
||||
dataReadCloser, pcsError = pcs.sendReqReturnReadCloser(reqTypePCS, op, http.MethodPost, pcsURL.String(), mr, nil)
|
||||
@@ -534,7 +534,7 @@ func (pcs *BaiduPCS) PrepareUploadCreateSuperFile(policy string, checkDir bool,
|
||||
|
||||
// 表单上传
|
||||
mr := multipartreader.NewMultipartReader()
|
||||
mr.AddFormFeild("param", bytes.NewReader(sendData))
|
||||
mr.AddFormField("param", bytes.NewReader(sendData))
|
||||
mr.CloseMultipart()
|
||||
|
||||
dataReadCloser, pcsError = pcs.sendReqReturnReadCloser(reqTypePCS, OperationUploadCreateSuperFile, http.MethodPost, pcsURL.String(), mr, nil)
|
||||
@@ -644,15 +644,15 @@ func (pcs *BaiduPCS) PrepareCloudDlListTask() (dataReadCloser io.ReadCloser, pcs
|
||||
return
|
||||
}
|
||||
|
||||
func (pcs *BaiduPCS) prepareCloudDlCDTask(opreation, method string, taskID int64) (dataReadCloser io.ReadCloser, pcsError pcserror.Error) {
|
||||
func (pcs *BaiduPCS) prepareCloudDlCDTask(operation, method string, taskID int64) (dataReadCloser io.ReadCloser, pcsError pcserror.Error) {
|
||||
pcs.lazyInit()
|
||||
pcsURL2 := pcs.generatePCSURL2("services/cloud_dl", method, map[string]string{
|
||||
"app_id": PanAppID,
|
||||
"task_id": strconv.FormatInt(taskID, 10),
|
||||
})
|
||||
baiduPCSVerbose.Infof("%s URL: %s\n", opreation, pcsURL2)
|
||||
baiduPCSVerbose.Infof("%s URL: %s\n", operation, pcsURL2)
|
||||
|
||||
dataReadCloser, pcsError = pcs.sendReqReturnReadCloser(reqTypePCS, opreation, http.MethodPost, pcsURL2.String(), nil, nil)
|
||||
dataReadCloser, pcsError = pcs.sendReqReturnReadCloser(reqTypePCS, operation, http.MethodPost, pcsURL2.String(), nil, nil)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -799,7 +799,7 @@ func (pcs *BaiduPCS) PrepareRecycleRestore(fidList ...int64) (dataReadCloser io.
|
||||
|
||||
// 表单上传
|
||||
mr := multipartreader.NewMultipartReader()
|
||||
mr.AddFormFeild("param", bytes.NewReader(sendData))
|
||||
mr.AddFormField("param", bytes.NewReader(sendData))
|
||||
mr.CloseMultipart()
|
||||
|
||||
dataReadCloser, pcsError = pcs.sendReqReturnReadCloser(reqTypePCS, OperationRecycleRestore, http.MethodPost, pcsURL.String(), mr, nil)
|
||||
|
||||
@@ -42,8 +42,8 @@
|
||||
| 403 | 31110 | access denied to set quota | 未授权设置此目录配额 |
|
||||
| 400 | 31111 | quota only sopport 2 level directories | 配额管理只支持两级目录 |
|
||||
| 400 | 31112 | exceed quota | 超出配额 |
|
||||
| 403 | 31113 | the quota is bigger than one of its parent directorys | 配额不能超出目录祖先的配额 |
|
||||
| 403 | 31114 | the quota is smaller than one of its sub directorys | 配额不能比子目录配额小 |
|
||||
| 403 | 31113 | the quota is bigger than one of its parent directories | 配额不能超出目录祖先的配额 |
|
||||
| 403 | 31114 | the quota is smaller than one of its sub directories | 配额不能比子目录配额小 |
|
||||
| 503 | 31141 | thumbnail failed, internal error | 请求缩略图服务失败 |
|
||||
| 401 | 110 | Access token invalid or no longer valid | Access Token不正确或者已经过期 |
|
||||
| 400 | 31201 | signature error | 签名错误 |
|
||||
|
||||
@@ -64,10 +64,10 @@
|
||||
| 400 | 31451 | quota size param not exist | 找不到参数quota size | 否 |
|
||||
| 503 | 31452 | quota info fail | quota info失败 | 是 |
|
||||
| 400 | 31453 | quota too big | quota过大 | 否 |
|
||||
| 400 | 31454 | quota size param not numberic | quota size 参数未数值化 | 否 |
|
||||
| 400 | 31454 | quota size param not numeric | quota size 参数未数值化 | 否 |
|
||||
| 400 | 31460 | no permission | 未授权 | 否 |
|
||||
| 400 | 31461 | account not login | 账户为登录,使用bduss认证失败 | 否 |
|
||||
| 400 | 31462 | access token errro | access token校验失败 | 否 |
|
||||
| 400 | 31462 | access token error | access token校验失败 | 否 |
|
||||
| 400 | 31470 | index num too much | index num太多 | 否 |
|
||||
| 400 | 31472 | table already exist | table已存在 | 否 |
|
||||
| 400 | 31473 | abnormal table already exist | 异常table已存在 | 否 |
|
||||
|
||||
@@ -25,9 +25,9 @@ func runCpMvOp(op string, paths ...string) {
|
||||
return
|
||||
}
|
||||
|
||||
froms, to := cpmvParsePath(paths...) // 分割
|
||||
from, to := cpmvParsePath(paths...) // 分割
|
||||
|
||||
froms, err = matchPathByShellPattern(froms...)
|
||||
from, err = matchPathByShellPattern(from...)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
@@ -58,35 +58,35 @@ func runCpMvOp(op string, paths ...string) {
|
||||
// 判断路径是否存在
|
||||
// 如果不存在, 则为重命名或同目录拷贝操作
|
||||
|
||||
// 如果 froms 数不是1, 则意义不明确.
|
||||
if len(froms) != 1 {
|
||||
// 如果 from 数不是1, 则意义不明确.
|
||||
if len(from) != 1 {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
if op == "copy" { // 拷贝
|
||||
err = pcs.Copy(&baidupcs.CpMvJSON{
|
||||
From: froms[0],
|
||||
From: from[0],
|
||||
To: to,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
fmt.Println("文件/目录拷贝失败: ")
|
||||
fmt.Printf("%s <-> %s\n", froms[0], to)
|
||||
fmt.Printf("%s <-> %s\n", from[0], to)
|
||||
return
|
||||
}
|
||||
fmt.Println("文件/目录拷贝成功: ")
|
||||
fmt.Printf("%s <-> %s\n", froms[0], to)
|
||||
fmt.Printf("%s <-> %s\n", from[0], to)
|
||||
} else { // 重命名
|
||||
err = pcs.Rename(froms[0], path.Clean(to))
|
||||
err = pcs.Rename(from[0], path.Clean(to))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
fmt.Println("重命名失败: ")
|
||||
fmt.Printf("%s -> %s\n", froms[0], to)
|
||||
fmt.Printf("%s -> %s\n", from[0], to)
|
||||
return
|
||||
}
|
||||
fmt.Println("重命名成功: ")
|
||||
fmt.Printf("%s -> %s\n", froms[0], to)
|
||||
fmt.Printf("%s -> %s\n", from[0], to)
|
||||
}
|
||||
return
|
||||
case pcsError != nil && pcsError.GetErrType() != pcserror.ErrTypeRemoteError:
|
||||
@@ -100,11 +100,11 @@ func runCpMvOp(op string, paths ...string) {
|
||||
}
|
||||
|
||||
cj := new(baidupcs.CpMvListJSON)
|
||||
cj.List = make([]*baidupcs.CpMvJSON, len(froms))
|
||||
for k := range froms {
|
||||
cj.List = make([]*baidupcs.CpMvJSON, len(from))
|
||||
for k := range from {
|
||||
cj.List[k] = &baidupcs.CpMvJSON{
|
||||
From: froms[k],
|
||||
To: path.Clean(to + baidupcs.PathSeparator + path.Base(froms[k])),
|
||||
From: from[k],
|
||||
To: path.Clean(to + baidupcs.PathSeparator + path.Base(from[k])),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,11 +145,11 @@ func cpmvPathValid(paths ...string) (err error) {
|
||||
}
|
||||
|
||||
// cpmvParsePath 解析路径
|
||||
func cpmvParsePath(paths ...string) (froms []string, to string) {
|
||||
func cpmvParsePath(paths ...string) (from []string, to string) {
|
||||
if len(paths) == 0 {
|
||||
return nil, ""
|
||||
}
|
||||
froms = paths[:len(paths)-1]
|
||||
from = paths[:len(paths)-1]
|
||||
to = paths[len(paths)-1]
|
||||
return
|
||||
}
|
||||
|
||||
@@ -7,9 +7,9 @@ import (
|
||||
)
|
||||
|
||||
func TestTrimPathInvalidChars(t *testing.T) {
|
||||
trimed := converter.TrimPathInvalidChars("ksjadfi*/?adf")
|
||||
if strings.Compare(trimed, "ksjadfiadf") != 0 {
|
||||
t.Fatalf("trimed: %s\n", trimed)
|
||||
trimmed := converter.TrimPathInvalidChars("ksjadfi*/?adf")
|
||||
if strings.Compare(trimmed, "ksjadfiadf") != 0 {
|
||||
t.Fatalf("trimmed: %s\n", trimmed)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ func (mt *Monitor) registerAllCompleted() {
|
||||
mt.err = worker.Err()
|
||||
close(mt.completed)
|
||||
return
|
||||
case StatusCodeSuccessed, StatusCodeCanceled:
|
||||
case StatusCodeSucceeded, StatusCodeCanceled:
|
||||
completeNum++
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ type (
|
||||
const (
|
||||
//StatusCodeInit 初始化
|
||||
StatusCodeInit StatusCode = iota
|
||||
//StatusCodeSuccessed 成功
|
||||
StatusCodeSuccessed
|
||||
//StatusCodeSucceeded 成功
|
||||
StatusCodeSucceeded
|
||||
//StatusCodePending 等待响应
|
||||
StatusCodePending
|
||||
//StatusCodeDownloading 下载中
|
||||
@@ -55,7 +55,7 @@ func GetStatusText(sc StatusCode) string {
|
||||
switch sc {
|
||||
case StatusCodeInit:
|
||||
return "初始化"
|
||||
case StatusCodeSuccessed:
|
||||
case StatusCodeSucceeded:
|
||||
return "成功"
|
||||
case StatusCodePending:
|
||||
return "等待响应"
|
||||
|
||||
@@ -197,7 +197,7 @@ func (wer *Worker) Canceled() bool {
|
||||
//Completed 是否已经完成
|
||||
func (wer *Worker) Completed() bool {
|
||||
switch wer.status.statusCode {
|
||||
case StatusCodeSuccessed, StatusCodeCanceled:
|
||||
case StatusCodeSucceeded, StatusCodeCanceled:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
@@ -245,7 +245,7 @@ func (wer *Worker) Execute() {
|
||||
if rlen < 0 {
|
||||
pcsverbose.Verbosef("DEBUG: RangeLen is negative at begin: %v, %d\n", wer.wrange, wer.wrange.Len())
|
||||
}
|
||||
wer.status.statusCode = StatusCodeSuccessed
|
||||
wer.status.statusCode = StatusCodeSucceeded
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -440,7 +440,7 @@ func (wer *Worker) Execute() {
|
||||
case rlen <= 0:
|
||||
// 下载完成
|
||||
// 小于0可能是因为 worker 被 duplicate
|
||||
wer.status.statusCode = StatusCodeSuccessed
|
||||
wer.status.statusCode = StatusCodeSucceeded
|
||||
if rlen < 0 {
|
||||
pcsverbose.Verbosef("DEBUG: RangeLen is negative at end: %v, %d\n", wer.wrange, wer.wrange.Len())
|
||||
}
|
||||
|
||||
@@ -55,8 +55,8 @@ func NewMultipartReader() (mr *MultipartReader) {
|
||||
return
|
||||
}
|
||||
|
||||
// AddFormFeild 增加 form 表单
|
||||
func (mr *MultipartReader) AddFormFeild(fieldname string, readerlen rio.ReaderLen) {
|
||||
// AddFormField 增加 form 表单
|
||||
func (mr *MultipartReader) AddFormField(fieldname string, readerlen rio.ReaderLen) {
|
||||
if readerlen == nil {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user