github.com/fzfile/BaiduPCS-Go@v0.0.0-20200606205115-4408961cf336/internal/pcsconfig/export.go (about) 1 package pcsconfig 2 3 import ( 4 "fmt" 5 "github.com/fzfile/BaiduPCS-Go/baidupcs" 6 "github.com/fzfile/BaiduPCS-Go/pcstable" 7 "github.com/fzfile/BaiduPCS-Go/pcsutil/converter" 8 "github.com/fzfile/BaiduPCS-Go/requester" 9 "github.com/olekukonko/tablewriter" 10 "os" 11 "strconv" 12 ) 13 14 // ActiveUser 获取当前登录的用户 15 func (c *PCSConfig) ActiveUser() *Baidu { 16 if c.activeUser == nil { 17 return &Baidu{} 18 } 19 return c.activeUser 20 } 21 22 // ActiveUserBaiduPCS 获取当前登录的用户的baidupcs.BaiduPCS 23 func (c *PCSConfig) ActiveUserBaiduPCS() *baidupcs.BaiduPCS { 24 if c.pcs == nil { 25 c.pcs = c.ActiveUser().BaiduPCS() 26 } 27 return c.pcs 28 } 29 30 func (c *PCSConfig) httpClientWithUA(ua string) *requester.HTTPClient { 31 client := requester.NewHTTPClient() 32 client.SetHTTPSecure(c.EnableHTTPS) 33 client.SetUserAgent(ua) 34 return client 35 } 36 37 // HTTPClient 返回设置好的 HTTPClient 38 func (c *PCSConfig) HTTPClient() *requester.HTTPClient { 39 return c.httpClientWithUA(c.UserAgent) 40 } 41 42 // PCSHTTPClient 返回设置好的 PCS HTTPClient 43 func (c *PCSConfig) PCSHTTPClient() *requester.HTTPClient { 44 return c.httpClientWithUA(c.PCSUA) 45 } 46 47 // PanHTTPClient 返回设置好的 Pan HTTPClient 48 func (c *PCSConfig) PanHTTPClient() *requester.HTTPClient { 49 return c.httpClientWithUA(c.PanUA) 50 } 51 52 // NumLogins 获取登录的用户数量 53 func (c *PCSConfig) NumLogins() int { 54 return len(c.BaiduUserList) 55 } 56 57 // AverageParallel 返回平均的下载最大并发量 58 func (c *PCSConfig) AverageParallel() int { 59 return AverageParallel(c.MaxParallel, c.MaxDownloadLoad) 60 } 61 62 // PrintTable 输出表格 63 func (c *PCSConfig) PrintTable() { 64 tb := pcstable.NewTable(os.Stdout) 65 tb.SetHeader([]string{"名称", "值", "建议值", "描述"}) 66 tb.SetHeaderAlignment(tablewriter.ALIGN_LEFT) 67 tb.SetColumnAlignment([]int{tablewriter.ALIGN_DEFAULT, tablewriter.ALIGN_LEFT, tablewriter.ALIGN_LEFT, tablewriter.ALIGN_LEFT}) 68 tb.AppendBulk([][]string{ 69 []string{"appid", fmt.Sprint(c.AppID), "", "百度 PCS 应用ID"}, 70 []string{"cache_size", converter.ConvertFileSize(int64(c.CacheSize), 2), "1KB ~ 256KB", "下载缓存, 如果硬盘占用高或下载速度慢, 请尝试调大此值"}, 71 []string{"max_parallel", strconv.Itoa(c.MaxParallel), "1 ~ 64", "下载最大并发量"}, 72 []string{"max_upload_parallel", strconv.Itoa(c.MaxUploadParallel), "1 ~ 100", "上传最大并发量"}, 73 []string{"max_download_load", strconv.Itoa(c.MaxDownloadLoad), "1 ~ 5", "同时进行下载文件的最大数量"}, 74 []string{"max_download_rate", showMaxRate(c.MaxDownloadRate), "", "限制最大下载速度, 0代表不限制"}, 75 []string{"max_upload_rate", showMaxRate(c.MaxUploadRate), "", "限制最大上传速度, 0代表不限制"}, 76 []string{"savedir", c.SaveDir, "", "下载文件的储存目录"}, 77 []string{"enable_https", fmt.Sprint(c.EnableHTTPS), "true", "启用 https"}, 78 []string{"user_agent", c.UserAgent, requester.DefaultUserAgent, "浏览器标识"}, 79 []string{"pcs_ua", c.PCSUA, "", "PCS 浏览器标识"}, 80 []string{"pan_ua", c.PanUA, baidupcs.NetdiskUA, "Pan 浏览器标识"}, 81 []string{"proxy", c.Proxy, "", "设置代理, 支持 http/socks5 代理"}, 82 []string{"local_addrs", c.LocalAddrs, "", "设置本地网卡地址, 多个地址用逗号隔开"}, 83 }) 84 tb.Render() 85 }