Skip to content

Commit

Permalink
修复一些问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Otokaze committed Feb 7, 2022
1 parent 7b6dd33 commit a4685ad
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 45 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

1. init.
2 changes: 1 addition & 1 deletion action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion dao/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
80 changes: 42 additions & 38 deletions dao/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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"`
Expand All @@ -137,50 +138,53 @@ 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,
AccessCode: accessCode,
FileName: res.FileName,
IsFolder: res.IsFolder,
FileID: res.FileId,
ShareID: checkRes.ShareId,
ShareID: res.ShareId,
}
return
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion utils/urlparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a4685ad

Please sign in to comment.