Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
iikira committed Jul 29, 2018
1 parent 217defb commit de3a91f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
4 changes: 3 additions & 1 deletion baidupcs/baidupcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const (
OperationShareCancel = "取消分享"
// OperationShareList 列出分享列表
OperationShareList = "列出分享列表"
// NetdiskUA 网盘客户端ua
NetdiskUA = "netdisk;7.8.1;Red;android-android;4.3"
)

var (
Expand Down Expand Up @@ -203,7 +205,7 @@ func (pcs *BaiduPCS) UK() (uk int64, pcsError Error) {

errInfo := NewErrorInfo(OperationGetUK)
body, err := pcs.client.Fetch("GET", pcsURL, nil, map[string]string{
"User-Agent": "netdisk;8.3.1",
"User-Agent": NetdiskUA,
})
if err != nil {
errInfo.errType = ErrTypeNetError
Expand Down
6 changes: 3 additions & 3 deletions baidupcs/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (pcs *BaiduPCS) ShareSet(paths []string, option *ShareOption) (s *Shared, p
"period": strconv.Itoa(option.Period),
}, map[string]string{
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": "netdisk;8.3.1",
"User-Agent": NetdiskUA,
})
if resp != nil {
defer resp.Body.Close()
Expand Down Expand Up @@ -160,7 +160,7 @@ func (pcs *BaiduPCS) ShareCancel(shareIDs []int64) (pcsError Error) {
"shareid_list": builder.String(),
}, map[string]string{
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": "netdisk;8.3.1",
"User-Agent": NetdiskUA,
})
if resp != nil {
defer resp.Body.Close()
Expand Down Expand Up @@ -214,7 +214,7 @@ func (pcs *BaiduPCS) ShareList(page int) (records ShareRecordInfoList, pcsError
baiduPCSVerbose.Infof("%s URL: %s\n", OperationShareList, pcsURL)

resp, err := pcs.client.Req("GET", pcsURL.String(), nil, map[string]string{
"User-Agent": "netdisk;8.3.1",
"User-Agent": NetdiskUA,
})
if resp != nil {
defer resp.Body.Close()
Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ func init() {
func main() {
defer pcsconfig.Config.Close()

line := pcsliner.NewLiner()
app := cli.NewApp()
app.Name = "BaiduPCS-Go"
app.Version = Version
Expand Down Expand Up @@ -135,7 +134,8 @@ func main() {
pcsverbose.Verbosef("VERBOSE: 这是一条调试信息\n\n")

var (
err error
line = pcsliner.NewLiner()
err error
)

line.History, err = pcsliner.NewLineHistory(historyFilePath)
Expand Down Expand Up @@ -1092,7 +1092,7 @@ func main() {
},
cli.BoolFlag{
Name: "nofix",
Usage: "在上传完成后不修复md5, 不一定能成功",
Usage: "在上传完成后不修复md5",
},
},
},
Expand Down Expand Up @@ -1695,7 +1695,7 @@ func main() {
Description: "清空控制台屏幕",
Category: "其他",
Action: func(c *cli.Context) error {
line.ClearScreen()
pcsliner.ClearScreen()
return nil
},
},
Expand Down
5 changes: 5 additions & 0 deletions pcsliner/clear.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ import (

// ClearScreen 清空屏幕
func (pl *PCSLiner) ClearScreen() {
ClearScreen()
}

// ClearScreen 清空屏幕
func ClearScreen() {
fmt.Print("\x1b[H\x1b[2J")
}
12 changes: 12 additions & 0 deletions pcsliner/clear_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,22 @@ import (
_ "unsafe" // for go:linkname
)

var (
defaultLinerState *liner.State
)

//go:linkname eraseScreen github.com/iikira/BaiduPCS-Go/vendor/github.com/peterh/liner.(*State).eraseScreen
func eraseScreen(s *liner.State)

// ClearScreen 清空屏幕
func (pl *PCSLiner) ClearScreen() {
eraseScreen(pl.State)
}

// ClearScreen 清空屏幕
func ClearScreen() {
if defaultLinerState == nil {
defaultLinerState = liner.NewLiner()
}
defaultLinerState.ClearScreen()
}
6 changes: 6 additions & 0 deletions requester/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ func (h *HTTPClient) SetResponseHeaderTimeout(t time.Duration) {
h.transport.ResponseHeaderTimeout = t
}

// SetTLSHandshakeTimeout 设置tls握手超时时间
func (h *HTTPClient) SetTLSHandshakeTimeout(t time.Duration) {
h.lazyInit()
h.transport.TLSHandshakeTimeout = t
}

// SetTimeout 设置 http 请求超时时间, 默认30s
func (h *HTTPClient) SetTimeout(t time.Duration) {
h.Client.Timeout = t
Expand Down

0 comments on commit de3a91f

Please sign in to comment.