diff --git a/CHANGELOG.md b/CHANGELOG.md index e2a7966..3349736 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,23 +1,34 @@ # 189Cloud-Downloader + 一个189云盘的下载器。(支持分享链接下载、支持Windows、Linux、macOS)Based Go. +## v0.2.1 + +1. 修复一些问题。 + ## v0.2.0 + 1. 天翼云API大改,对客户端进行修复。 ## v0.1.4 + 1. 修复单文件分享时找不到shareId的问题。 2. 修复在个别情况下载文件损坏的问题。 ## v0.1.3 + 1. fix `get` current not found. ## v0.1.2 + 1. Support loading share link with access code. ## v0.1.1 + 1. Support keyboard operation in Bash. 2. Support to cancel download via ctrl+c. 3. Now, You can print application version. ## v0.1.0 -1. init. \ No newline at end of file + +1. init. diff --git a/action.go b/action.go index f31a5cd..8d30905 100644 --- a/action.go +++ b/action.go @@ -104,7 +104,7 @@ func shareAction(ctx *cli.Context) (err error) { printcolor.Red("%v\n", err) return } - current = &model.Dir{ID: share.FileID, Name: share.FileName} + current = &model.Dir{ID: share.FileID, Name: share.FileName, IsFolder: share.IsFolder} dirs[current.GetID()] = current return } diff --git a/dao/home.go b/dao/home.go index 6f68067..3dfac16 100644 --- a/dao/home.go +++ b/dao/home.go @@ -91,7 +91,7 @@ func (d *dao) GetHomeDirAll(ctx context.Context, fileID ...string) (dirs []*mode return } dirs = append(dirs, dirs2...) - if len(dirs2) <= 100 { + if len(dirs2) < 100 { return } } diff --git a/dao/share.go b/dao/share.go index 23c7271..c2895ec 100644 --- a/dao/share.go +++ b/dao/share.go @@ -92,7 +92,7 @@ func (d *dao) GetShareDirAll(ctx context.Context, share *model.ShareInfo, fileID return } dirs = append(dirs, dirs2...) - if len(dirs2) <= 100 { + if len(dirs2) < 100 { return } } @@ -123,6 +123,7 @@ func (d *dao) GetShareInfo(ctx context.Context, shareCode, accessCode string) (i ResCode int `json:"res_code"` ResMsg string `json:"res_message"` FileId string `json:"fileId"` + ShareId int64 `json:"shareId"` FileName string `json:"fileName"` IsFolder bool `json:"isFolder"` NeedAccessCode int8 `json:"needAccessCode"` @@ -137,42 +138,45 @@ func (d *dao) GetShareInfo(ctx context.Context, shareCode, accessCode string) (i log.Error("d.GetShareFileInfo() error(%s)", res.ResMsg) return } - if res.NeedAccessCode == 1 && accessCode == "" { - err = errors.New("该分享链接需要访问密码,否则无法读取。") - return - } - params = url.Values{} - params.Set("shareCode", shareCode) - params.Set("accessCode", accessCode) - params.Set("noCache", utils.GenNoCacheNum()) - var checkReq *http.Request - if checkReq, err = http.NewRequest("GET", _checkAccessCodeAPI+params.Encode(), nil); err != nil { - log.Error("http.NewRequest(GET, %s)", _checkAccessCodeAPI+params.Encode(), err) - return - } - checkReq.Header.Set("accept", "application/json;charset=UTF-8") - var checkResp *http.Response - if checkResp, err = d.httpCli.Do(checkReq); err != nil { - log.Error("httpCli.Get(%s) 请求失败!error(%v)", _checkAccessCodeAPI+params.Encode(), err) - return - } - defer checkResp.Body.Close() - if body, err = ioutil.ReadAll(checkResp.Body); err != nil { - log.Error("ioutil.ReadAll error(%v)", err) - return - } - var checkRes struct { - ResCode int `json:"res_code"` - ResMsg string `json:"res_message"` - ShareId int64 `json:"shareId"` - } - if err = json.Unmarshal(body, &checkRes); err != nil { - log.Error("json.Unmarshal() error(%v)", err) - return - } - if checkRes.ResCode != 0 { - log.Error("req checkAccessCodeAPI error(%s)", res.ResMsg) - return + if res.NeedAccessCode == 1 { + if accessCode == "" { + err = errors.New("该分享链接需要访问密码,否则无法读取。") + return + } + params = url.Values{} + params.Set("shareCode", shareCode) + params.Set("accessCode", accessCode) + params.Set("noCache", utils.GenNoCacheNum()) + var checkReq *http.Request + if checkReq, err = http.NewRequest("GET", _checkAccessCodeAPI+params.Encode(), nil); err != nil { + log.Error("http.NewRequest(GET, %s)", _checkAccessCodeAPI+params.Encode(), err) + return + } + checkReq.Header.Set("accept", "application/json;charset=UTF-8") + var checkResp *http.Response + if checkResp, err = d.httpCli.Do(checkReq); err != nil { + log.Error("httpCli.Get(%s) 请求失败!error(%v)", _checkAccessCodeAPI+params.Encode(), err) + return + } + defer checkResp.Body.Close() + if body, err = ioutil.ReadAll(checkResp.Body); err != nil { + log.Error("ioutil.ReadAll error(%v)", err) + return + } + var checkRes struct { + ResCode int `json:"res_code"` + ResMsg string `json:"res_message"` + ShareId int64 `json:"shareId"` + } + if err = json.Unmarshal(body, &checkRes); err != nil { + log.Error("json.Unmarshal() error(%v)", err) + return + } + if checkRes.ResCode != 0 { + log.Error("req checkAccessCodeAPI error(%s)", res.ResMsg) + return + } + res.ShareId = checkRes.ShareId } info = &model.ShareInfo{ ShareCode: shareCode, @@ -180,7 +184,7 @@ func (d *dao) GetShareInfo(ctx context.Context, shareCode, accessCode string) (i FileName: res.FileName, IsFolder: res.IsFolder, FileID: res.FileId, - ShareID: checkRes.ShareId, + ShareID: res.ShareId, } return } diff --git a/go.mod b/go.mod index fc47c6c..d15bb30 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module 189Cloud-Downloader go 1.15 require ( - github.com/otokaze/go-kit v0.0.0-20211104183029-ff83d7a22d29 + github.com/otokaze/go-kit v0.0.0-20220207161129-e72a185d0fff github.com/peterh/liner v1.2.1 github.com/urfave/cli/v2 v2.3.0 ) diff --git a/go.sum b/go.sum index 84afeb0..2ff1809 100644 --- a/go.sum +++ b/go.sum @@ -3,8 +3,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSY github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/mattn/go-runewidth v0.0.3 h1:a+kO+98RDGEfo6asOGMmpodZq4FNtnGP54yps8BzLR4= github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= -github.com/otokaze/go-kit v0.0.0-20211104183029-ff83d7a22d29 h1:lwUm1+3l9xFPFKnLGmHqcs7BZo6DtlSaNeyFI6xcZDQ= -github.com/otokaze/go-kit v0.0.0-20211104183029-ff83d7a22d29/go.mod h1:51Xo2fbqw3dxEjDyHgJQ5WipcOPXs/Y+Zn3YtUGXeN8= +github.com/otokaze/go-kit v0.0.0-20220207161129-e72a185d0fff h1:DG/TxlOgopem0gjR/4nmGi4Bo05h2wDGGW0fKu/xGwE= +github.com/otokaze/go-kit v0.0.0-20220207161129-e72a185d0fff/go.mod h1:51Xo2fbqw3dxEjDyHgJQ5WipcOPXs/Y+Zn3YtUGXeN8= github.com/peterh/liner v1.2.1 h1:O4BlKaq/LWu6VRWmol4ByWfzx6MfXc5Op5HETyIy5yg= github.com/peterh/liner v1.2.1/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/utils/urlparse.go b/utils/urlparse.go index 7f8b440..f74c6c1 100644 --- a/utils/urlparse.go +++ b/utils/urlparse.go @@ -4,7 +4,7 @@ import "regexp" var ( _shareCodePart1 = regexp.MustCompile(`https://cloud.189.cn/t/(\w+)`) - _shareCodePart2 = regexp.MustCompile(`https://cloud.189.cn/web/share?code=(\w+)`) + _shareCodePart2 = regexp.MustCompile(`https://cloud.189.cn/web/share\?code=(\w+)`) ) func ParseShareCode(url string) string {