├── pcsinit └── pcsinit.s ├── vendor └── github.com │ ├── modern-go │ ├── reflect2 │ │ ├── reflect2_amd64.s │ │ ├── relfect2_386.s │ │ ├── relfect2_arm.s │ │ ├── relfect2_arm64.s │ │ ├── relfect2_mipsx.s │ │ ├── relfect2_s390x.s │ │ ├── relfect2_amd64p32.s │ │ ├── relfect2_mips64x.s │ │ ├── relfect2_ppc64x.s │ │ ├── .gitignore │ │ ├── README.md │ │ ├── go_below_17.go │ │ ├── go_above_17.go │ │ ├── go_below_19.go │ │ ├── go_above_19.go │ │ ├── safe_struct.go │ │ ├── Gopkg.lock │ │ ├── reflect2_kind.go │ │ ├── Gopkg.toml │ │ ├── unsafe_ptr.go │ │ ├── safe_field.go │ │ ├── unsafe_eface.go │ │ ├── unsafe_iface.go │ │ ├── unsafe_struct.go │ │ ├── safe_type.go │ │ ├── type_map.go │ │ ├── unsafe_array.go │ │ └── unsafe_field.go │ └── concurrent │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── go_above_19.go │ │ ├── test.sh │ │ ├── log.go │ │ ├── executor.go │ │ ├── go_below_19.go │ │ └── README.md │ ├── fatih │ └── color │ │ ├── .travis.yml │ │ └── LICENSE.md │ ├── urfave │ └── cli │ │ ├── .flake8 │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── appveyor.yml │ │ ├── cli.go │ │ ├── LICENSE │ │ ├── category.go │ │ └── funcs.go │ ├── json-iterator │ └── go │ │ ├── .codecov.yml │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── test.sh │ │ ├── build.sh │ │ ├── Gopkg.lock │ │ ├── Gopkg.toml │ │ ├── fuzzy_mode_convert_table.md │ │ ├── jsoniter.go │ │ ├── pool.go │ │ ├── LICENSE │ │ ├── any_nil.go │ │ ├── any_int64.go │ │ ├── any_int32.go │ │ ├── any_uint64.go │ │ ├── iter_array.go │ │ ├── any_uint32.go │ │ ├── any_float.go │ │ ├── any_invalid.go │ │ ├── reflect_dynamic.go │ │ ├── reflect_json_raw_message.go │ │ └── iter_skip_strict.go │ ├── iikira │ ├── baidu-tools │ │ ├── .gitignore │ │ ├── version.go │ │ ├── README.md │ │ ├── baidu.go │ │ ├── tieba │ │ │ ├── tieba.go │ │ │ └── tiebautil │ │ │ │ └── client_signature.go │ │ ├── randominfo │ │ │ ├── phone.go │ │ │ └── randominfo.go │ │ └── pan │ │ │ └── parser.go │ ├── Baidu-Login │ │ ├── version.go │ │ ├── config.go │ │ ├── .gitignore │ │ ├── bdcrypto │ │ │ ├── bdcrypto.go │ │ │ ├── reverse.go │ │ │ ├── base64.go │ │ │ ├── hmac.go │ │ │ ├── archive.go │ │ │ └── ecb │ │ │ │ └── ecb.go │ │ ├── http_server_page.go │ │ └── README.md │ └── args │ │ ├── .gitignore │ │ ├── LICENSE │ │ └── README.md │ ├── GeertJohan │ └── go.rice │ │ ├── debug.go │ │ ├── .gitignore │ │ ├── AUTHORS │ │ ├── .travis.yml │ │ ├── http.go │ │ ├── sort.go │ │ ├── LICENSE │ │ └── config.go │ ├── olekukonko │ └── tablewriter │ │ ├── .travis.yml │ │ ├── .gitignore │ │ ├── LICENCE.md │ │ └── csv.go │ ├── kardianos │ └── osext │ │ ├── osext_go18.go │ │ ├── osext_plan9.go │ │ ├── README.md │ │ ├── osext_windows.go │ │ ├── osext.go │ │ ├── osext_procfs.go │ │ └── LICENSE │ ├── daaku │ └── go.zipexe │ │ ├── readme.md │ │ └── license │ ├── bitly │ └── go-simplejson │ │ ├── .travis.yml │ │ ├── README.md │ │ ├── LICENSE │ │ └── simplejson_go10.go │ ├── mattn │ └── go-runewidth │ │ ├── runewidth_js.go │ │ ├── .travis.yml │ │ ├── runewidth_windows.go │ │ ├── README.mkd │ │ ├── LICENSE │ │ └── runewidth_posix.go │ ├── shiena │ └── ansicolor │ │ ├── .gitignore │ │ ├── ansicolor_ansi.go │ │ ├── LICENSE │ │ └── ansicolor.go │ ├── peterh │ └── liner │ │ ├── input_linux.go │ │ ├── bsdinput.go │ │ ├── input_darwin.go │ │ ├── unixmode.go │ │ ├── COPYING │ │ ├── fallbackinput.go │ │ ├── output.go │ │ └── width.go │ └── astaxie │ └── beego │ ├── LICENSE │ └── utils │ ├── utils.go │ ├── caller.go │ ├── captcha │ └── LICENSE │ └── rand.go ├── debian ├── Packages.sh ├── linux-amd64 │ └── control └── iphoneos-arm │ └── control ├── assets ├── caution.png ├── BaiduPCS-Go.ico └── donate │ └── alipay.jpg ├── resource_windows.syso ├── internal ├── pcsupdate │ ├── check_windows.go │ ├── check_unix.go │ └── updatefile.go ├── pcsweb │ ├── static │ │ ├── favicon.ico │ │ ├── fonts │ │ │ ├── FontAwesome.otf │ │ │ ├── fontawesome-webfont.eot │ │ │ ├── fontawesome-webfont.ttf │ │ │ ├── fontawesome-webfont.woff │ │ │ └── fontawesome-webfont.woff2 │ │ ├── js │ │ │ └── nano.js │ │ └── css │ │ │ └── main.css │ ├── template │ │ ├── template.html │ │ ├── about.html │ │ └── 404.html │ ├── utils.go │ ├── pcsfile.go │ ├── errors.go │ ├── middleware.go │ └── pcsweb.go ├── pcscommand │ ├── runner.go │ ├── meta.go │ ├── quota.go │ ├── pcscommand.go │ ├── cd.go │ ├── rm_mkdir.go │ ├── export.go │ ├── tree.go │ ├── cloud_dl.go │ └── bg_fg.go └── pcsconfig │ └── errors.go ├── pcspath ├── regexp.go ├── util_test.go ├── match_test.go ├── match.go ├── pcspath.go └── util.go ├── pcsutil ├── getip │ ├── getip_test.go │ └── getip.go ├── regexp_pre.go ├── waitgroup │ ├── wait_group_test.go │ └── wait_group.go ├── converter │ ├── unsafe_strconv_test.go │ └── converter.go ├── error.go ├── addr.go ├── log_colorable_prefix.go ├── pcstime │ └── time.go └── pcsutil.go ├── pcsverbose ├── utils.go ├── pcsdebug │ └── cpu.go └── pcsverbose.go ├── pcscache ├── pcscache.go └── dir_cache.go ├── requester ├── rio │ ├── multi_test.go │ ├── buf.go │ ├── file.go │ ├── rio.go │ ├── speeds │ │ └── speeds.go │ └── multi.go ├── requester.go ├── uploader │ ├── readed.go │ ├── example.go │ └── status.go ├── downloader │ ├── config.go │ ├── range.go │ ├── example.go │ ├── utils.go │ ├── cachepool │ │ └── cachepool.go │ ├── loadbalance.go │ └── download_test.go └── dial.go ├── pcstable └── pcstable.go ├── .gitignore ├── Info.plist ├── baidupcs ├── rm_mkdir.go ├── cp_mv_rename.go ├── quota.go ├── util.go └── jsontable.go ├── BaiduPCS-Go.exe.manifest ├── .github └── RELEASE_TEMPLATE.md ├── versioninfo.json ├── pcsliner ├── linehistory.go └── pcsliner.go └── Gopkg.toml /pcsinit/pcsinit.s: -------------------------------------------------------------------------------- 1 | // +build !noasm !appengine 2 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/reflect2/reflect2_amd64.s: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/reflect2/relfect2_386.s: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/reflect2/relfect2_arm.s: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/reflect2/relfect2_arm64.s: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/reflect2/relfect2_mipsx.s: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/reflect2/relfect2_s390x.s: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /debian/Packages.sh: -------------------------------------------------------------------------------- 1 | dpkg-scanpackages . | gzip > Packages.gz -------------------------------------------------------------------------------- /vendor/github.com/modern-go/reflect2/relfect2_amd64p32.s: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/reflect2/relfect2_mips64x.s: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/reflect2/relfect2_ppc64x.s: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/reflect2/.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/concurrent/.gitignore: -------------------------------------------------------------------------------- 1 | /coverage.txt 2 | -------------------------------------------------------------------------------- /vendor/github.com/fatih/color/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 1.3 3 | 4 | -------------------------------------------------------------------------------- /vendor/github.com/urfave/cli/.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | max-line-length = 120 3 | -------------------------------------------------------------------------------- /vendor/github.com/urfave/cli/.gitignore: -------------------------------------------------------------------------------- 1 | *.coverprofile 2 | node_modules/ 3 | -------------------------------------------------------------------------------- /assets/caution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foxsen/BaiduPCS-Go/master/assets/caution.png -------------------------------------------------------------------------------- /vendor/github.com/json-iterator/go/.codecov.yml: -------------------------------------------------------------------------------- 1 | ignore: 2 | - "output_tests/.*" 3 | 4 | -------------------------------------------------------------------------------- /resource_windows.syso: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foxsen/BaiduPCS-Go/master/resource_windows.syso -------------------------------------------------------------------------------- /vendor/github.com/iikira/baidu-tools/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .vscode/ 3 | *txt 4 | *.jar 5 | *.aar -------------------------------------------------------------------------------- /assets/BaiduPCS-Go.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foxsen/BaiduPCS-Go/master/assets/BaiduPCS-Go.ico -------------------------------------------------------------------------------- /vendor/github.com/json-iterator/go/.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | /bug_test.go 3 | /coverage.txt 4 | /.idea 5 | -------------------------------------------------------------------------------- /assets/donate/alipay.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foxsen/BaiduPCS-Go/master/assets/donate/alipay.jpg -------------------------------------------------------------------------------- /internal/pcsupdate/check_windows.go: -------------------------------------------------------------------------------- 1 | package pcsupdate 2 | 3 | func checkWritable() bool { 4 | return true 5 | } 6 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/reflect2/README.md: -------------------------------------------------------------------------------- 1 | # reflect2 2 | reflect api that avoids runtime reflect.Value cost 3 | -------------------------------------------------------------------------------- /internal/pcsweb/static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foxsen/BaiduPCS-Go/master/internal/pcsweb/static/favicon.ico -------------------------------------------------------------------------------- /vendor/github.com/iikira/baidu-tools/version.go: -------------------------------------------------------------------------------- 1 | package baidu 2 | 3 | const ( 4 | // Version 版本号 5 | Version = "v1.0" 6 | ) 7 | -------------------------------------------------------------------------------- /vendor/github.com/iikira/Baidu-Login/version.go: -------------------------------------------------------------------------------- 1 | package baidulogin 2 | 3 | const ( 4 | // Version 版本号 5 | Version = "v1.2.1" 6 | ) 7 | -------------------------------------------------------------------------------- /vendor/github.com/GeertJohan/go.rice/debug.go: -------------------------------------------------------------------------------- 1 | package rice 2 | 3 | // Debug can be set to true to enable debugging. 4 | var Debug = false 5 | -------------------------------------------------------------------------------- /internal/pcsweb/static/fonts/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foxsen/BaiduPCS-Go/master/internal/pcsweb/static/fonts/FontAwesome.otf -------------------------------------------------------------------------------- /pcspath/regexp.go: -------------------------------------------------------------------------------- 1 | package pcspath 2 | 3 | import ( 4 | "regexp" 5 | ) 6 | 7 | var ( 8 | patternRE = regexp.MustCompile(`[\*\?]`) 9 | ) 10 | -------------------------------------------------------------------------------- /internal/pcsweb/static/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foxsen/BaiduPCS-Go/master/internal/pcsweb/static/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /internal/pcsweb/static/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foxsen/BaiduPCS-Go/master/internal/pcsweb/static/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /internal/pcsweb/static/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foxsen/BaiduPCS-Go/master/internal/pcsweb/static/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /internal/pcsweb/static/fonts/fontawesome-webfont.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foxsen/BaiduPCS-Go/master/internal/pcsweb/static/fonts/fontawesome-webfont.woff2 -------------------------------------------------------------------------------- /vendor/github.com/iikira/baidu-tools/README.md: -------------------------------------------------------------------------------- 1 | # 百度工具箱 2 | [![GoDoc](https://godoc.org/github.com/iikira/baidu-tools?status.svg)](https://godoc.org/github.com/iikira/baidu-tools) -------------------------------------------------------------------------------- /vendor/github.com/GeertJohan/go.rice/.gitignore: -------------------------------------------------------------------------------- 1 | /example/example 2 | /example/example.exe 3 | /rice/rice 4 | /rice/rice.exe 5 | 6 | *.rice-box.go 7 | *.rice-box.syso 8 | .wercker 9 | -------------------------------------------------------------------------------- /pcsutil/getip/getip_test.go: -------------------------------------------------------------------------------- 1 | package getip 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | ) 7 | 8 | func TestGetIP(t *testing.T) { 9 | fmt.Println(IPInfo(false)) 10 | } 11 | -------------------------------------------------------------------------------- /vendor/github.com/GeertJohan/go.rice/AUTHORS: -------------------------------------------------------------------------------- 1 | Geert-Johan Riemer 2 | Paul Maddox 3 | Vincent Petithory 4 | 5 | -------------------------------------------------------------------------------- /vendor/github.com/olekukonko/tablewriter/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.1 5 | - 1.2 6 | - 1.3 7 | - 1.4 8 | - 1.5 9 | - 1.6 10 | - 1.7 11 | - 1.8 12 | - tip 13 | -------------------------------------------------------------------------------- /vendor/github.com/kardianos/osext/osext_go18.go: -------------------------------------------------------------------------------- 1 | //+build go1.8,!openbsd 2 | 3 | package osext 4 | 5 | import "os" 6 | 7 | func executable() (string, error) { 8 | return os.Executable() 9 | } 10 | -------------------------------------------------------------------------------- /internal/pcsweb/template/template.html: -------------------------------------------------------------------------------- 1 | {{define "title"}}{{end}} {{define "contents"}} 2 |
3 | 4 |
5 | {{end}} {{define "contents_js"}} 6 | {{end}} -------------------------------------------------------------------------------- /vendor/github.com/modern-go/reflect2/go_below_17.go: -------------------------------------------------------------------------------- 1 | //+build !go1.7 2 | 3 | package reflect2 4 | 5 | import "unsafe" 6 | 7 | func resolveTypeOff(rtype unsafe.Pointer, off int32) unsafe.Pointer { 8 | return nil 9 | } -------------------------------------------------------------------------------- /vendor/github.com/daaku/go.zipexe/readme.md: -------------------------------------------------------------------------------- 1 | go.zipexe 2 | ========= 3 | 4 | This module was taken as-is from https://github.com/cookieo9/resources-go. 5 | Documentation: https://godoc.org/github.com/daaku/go.zipexe 6 | -------------------------------------------------------------------------------- /vendor/github.com/bitly/go-simplejson/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 3 | - 1.0.3 4 | - 1.1.2 5 | - 1.2 6 | - tip 7 | install: 8 | - go get github.com/bmizerany/assert 9 | notifications: 10 | email: false 11 | -------------------------------------------------------------------------------- /pcsverbose/utils.go: -------------------------------------------------------------------------------- 1 | package pcsverbose 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | "io/ioutil" 7 | ) 8 | 9 | //PrintReader 输出Reader 10 | func PrintReader(r io.Reader) { 11 | b, _ := ioutil.ReadAll(r) 12 | fmt.Printf("%s\n", b) 13 | } 14 | -------------------------------------------------------------------------------- /vendor/github.com/mattn/go-runewidth/runewidth_js.go: -------------------------------------------------------------------------------- 1 | // +build js 2 | 3 | package runewidth 4 | 5 | func IsEastAsian() bool { 6 | // TODO: Implement this for the web. Detect east asian in a compatible way, and return true. 7 | return false 8 | } 9 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/reflect2/go_above_17.go: -------------------------------------------------------------------------------- 1 | //+build go1.7 2 | 3 | package reflect2 4 | 5 | import "unsafe" 6 | 7 | //go:linkname resolveTypeOff reflect.resolveTypeOff 8 | func resolveTypeOff(rtype unsafe.Pointer, off int32) unsafe.Pointer 9 | -------------------------------------------------------------------------------- /vendor/github.com/json-iterator/go/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.8.x 5 | - 1.x 6 | 7 | before_install: 8 | - go get -t -v ./... 9 | 10 | script: 11 | - ./test.sh 12 | 13 | after_success: 14 | - bash <(curl -s https://codecov.io/bash) 15 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/concurrent/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.8.x 5 | - 1.x 6 | 7 | before_install: 8 | - go get -t -v ./... 9 | 10 | script: 11 | - ./test.sh 12 | 13 | after_success: 14 | - bash <(curl -s https://codecov.io/bash) 15 | -------------------------------------------------------------------------------- /pcsutil/regexp_pre.go: -------------------------------------------------------------------------------- 1 | package pcsutil 2 | 3 | import ( 4 | "regexp" 5 | ) 6 | 7 | var ( 8 | // HTTPSRE https regexp 9 | HTTPSRE = regexp.MustCompile("^https") 10 | // ChinaPhoneRE https regexp 11 | ChinaPhoneRE = regexp.MustCompile(`^(\+86)?1[3-9][0-9]\d{8}$`) 12 | ) 13 | -------------------------------------------------------------------------------- /vendor/github.com/mattn/go-runewidth/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 3 | - tip 4 | before_install: 5 | - go get github.com/mattn/goveralls 6 | - go get golang.org/x/tools/cmd/cover 7 | script: 8 | - $HOME/gopath/bin/goveralls -repotoken lAKAWPzcGsD3A8yBX3BGGtRUdJ6CaGERL 9 | -------------------------------------------------------------------------------- /internal/pcsupdate/check_unix.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package pcsupdate 4 | 5 | import ( 6 | "github.com/iikira/BaiduPCS-Go/pcsutil" 7 | "syscall" 8 | ) 9 | 10 | func checkWritable() bool { 11 | return syscall.Access(pcsutil.ExecutablePath(), syscall.O_RDWR) == nil 12 | } 13 | -------------------------------------------------------------------------------- /pcscache/pcscache.go: -------------------------------------------------------------------------------- 1 | package pcscache 2 | 3 | import ( 4 | "github.com/iikira/BaiduPCS-Go/baidupcs" 5 | "time" 6 | ) 7 | 8 | var ( 9 | // DirCache 网盘目录缓存 10 | DirCache = &dirCache{ 11 | fdl: map[string]*baidupcs.FileDirectoryList{}, 12 | lifeTime: 1 * time.Hour, 13 | } 14 | ) 15 | -------------------------------------------------------------------------------- /debian/linux-amd64/control: -------------------------------------------------------------------------------- 1 | Package: BaiduPCS-Go 2 | Version: 3.5 3 | Homepage: https://github.com/iikira/BaiduPCS-Go 4 | Section: utils 5 | Priority: optional 6 | Architecture: amd64 7 | Installed-Size: 4096 8 | Maintainer: iikira 9 | Description: BaiduPCS-Go 使用Go语言编写的百度网盘命令行客户端, 为操作百度网盘, 提供实用功能. -------------------------------------------------------------------------------- /debian/iphoneos-arm/control: -------------------------------------------------------------------------------- 1 | Package: BaiduPCS-Go 2 | Version: 3.5.3 3 | Homepage: https://github.com/iikira/BaiduPCS-Go 4 | Section: 实用工具 5 | Priority: optional 6 | Architecture: iphoneos-arm 7 | Installed-Size: 4096 8 | Maintainer: iikira 9 | Description: BaiduPCS-Go 使用Go语言编写的百度网盘命令行客户端, 为操作百度网盘, 提供实用功能. -------------------------------------------------------------------------------- /vendor/github.com/iikira/Baidu-Login/config.go: -------------------------------------------------------------------------------- 1 | package baidulogin 2 | 3 | import ( 4 | "github.com/GeertJohan/go.rice" 5 | "github.com/astaxie/beego/session" 6 | ) 7 | 8 | var ( 9 | templateFilesBox *rice.Box 10 | libFilesBox *rice.Box 11 | 12 | globalSessions *session.Manager // 全局 sessions 管理器 13 | ) 14 | -------------------------------------------------------------------------------- /internal/pcsweb/template/about.html: -------------------------------------------------------------------------------- 1 | {{define "title"}}关于{{end}}{{define "contents"}} 2 |
3 | 6 |
7 | {{end}}{{define "contents_js"}} {{end}} -------------------------------------------------------------------------------- /vendor/github.com/modern-go/concurrent/go_above_19.go: -------------------------------------------------------------------------------- 1 | //+build go1.9 2 | 3 | package concurrent 4 | 5 | import "sync" 6 | 7 | // Map is a wrapper for sync.Map introduced in go1.9 8 | type Map struct { 9 | sync.Map 10 | } 11 | 12 | // NewMap creates a thread safe Map 13 | func NewMap() *Map { 14 | return &Map{} 15 | } 16 | -------------------------------------------------------------------------------- /internal/pcscommand/runner.go: -------------------------------------------------------------------------------- 1 | package pcscommand 2 | 3 | import ( 4 | "io" 5 | "os" 6 | ) 7 | 8 | var ( 9 | // DefaultRunner 默认 Runner 10 | DefaultRunner = Runner{ 11 | Output: os.Stdout, 12 | } 13 | ) 14 | 15 | type ( 16 | // Runner 执行器 17 | Runner struct { 18 | Output io.Writer 19 | IsBackground bool 20 | } 21 | ) 22 | -------------------------------------------------------------------------------- /pcspath/util_test.go: -------------------------------------------------------------------------------- 1 | package pcspath 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | ) 7 | 8 | func TestEscapeBlank(t *testing.T) { 9 | fmt.Println(Escape("asdfj(alsf)djlsf")) 10 | fmt.Println(Escape("asdfjal\\\\\\ sfdj lsf")) 11 | fmt.Println(Escape("asdfjal\\\\ sfdj lsf")) 12 | fmt.Println(Escape("asdfjal\\ s (asdfa) [asf] fdj lsf")) 13 | } 14 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/reflect2/go_below_19.go: -------------------------------------------------------------------------------- 1 | //+build !go1.9 2 | 3 | package reflect2 4 | 5 | import ( 6 | "unsafe" 7 | ) 8 | 9 | //go:linkname makemap reflect.makemap 10 | func makemap(rtype unsafe.Pointer) (m unsafe.Pointer) 11 | 12 | func makeMapWithSize(rtype unsafe.Pointer, cap int) unsafe.Pointer { 13 | return makemap(rtype) 14 | } 15 | -------------------------------------------------------------------------------- /requester/rio/multi_test.go: -------------------------------------------------------------------------------- 1 | package rio 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | "os" 7 | "strings" 8 | "testing" 9 | ) 10 | 11 | func TestMultiReaderLen(t *testing.T) { 12 | rd1, rd2 := strings.NewReader("asdkfljalf"), strings.NewReader("---asva sdf") 13 | multi := MultiReaderLen(rd1, rd2) 14 | fmt.Println(multi.Len()) 15 | io.Copy(os.Stdout, multi) 16 | } 17 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/reflect2/go_above_19.go: -------------------------------------------------------------------------------- 1 | //+build go1.9 2 | 3 | package reflect2 4 | 5 | import ( 6 | "unsafe" 7 | ) 8 | 9 | //go:linkname makemap reflect.makemap 10 | func makemap(rtype unsafe.Pointer, cap int) (m unsafe.Pointer) 11 | 12 | func makeMapWithSize(rtype unsafe.Pointer, cap int) unsafe.Pointer { 13 | return makemap(rtype, cap) 14 | } 15 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/reflect2/safe_struct.go: -------------------------------------------------------------------------------- 1 | package reflect2 2 | 3 | type safeStructType struct { 4 | safeType 5 | } 6 | 7 | func (type2 *safeStructType) FieldByName(name string) StructField { 8 | field, found := type2.Type.FieldByName(name) 9 | if !found { 10 | panic("field " + name + " not found") 11 | } 12 | return &safeField{StructField: field} 13 | } -------------------------------------------------------------------------------- /vendor/github.com/olekukonko/tablewriter/.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Go template 3 | # Binaries for programs and plugins 4 | *.exe 5 | *.exe~ 6 | *.dll 7 | *.so 8 | *.dylib 9 | 10 | # Test binary, build with `go test -c` 11 | *.test 12 | 13 | # Output of the go coverage tool, specifically when used with LiteIDE 14 | *.out 15 | 16 | -------------------------------------------------------------------------------- /vendor/github.com/json-iterator/go/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | echo "" > coverage.txt 5 | 6 | for d in $(go list ./... | grep -v vendor); do 7 | go test -coverprofile=profile.out -coverpkg=github.com/json-iterator/go $d 8 | if [ -f profile.out ]; then 9 | cat profile.out >> coverage.txt 10 | rm profile.out 11 | fi 12 | done 13 | -------------------------------------------------------------------------------- /pcsutil/waitgroup/wait_group_test.go: -------------------------------------------------------------------------------- 1 | package waitgroup 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | "time" 7 | ) 8 | 9 | func TestWg(t *testing.T) { 10 | wg := NewWaitGroup(2) 11 | for i := 0; i < 60; i++ { 12 | wg.AddDelta() 13 | go func(i int) { 14 | fmt.Println(i, wg.Parallel()) 15 | time.Sleep(1e9) 16 | wg.Done() 17 | }(i) 18 | } 19 | wg.Wait() 20 | } 21 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/concurrent/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | echo "" > coverage.txt 5 | 6 | for d in $(go list ./... | grep -v vendor); do 7 | go test -coverprofile=profile.out -coverpkg=github.com/modern-go/concurrent $d 8 | if [ -f profile.out ]; then 9 | cat profile.out >> coverage.txt 10 | rm profile.out 11 | fi 12 | done 13 | -------------------------------------------------------------------------------- /pcspath/match_test.go: -------------------------------------------------------------------------------- 1 | package pcspath 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | ) 7 | 8 | func TestMatch(t *testing.T) { 9 | workdir := "/" 10 | pp := NewPCSPath(&workdir, "[123?") 11 | fmt.Println(pp.AbsPathNoMatch()) 12 | fmt.Println(pp.Match([]string{"123", "/[1234", "12345"}...)) 13 | } 14 | 15 | func TestTest(t *testing.T) { 16 | fmt.Println(SplitAll("/1/2/3")) 17 | } 18 | -------------------------------------------------------------------------------- /vendor/github.com/iikira/args/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | -------------------------------------------------------------------------------- /internal/pcsweb/static/js/nano.js: -------------------------------------------------------------------------------- 1 | /* Nano Templates - https://github.com/trix/nano */ 2 | 3 | function nano(template, data) { 4 | return template.replace(/\{([\w\.]*)\}/g, function(str, key) { 5 | var keys = key.split("."), v = data[keys.shift()]; 6 | for (var i = 0, l = keys.length; i < l; i++) v = v[keys[i]]; 7 | return (typeof v !== "undefined" && v !== null) ? v : ""; 8 | }); 9 | } -------------------------------------------------------------------------------- /internal/pcsweb/template/404.html: -------------------------------------------------------------------------------- 1 | {{define "title"}}404 Not Found{{end}} {{define "contents"}} 2 |
3 |
4 | 7 | 404 page not found 8 |
9 |
10 | {{end}}{{define "contents_js"}} {{end}} -------------------------------------------------------------------------------- /vendor/github.com/modern-go/concurrent/log.go: -------------------------------------------------------------------------------- 1 | package concurrent 2 | 3 | import ( 4 | "os" 5 | "log" 6 | "io/ioutil" 7 | ) 8 | 9 | // ErrorLogger is used to print out error, can be set to writer other than stderr 10 | var ErrorLogger = log.New(os.Stderr, "", 0) 11 | 12 | // InfoLogger is used to print informational message, default to off 13 | var InfoLogger = log.New(ioutil.Discard, "", 0) -------------------------------------------------------------------------------- /vendor/github.com/iikira/baidu-tools/baidu.go: -------------------------------------------------------------------------------- 1 | package baidu 2 | 3 | // Baidu 百度帐号详细情况 4 | type Baidu struct { 5 | UID uint64 // 百度ID对应的uid 6 | Name string // 真实ID 7 | NameShow string // 显示的用户名(昵称) 8 | Sex string // 性别 9 | Age float64 // 帐号年龄 10 | Auth *Auth 11 | } 12 | 13 | // Auth 百度验证 14 | type Auth struct { 15 | BDUSS string // 百度BDUSS 16 | PTOKEN string 17 | STOKEN string 18 | } 19 | -------------------------------------------------------------------------------- /internal/pcsweb/utils.go: -------------------------------------------------------------------------------- 1 | package pcsweb 2 | 3 | import ( 4 | "html/template" 5 | ) 6 | 7 | // boxTmplParse ricebox 载入文件内容, 并进行模板解析 8 | func boxTmplParse(name string, fileNames ...string) (tmpl *template.Template) { 9 | var ( 10 | err error 11 | ) 12 | tmpl = template.New(name) 13 | for k := range fileNames { 14 | _, err = tmpl.Parse(templatesBox.MustString(fileNames[k])) 15 | checkErr(err) 16 | } 17 | return 18 | } 19 | -------------------------------------------------------------------------------- /vendor/github.com/bitly/go-simplejson/README.md: -------------------------------------------------------------------------------- 1 | ### go-simplejson 2 | 3 | a Go package to interact with arbitrary JSON 4 | 5 | [![Build Status](https://secure.travis-ci.org/bitly/go-simplejson.png)](http://travis-ci.org/bitly/go-simplejson) 6 | 7 | ### Importing 8 | 9 | import github.com/bitly/go-simplejson 10 | 11 | ### Documentation 12 | 13 | Visit the docs on [gopkgdoc](http://godoc.org/github.com/bitly/go-simplejson) 14 | -------------------------------------------------------------------------------- /internal/pcscommand/meta.go: -------------------------------------------------------------------------------- 1 | package pcscommand 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | // RunGetMeta 执行 获取单个文件/目录的元信息 8 | func RunGetMeta(path string) { 9 | p, err := getAbsPath(path) 10 | if err != nil { 11 | fmt.Println(err) 12 | return 13 | } 14 | 15 | data, err := GetBaiduPCS().FilesDirectoriesMeta(p) 16 | if err != nil { 17 | fmt.Println(err) 18 | return 19 | } 20 | fmt.Println() 21 | fmt.Println(data) 22 | } 23 | -------------------------------------------------------------------------------- /pcsutil/converter/unsafe_strconv_test.go: -------------------------------------------------------------------------------- 1 | // go test -test.bench=".*" 2 | package converter 3 | 4 | import ( 5 | "testing" 6 | ) 7 | 8 | var str = "asddsadfaalkdjsksajdfkashjkdfhashfliuhsadifhasifhaishdfiashdihaisdfhiuassfasdff" 9 | 10 | func BenchmarkToBytes(b *testing.B) { 11 | for i := 0; i <= b.N; i++ { 12 | _ = ToBytes(str) 13 | } 14 | } 15 | 16 | func BenchmarkBytes(b *testing.B) { 17 | for i := 0; i <= b.N; i++ { 18 | _ = []byte(str) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /pcsutil/error.go: -------------------------------------------------------------------------------- 1 | package pcsutil 2 | 3 | import ( 4 | "log" 5 | "os" 6 | ) 7 | 8 | // PrintErrIfExist 简易错误处理, 如果 err 存在, 就只向屏幕输出 err 。 9 | func PrintErrIfExist(err error) { 10 | if err != nil { 11 | log.Println(err) 12 | } 13 | } 14 | 15 | // PrintErrAndExit 简易错误处理, 如果 err 存在, 向屏幕输出 err 并退出, annotate 是加在 err 之前的注释信息。 16 | func PrintErrAndExit(annotate string, err error) { 17 | if err != nil { 18 | log.Println(annotate, err) 19 | os.Exit(1) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /vendor/github.com/json-iterator/go/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | set -x 4 | 5 | if [ ! -d /tmp/build-golang/src/github.com/json-iterator ]; then 6 | mkdir -p /tmp/build-golang/src/github.com/json-iterator 7 | ln -s $PWD /tmp/build-golang/src/github.com/json-iterator/go 8 | fi 9 | export GOPATH=/tmp/build-golang 10 | go get -u github.com/golang/dep/cmd/dep 11 | cd /tmp/build-golang/src/github.com/json-iterator/go 12 | exec $GOPATH/bin/dep ensure -update 13 | -------------------------------------------------------------------------------- /vendor/github.com/shiena/ansicolor/.gitignore: -------------------------------------------------------------------------------- 1 | # Created by http://www.gitignore.io 2 | 3 | ### Go ### 4 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 5 | *.o 6 | *.a 7 | *.so 8 | 9 | # Folders 10 | _obj 11 | _test 12 | 13 | # Architecture specific extensions/prefixes 14 | *.[568vq] 15 | [568vq].out 16 | 17 | *.cgo1.go 18 | *.cgo2.c 19 | _cgo_defun.c 20 | _cgo_gotypes.go 21 | _cgo_export.* 22 | 23 | _testmain.go 24 | 25 | *.exe 26 | *.test 27 | 28 | -------------------------------------------------------------------------------- /vendor/github.com/iikira/Baidu-Login/.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.dll 4 | *.so 5 | *.dylib 6 | cmd/Baidu-Login/Baidu-Login 7 | 8 | # Test binary, build with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 15 | .glide/ 16 | 17 | # others 18 | .DS_Store 19 | test/ 20 | out/ 21 | upx.log 22 | -------------------------------------------------------------------------------- /vendor/github.com/shiena/ansicolor/ansicolor_ansi.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 shiena Authors. All rights reserved. 2 | // Use of this source code is governed by a MIT-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !windows 6 | 7 | package ansicolor 8 | 9 | import "io" 10 | 11 | type ansiColorWriter struct { 12 | w io.Writer 13 | mode outputMode 14 | } 15 | 16 | func (cw *ansiColorWriter) Write(p []byte) (int, error) { 17 | return cw.w.Write(p) 18 | } 19 | -------------------------------------------------------------------------------- /vendor/github.com/iikira/Baidu-Login/bdcrypto/bdcrypto.go: -------------------------------------------------------------------------------- 1 | package bdcrypto 2 | 3 | import ( 4 | "encoding/hex" 5 | ) 6 | 7 | // RSAEncryptOfWapBaidu 针对 WAP 登录百度的 RSA 加密 8 | func RSAEncryptOfWapBaidu(rsaPublicKeyModulus string, origData []byte) (string, error) { 9 | ciphertext, err := RSAEncryptNoPadding(rsaPublicKeyModulus, DefaultRSAPublicKeyExponent, BytesReverse(origData)) 10 | if err != nil { 11 | return "", err 12 | } 13 | 14 | return hex.EncodeToString(ciphertext), nil 15 | } 16 | -------------------------------------------------------------------------------- /vendor/github.com/GeertJohan/go.rice/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - master 5 | - 1.x.x 6 | - 1.8.x 7 | - 1.7.x 8 | - 1.6.x 9 | - 1.5.x 10 | 11 | install: 12 | - go get -t ./... 13 | - env 14 | - if [ "${TRAVIS_GO_VERSION%.*}" != "1.5" ]; then go get github.com/golang/lint/golint; fi 15 | script: 16 | - go build -x ./... 17 | - go test -cover ./... 18 | - go vet ./... 19 | - if [ "${TRAVIS_GO_VERSION%.*}" != "1.5" ]; then golint .; fi 20 | -------------------------------------------------------------------------------- /pcstable/pcstable.go: -------------------------------------------------------------------------------- 1 | // Package pcstable 格式化表格包 2 | package pcstable 3 | 4 | import ( 5 | "github.com/olekukonko/tablewriter" 6 | "io" 7 | ) 8 | 9 | // PCSTable 封装 tablewriter.Table 10 | type PCSTable struct { 11 | *tablewriter.Table 12 | } 13 | 14 | // NewTable 预设了一些配置 15 | func NewTable(wt io.Writer) PCSTable { 16 | tb := tablewriter.NewWriter(wt) 17 | tb.SetAutoWrapText(false) 18 | tb.SetBorder(false) 19 | tb.SetHeaderLine(false) 20 | tb.SetColumnSeparator("") 21 | return PCSTable{tb} 22 | } 23 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/reflect2/Gopkg.lock: -------------------------------------------------------------------------------- 1 | # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. 2 | 3 | 4 | [[projects]] 5 | name = "github.com/modern-go/concurrent" 6 | packages = ["."] 7 | revision = "e0a39a4cb4216ea8db28e22a69f4ec25610d513a" 8 | version = "1.0.0" 9 | 10 | [solve-meta] 11 | analyzer-name = "dep" 12 | analyzer-version = 1 13 | inputs-digest = "daee8a88b3498b61c5640056665b8b9eea062006f5e596bbb6a3ed9119a11ec7" 14 | solver-name = "gps-cdcl" 15 | solver-version = 1 16 | -------------------------------------------------------------------------------- /internal/pcscommand/quota.go: -------------------------------------------------------------------------------- 1 | package pcscommand 2 | 3 | import ( 4 | "fmt" 5 | "github.com/iikira/BaiduPCS-Go/pcsutil/converter" 6 | ) 7 | 8 | // RunGetQuota 执行 获取当前用户空间配额信息, 并输出 9 | func RunGetQuota() { 10 | quota, used, err := GetBaiduPCS().QuotaInfo() 11 | if err != nil { 12 | fmt.Println(err) 13 | return 14 | } 15 | fmt.Printf("用户名: %s, 总空间: %s, 已用空间: %s, 比率: %f%%\n", 16 | GetActiveUser().Name, 17 | converter.ConvertFileSize(quota), 18 | converter.ConvertFileSize(used), 19 | 100*float64(used)/float64(quota), 20 | ) 21 | } 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.dll 4 | *.so 5 | *.dylib 6 | BaiduPCS-Go 7 | 8 | # Test binary, build with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | out/ 14 | *.dl 15 | 16 | # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 17 | .glide/ 18 | 19 | # Others 20 | .DS_Store 21 | *.proc 22 | *.txt 23 | *.log 24 | captcha.png 25 | pcs_config.json 26 | test/ 27 | download/ 28 | *-downloading 29 | 30 | # GoLand 31 | .idea/ -------------------------------------------------------------------------------- /vendor/github.com/iikira/baidu-tools/tieba/tieba.go: -------------------------------------------------------------------------------- 1 | package tieba 2 | 3 | import ( 4 | "github.com/iikira/baidu-tools" 5 | ) 6 | 7 | // Tieba 百度贴吧账号详细情况 8 | type Tieba struct { 9 | Baidu *baidu.Baidu 10 | Tbs string 11 | Stat *Stat 12 | Bars []*Bar //要执行任务的贴吧列表 13 | } 14 | 15 | //Bar 贴吧详情 16 | type Bar struct { 17 | FID string // 贴吧fid 18 | Name string // 名字 19 | Level string // 个人等级 20 | Exp int // 个人经验 21 | } 22 | 23 | // Stat 统计数据 24 | type Stat struct { 25 | LikeForumNum int // 关注的贴吧数 26 | PostNum int // 发言次数 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/iikira/Baidu-Login/bdcrypto/reverse.go: -------------------------------------------------------------------------------- 1 | package bdcrypto 2 | 3 | import ( 4 | "unsafe" 5 | ) 6 | 7 | // BytesReverse 反转字节数组, 此操作会修改原值 8 | func BytesReverse(b []byte) []byte { 9 | length := len(b) 10 | for i := 0; i < length/2; i++ { 11 | b[i], b[length-i-1] = b[length-i-1], b[i] 12 | } 13 | return b 14 | } 15 | 16 | // StringReverse 反转字符串, 此操作不会修改原值 17 | func StringReverse(s string) string { 18 | newBytes := make([]byte, len(s)) 19 | copy(newBytes, s) 20 | b := BytesReverse(newBytes) 21 | return *(*string)(unsafe.Pointer(&b)) 22 | } 23 | -------------------------------------------------------------------------------- /internal/pcsweb/static/css/main.css: -------------------------------------------------------------------------------- 1 | @charset "utf-8"; 2 | 3 | #logo { 4 | display: none; 5 | } 6 | 7 | @media (max-width: 767px) { 8 | #logo { 9 | display: inline; 10 | } 11 | } 12 | 13 | .navbar.navbar-inverse { 14 | border: 0; 15 | box-shadow: 0 0 10px #000; 16 | background-color: rgba(255, 149, 117, 0.8); 17 | } 18 | 19 | header a { 20 | color: #000 !important; 21 | } 22 | 23 | .directory-list-header { 24 | font-family: "Microsoft YaHei", 微软雅黑, 黑体, 宋体, sans-serif; 25 | font-weight: bold; 26 | padding: 10px 15px; 27 | } -------------------------------------------------------------------------------- /requester/requester.go: -------------------------------------------------------------------------------- 1 | // Package requester 提供网络请求简便操作 2 | package requester 3 | 4 | var ( 5 | // UserAgent 浏览器标识 6 | UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36" 7 | 8 | // DefaultClient 默认 http 客户端 9 | DefaultClient = NewHTTPClient() 10 | ) 11 | 12 | // ContentTyper Content-Type 接口 13 | type ContentTyper interface { 14 | ContentType() string 15 | } 16 | 17 | // ContentLengther Content-Length 接口 18 | type ContentLengther interface { 19 | ContentLength() int64 20 | } 21 | -------------------------------------------------------------------------------- /vendor/github.com/kardianos/osext/osext_plan9.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //+build !go1.8 6 | 7 | package osext 8 | 9 | import ( 10 | "os" 11 | "strconv" 12 | "syscall" 13 | ) 14 | 15 | func executable() (string, error) { 16 | f, err := os.Open("/proc/" + strconv.Itoa(os.Getpid()) + "/text") 17 | if err != nil { 18 | return "", err 19 | } 20 | defer f.Close() 21 | return syscall.Fd2path(int(f.Fd())) 22 | } 23 | -------------------------------------------------------------------------------- /vendor/github.com/urfave/cli/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | sudo: false 3 | dist: trusty 4 | osx_image: xcode8.3 5 | go: 1.8.x 6 | 7 | os: 8 | - linux 9 | - osx 10 | 11 | cache: 12 | directories: 13 | - node_modules 14 | 15 | before_script: 16 | - go get github.com/urfave/gfmrun/... || true 17 | - go get golang.org/x/tools/cmd/goimports 18 | - if [ ! -f node_modules/.bin/markdown-toc ] ; then 19 | npm install markdown-toc ; 20 | fi 21 | 22 | script: 23 | - ./runtests gen 24 | - ./runtests vet 25 | - ./runtests test 26 | - ./runtests gfmrun 27 | - ./runtests toc 28 | -------------------------------------------------------------------------------- /vendor/github.com/mattn/go-runewidth/runewidth_windows.go: -------------------------------------------------------------------------------- 1 | package runewidth 2 | 3 | import ( 4 | "syscall" 5 | ) 6 | 7 | var ( 8 | kernel32 = syscall.NewLazyDLL("kernel32") 9 | procGetConsoleOutputCP = kernel32.NewProc("GetConsoleOutputCP") 10 | ) 11 | 12 | // IsEastAsian return true if the current locale is CJK 13 | func IsEastAsian() bool { 14 | r1, _, _ := procGetConsoleOutputCP.Call() 15 | if r1 == 0 { 16 | return false 17 | } 18 | 19 | switch int(r1) { 20 | case 932, 51932, 936, 949, 950: 21 | return true 22 | } 23 | 24 | return false 25 | } 26 | -------------------------------------------------------------------------------- /vendor/github.com/peterh/liner/input_linux.go: -------------------------------------------------------------------------------- 1 | // +build linux 2 | 3 | package liner 4 | 5 | import "syscall" 6 | 7 | const ( 8 | getTermios = syscall.TCGETS 9 | setTermios = syscall.TCSETS 10 | ) 11 | 12 | const ( 13 | icrnl = syscall.ICRNL 14 | inpck = syscall.INPCK 15 | istrip = syscall.ISTRIP 16 | ixon = syscall.IXON 17 | opost = syscall.OPOST 18 | cs8 = syscall.CS8 19 | isig = syscall.ISIG 20 | icanon = syscall.ICANON 21 | iexten = syscall.IEXTEN 22 | ) 23 | 24 | type termios struct { 25 | syscall.Termios 26 | } 27 | 28 | const cursorColumn = false 29 | -------------------------------------------------------------------------------- /pcsutil/addr.go: -------------------------------------------------------------------------------- 1 | package pcsutil 2 | 3 | import ( 4 | "net" 5 | ) 6 | 7 | // ListAddresses 列出本地可用的 IP 地址 8 | func ListAddresses() (addresses []string) { 9 | ifaces, _ := net.Interfaces() 10 | addresses = make([]string, 0, len(ifaces)) 11 | for k := range ifaces[:] { 12 | ifAddrs, _ := ifaces[k].Addrs() 13 | for l := range ifAddrs[:] { 14 | switch v := ifAddrs[l].(type) { 15 | case *net.IPNet: 16 | addresses = append(addresses, v.IP.String()) 17 | case *net.IPAddr: 18 | addresses = append(addresses, v.IP.String()) 19 | } 20 | } 21 | } 22 | return 23 | } 24 | -------------------------------------------------------------------------------- /internal/pcscommand/pcscommand.go: -------------------------------------------------------------------------------- 1 | // Package pcscommand 命令包 2 | package pcscommand 3 | 4 | import ( 5 | "github.com/iikira/BaiduPCS-Go/baidupcs" 6 | "github.com/iikira/BaiduPCS-Go/internal/pcsconfig" 7 | "github.com/iikira/BaiduPCS-Go/pcsverbose" 8 | ) 9 | 10 | var ( 11 | pcsCommandVerbose = pcsverbose.New("PCSCOMMAND") 12 | ) 13 | 14 | // GetActiveUser 获取当前登录的百度帐号 15 | func GetActiveUser() *pcsconfig.Baidu { 16 | return pcsconfig.Config.ActiveUser() 17 | } 18 | 19 | // GetBaiduPCS 从配置读取BaiduPCS 20 | func GetBaiduPCS() *baidupcs.BaiduPCS { 21 | return pcsconfig.Config.ActiveUserBaiduPCS() 22 | } 23 | -------------------------------------------------------------------------------- /pcsutil/getip/getip.go: -------------------------------------------------------------------------------- 1 | // Package getip 获取 ip 信息包 2 | package getip 3 | 4 | import ( 5 | "github.com/iikira/BaiduPCS-Go/requester" 6 | "unsafe" 7 | ) 8 | 9 | //IPInfo 获取IP地址和IP位置 10 | func IPInfo(https bool) (ipAddr string, err error) { 11 | c := requester.NewHTTPClient() 12 | c.SetHTTPSecure(https) 13 | 14 | var scheme string 15 | if https { 16 | scheme = "https" 17 | } else { 18 | scheme = "http" 19 | } 20 | 21 | body, err := c.Fetch("GET", scheme+"://api.ipify.org", nil, nil) 22 | if err != nil { 23 | return "", err 24 | } 25 | 26 | return *(*string)(unsafe.Pointer(&body)), nil 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/urfave/cli/appveyor.yml: -------------------------------------------------------------------------------- 1 | version: "{build}" 2 | 3 | os: Windows Server 2016 4 | 5 | image: Visual Studio 2017 6 | 7 | clone_folder: c:\gopath\src\github.com\urfave\cli 8 | 9 | environment: 10 | GOPATH: C:\gopath 11 | GOVERSION: 1.8.x 12 | PYTHON: C:\Python36-x64 13 | PYTHON_VERSION: 3.6.x 14 | PYTHON_ARCH: 64 15 | 16 | install: 17 | - set PATH=%GOPATH%\bin;C:\go\bin;%PATH% 18 | - go version 19 | - go env 20 | - go get github.com/urfave/gfmrun/... 21 | - go get -v -t ./... 22 | 23 | build_script: 24 | - python runtests vet 25 | - python runtests test 26 | - python runtests gfmrun 27 | -------------------------------------------------------------------------------- /vendor/github.com/GeertJohan/go.rice/http.go: -------------------------------------------------------------------------------- 1 | package rice 2 | 3 | import ( 4 | "net/http" 5 | ) 6 | 7 | // HTTPBox implements http.FileSystem which allows the use of Box with a http.FileServer. 8 | // e.g.: http.Handle("/", http.FileServer(rice.MustFindBox("http-files").HTTPBox())) 9 | type HTTPBox struct { 10 | *Box 11 | } 12 | 13 | // HTTPBox creates a new HTTPBox from an existing Box 14 | func (b *Box) HTTPBox() *HTTPBox { 15 | return &HTTPBox{b} 16 | } 17 | 18 | // Open returns a File using the http.File interface 19 | func (hb *HTTPBox) Open(name string) (http.File, error) { 20 | return hb.Box.Open(name) 21 | } 22 | -------------------------------------------------------------------------------- /vendor/github.com/astaxie/beego/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2014 astaxie 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /pcsutil/log_colorable_prefix.go: -------------------------------------------------------------------------------- 1 | package pcsutil 2 | 3 | import ( 4 | "fmt" 5 | "github.com/fatih/color" 6 | "github.com/iikira/BaiduPCS-Go/pcsutil/pcstime" 7 | "log" 8 | ) 9 | 10 | var ( 11 | // ErrorColor 设置输出错误的颜色 12 | ErrorColor = color.New(color.FgRed).SprintFunc() 13 | ) 14 | 15 | // 自定义log writer 16 | type logWriter struct{} 17 | 18 | func (logWriter) Write(bytes []byte) (int, error) { 19 | return fmt.Fprint(color.Output, "["+pcstime.BeijingTimeOption("Refer")+"] "+string(bytes)) 20 | } 21 | 22 | // SetLogPrefix 设置日志输出的时间前缀 23 | func SetLogPrefix() { 24 | log.SetFlags(0) 25 | log.SetOutput(new(logWriter)) 26 | } 27 | -------------------------------------------------------------------------------- /internal/pcsconfig/errors.go: -------------------------------------------------------------------------------- 1 | package pcsconfig 2 | 3 | import ( 4 | "errors" 5 | ) 6 | 7 | var ( 8 | //ErrNotLogin 未登录帐号错误 9 | ErrNotLogin = errors.New("baidu user not login") 10 | //ErrConfigFilePathNotSet 未设置配置文件 11 | ErrConfigFilePathNotSet = errors.New("config file not set") 12 | //ErrConfigFileNotExist 未设置Config, 未初始化 13 | ErrConfigFileNotExist = errors.New("config file not exist") 14 | //ErrConfigFileNoPermission Config文件无权限访问 15 | ErrConfigFileNoPermission = errors.New("config file permission denied") 16 | //ErrConfigContentsParseError 解析Config数据错误 17 | ErrConfigContentsParseError = errors.New("config contents parse error") 18 | ) 19 | -------------------------------------------------------------------------------- /vendor/github.com/iikira/Baidu-Login/bdcrypto/base64.go: -------------------------------------------------------------------------------- 1 | package bdcrypto 2 | 3 | import ( 4 | "bytes" 5 | "encoding/base64" 6 | "io/ioutil" 7 | ) 8 | 9 | // Base64Encode base64加密 10 | func Base64Encode(raw []byte) []byte { 11 | var encoded bytes.Buffer 12 | encoder := base64.NewEncoder(base64.StdEncoding, &encoded) 13 | encoder.Write(raw) 14 | encoder.Close() 15 | return encoded.Bytes() 16 | } 17 | 18 | // Base64Decode base64解密 19 | func Base64Decode(raw []byte) []byte { 20 | var buf bytes.Buffer 21 | buf.Write(raw) 22 | decoder := base64.NewDecoder(base64.StdEncoding, &buf) 23 | decoded, _ := ioutil.ReadAll(decoder) 24 | return decoded 25 | } 26 | -------------------------------------------------------------------------------- /internal/pcsweb/pcsfile.go: -------------------------------------------------------------------------------- 1 | package pcsweb 2 | 3 | import ( 4 | "github.com/iikira/BaiduPCS-Go/baidupcs" 5 | "github.com/iikira/BaiduPCS-Go/internal/pcsconfig" 6 | "io" 7 | "net/http" 8 | ) 9 | 10 | func fileList(w http.ResponseWriter, r *http.Request) { 11 | r.ParseForm() 12 | 13 | fpath := r.Form.Get("path") 14 | dataReadCloser, err := pcsconfig.Config.ActiveUserBaiduPCS().PrepareFilesDirectoriesList(fpath, baidupcs.DefaultOrderOptions) 15 | if err != nil { 16 | w.Write((&ErrInfo{ 17 | ErrroCode: 1, 18 | ErrorMsg: err.Error(), 19 | }).JSON()) 20 | return 21 | } 22 | 23 | defer dataReadCloser.Close() 24 | io.Copy(w, dataReadCloser) 25 | } 26 | -------------------------------------------------------------------------------- /requester/rio/buf.go: -------------------------------------------------------------------------------- 1 | package rio 2 | 3 | import ( 4 | "unsafe" 5 | ) 6 | 7 | // Buffer 为固定长度的 Buf, 实现 io.WriterAt 接口 8 | type Buffer struct { 9 | Buf []byte 10 | } 11 | 12 | // NewBuffer 初始化 Buffer 13 | func NewBuffer(buf []byte) *Buffer { 14 | return &Buffer{ 15 | Buf: buf, 16 | } 17 | } 18 | 19 | // WriteAt 实现 io.WriterAt 接口 20 | // 不进行越界检查 21 | func (b *Buffer) WriteAt(p []byte, off int64) (n int, err error) { 22 | n = copy(b.Buf[off:], p) 23 | return n, nil 24 | } 25 | 26 | // Bytes 返回 buf 27 | func (b *Buffer) Bytes() []byte { 28 | return b.Buf 29 | } 30 | 31 | func (b *Buffer) String() string { 32 | return *(*string)(unsafe.Pointer(&b.Buf)) 33 | } 34 | -------------------------------------------------------------------------------- /Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleName 6 | BaiduPCS-Go 7 | CFBundleSupportedPlatforms 8 | 9 | iPhoneOS 10 | 11 | CFBundleExecutable 12 | BaiduPCS-Go 13 | CFBundleVersion 14 | 1.0 15 | CFBundleIdentifier 16 | com.iikira.baidupcsgo 17 | LSRequiresIPhoneOS 18 | 19 | CFBundleDisplayName 20 | BaiduPCS-Go 21 | 22 | -------------------------------------------------------------------------------- /internal/pcsweb/errors.go: -------------------------------------------------------------------------------- 1 | package pcsweb 2 | 3 | import ( 4 | "fmt" 5 | "github.com/json-iterator/go" 6 | ) 7 | 8 | // ErrInfo web 错误详情 9 | type ErrInfo struct { 10 | ErrroCode int `json:"error_code"` 11 | ErrorMsg string `json:"error_msg"` 12 | } 13 | 14 | func (ei *ErrInfo) Error() string { 15 | return fmt.Sprintf("error code: %d, error message: %s", ei.ErrroCode, ei.ErrorMsg) 16 | } 17 | 18 | // JSON 将错误信息打包成 json 19 | func (ei *ErrInfo) JSON() (data []byte) { 20 | var err error 21 | data, err = jsoniter.MarshalIndent(ei, "", " ") 22 | checkErr(err) 23 | 24 | return 25 | } 26 | 27 | // checkErr 遇到错误就退出 28 | func checkErr(err error) { 29 | if err != nil { 30 | panic(err) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /baidupcs/rm_mkdir.go: -------------------------------------------------------------------------------- 1 | package baidupcs 2 | 3 | // Remove 批量删除文件/目录 4 | func (pcs *BaiduPCS) Remove(paths ...string) (pcsError Error) { 5 | dataReadCloser, pcsError := pcs.PrepareRemove(paths...) 6 | if pcsError != nil { 7 | return 8 | } 9 | 10 | defer dataReadCloser.Close() 11 | 12 | errInfo := decodeJSONError(OperationRemove, dataReadCloser) 13 | return errInfo 14 | } 15 | 16 | // Mkdir 创建目录 17 | func (pcs *BaiduPCS) Mkdir(pcspath string) (pcsError Error) { 18 | dataReadCloser, pcsError := pcs.PrepareMkdir(pcspath) 19 | if pcsError != nil { 20 | return 21 | } 22 | 23 | defer dataReadCloser.Close() 24 | 25 | errInfo := decodeJSONError(OperationMkdir, dataReadCloser) 26 | return errInfo 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/concurrent/executor.go: -------------------------------------------------------------------------------- 1 | package concurrent 2 | 3 | import "context" 4 | 5 | // Executor replace go keyword to start a new goroutine 6 | // the goroutine should cancel itself if the context passed in has been cancelled 7 | // the goroutine started by the executor, is owned by the executor 8 | // we can cancel all executors owned by the executor just by stop the executor itself 9 | // however Executor interface does not Stop method, the one starting and owning executor 10 | // should use the concrete type of executor, instead of this interface. 11 | type Executor interface { 12 | // Go starts a new goroutine controlled by the context 13 | Go(handler func(ctx context.Context)) 14 | } 15 | -------------------------------------------------------------------------------- /vendor/github.com/json-iterator/go/Gopkg.lock: -------------------------------------------------------------------------------- 1 | # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. 2 | 3 | 4 | [[projects]] 5 | name = "github.com/modern-go/concurrent" 6 | packages = ["."] 7 | revision = "e0a39a4cb4216ea8db28e22a69f4ec25610d513a" 8 | version = "1.0.0" 9 | 10 | [[projects]] 11 | name = "github.com/modern-go/reflect2" 12 | packages = ["."] 13 | revision = "1df9eeb2bb81f327b96228865c5687bc2194af3f" 14 | version = "1.0.0" 15 | 16 | [solve-meta] 17 | analyzer-name = "dep" 18 | analyzer-version = 1 19 | inputs-digest = "ac7003b5a981716353a43055ab7d4c5357403cb30a60de2dbdeb446c1544beaa" 20 | solver-name = "gps-cdcl" 21 | solver-version = 1 22 | -------------------------------------------------------------------------------- /pcsverbose/pcsdebug/cpu.go: -------------------------------------------------------------------------------- 1 | // Package pcsdebug 调试包 2 | package pcsdebug 3 | 4 | import ( 5 | "context" 6 | "fmt" 7 | "os" 8 | "runtime/pprof" 9 | ) 10 | 11 | //StartCPUProfile 收集cpu信息 12 | func StartCPUProfile(ctx context.Context, cpuProfile string) { 13 | if cpuProfile != "" { 14 | f, err := os.Create(cpuProfile) 15 | if err != nil { 16 | fmt.Fprintf(os.Stderr, "Can not create cpu profile output file: %s", err) 17 | return 18 | } 19 | if err := pprof.StartCPUProfile(f); err != nil { 20 | fmt.Fprintf(os.Stderr, "Can not start cpu profile: %s", err) 21 | f.Close() 22 | return 23 | } 24 | defer pprof.StopCPUProfile() 25 | } 26 | select { 27 | case <-ctx.Done(): 28 | return 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /vendor/github.com/iikira/baidu-tools/randominfo/phone.go: -------------------------------------------------------------------------------- 1 | package randominfo 2 | 3 | // SumIMEI 根据key计算出imei 4 | func SumIMEI(key string) uint64 { 5 | var hash uint64 = 53202347234687234 6 | for k := range key { 7 | hash += (hash << 5) + uint64(key[k]) 8 | } 9 | hash %= uint64(1e15) 10 | if hash < 1e14 { 11 | hash += 1e14 12 | } 13 | return hash 14 | } 15 | 16 | // GetPhoneModel 根据key, 从PhoneModelDataBase中取出手机型号 17 | func GetPhoneModel(key string) string { 18 | if len(PhoneModelDataBase) <= 0 { 19 | return "S3" 20 | } 21 | var hash uint64 = 2134 22 | for k := range key { 23 | hash += (hash << 4) + uint64(key[k]) 24 | } 25 | hash %= uint64(len(PhoneModelDataBase)) 26 | return PhoneModelDataBase[int(hash)] 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/astaxie/beego/utils/utils.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "os" 5 | "path/filepath" 6 | "runtime" 7 | "strings" 8 | ) 9 | 10 | // GetGOPATHs returns all paths in GOPATH variable. 11 | func GetGOPATHs() []string { 12 | gopath := os.Getenv("GOPATH") 13 | if gopath == "" && strings.Compare(runtime.Version(), "go1.8") >= 0 { 14 | gopath = defaultGOPATH() 15 | } 16 | return filepath.SplitList(gopath) 17 | } 18 | 19 | func defaultGOPATH() string { 20 | env := "HOME" 21 | if runtime.GOOS == "windows" { 22 | env = "USERPROFILE" 23 | } else if runtime.GOOS == "plan9" { 24 | env = "home" 25 | } 26 | if home := os.Getenv(env); home != "" { 27 | return filepath.Join(home, "go") 28 | } 29 | return "" 30 | } 31 | -------------------------------------------------------------------------------- /vendor/github.com/peterh/liner/bsdinput.go: -------------------------------------------------------------------------------- 1 | // +build openbsd freebsd netbsd 2 | 3 | package liner 4 | 5 | import "syscall" 6 | 7 | const ( 8 | getTermios = syscall.TIOCGETA 9 | setTermios = syscall.TIOCSETA 10 | ) 11 | 12 | const ( 13 | // Input flags 14 | inpck = 0x010 15 | istrip = 0x020 16 | icrnl = 0x100 17 | ixon = 0x200 18 | 19 | // Output flags 20 | opost = 0x1 21 | 22 | // Control flags 23 | cs8 = 0x300 24 | 25 | // Local flags 26 | isig = 0x080 27 | icanon = 0x100 28 | iexten = 0x400 29 | ) 30 | 31 | type termios struct { 32 | Iflag uint32 33 | Oflag uint32 34 | Cflag uint32 35 | Lflag uint32 36 | Cc [20]byte 37 | Ispeed int32 38 | Ospeed int32 39 | } 40 | 41 | const cursorColumn = false 42 | -------------------------------------------------------------------------------- /pcspath/match.go: -------------------------------------------------------------------------------- 1 | package pcspath 2 | 3 | import ( 4 | "path" 5 | ) 6 | 7 | // AbsPathNoMatch 返回绝对路径, 不检测通配符 8 | func (pp *PCSPath) AbsPathNoMatch() string { 9 | pp.CleanPath() 10 | if !path.IsAbs(pp.SubPath) { 11 | return path.Clean(*pp.WorkdirDestination + "/" + pp.SubPath) 12 | } 13 | return pp.SubPath 14 | } 15 | 16 | // Match 检测 pcspaths 的通配符, 返回匹配成功的 matchedPCSPaths 17 | func (pp *PCSPath) Match(pcspaths ...string) (matchedPCSPaths []string) { 18 | pattern := pp.AbsPathNoMatch() // 获取绝对路径 19 | 20 | for k := range pcspaths { 21 | matched, _ := path.Match(pattern, pcspaths[k]) 22 | if !matched { 23 | continue 24 | } 25 | 26 | matchedPCSPaths = append(matchedPCSPaths, pcspaths[k]) 27 | } 28 | 29 | return matchedPCSPaths 30 | } 31 | -------------------------------------------------------------------------------- /requester/rio/file.go: -------------------------------------------------------------------------------- 1 | package rio 2 | 3 | import ( 4 | "os" 5 | "sync/atomic" 6 | ) 7 | 8 | // NewFileReaderLen64 *os.File 实现 ReadedLen64 接口 9 | func NewFileReaderLen64(f *os.File) ReaderLen64 { 10 | if f == nil { 11 | return nil 12 | } 13 | 14 | return &fileReadedlen64{ 15 | f: f, 16 | } 17 | } 18 | 19 | type fileReadedlen64 struct { 20 | readed int64 21 | f *os.File 22 | } 23 | 24 | // Read 读文件, 并记录已读取数据量 25 | func (fr *fileReadedlen64) Read(b []byte) (n int, err error) { 26 | n, err = fr.f.Read(b) 27 | atomic.AddInt64(&fr.readed, int64(n)) 28 | return n, err 29 | } 30 | 31 | // Len 返回文件的大小 32 | func (fr *fileReadedlen64) Len() int64 { 33 | info, err := fr.f.Stat() 34 | if err != nil { 35 | return 0 36 | } 37 | return info.Size() - fr.readed 38 | } 39 | -------------------------------------------------------------------------------- /requester/uploader/readed.go: -------------------------------------------------------------------------------- 1 | package uploader 2 | 3 | import ( 4 | "github.com/iikira/BaiduPCS-Go/requester/rio" 5 | "sync/atomic" 6 | ) 7 | 8 | // Readed64 增加获取已读取数据量, 用于统计速度 9 | type Readed64 interface { 10 | rio.ReaderLen64 11 | Readed() int64 12 | } 13 | 14 | // NewReaded64 实现Readed64接口 15 | func NewReaded64(rl rio.ReaderLen64) Readed64 { 16 | return &readed64{ 17 | readed: 0, 18 | ReaderLen64: rl, 19 | } 20 | } 21 | 22 | type readed64 struct { 23 | readed int64 24 | rio.ReaderLen64 25 | } 26 | 27 | func (r64 *readed64) Read(p []byte) (n int, err error) { 28 | n, err = r64.ReaderLen64.Read(p) 29 | atomic.AddInt64(&r64.readed, int64(n)) 30 | return n, err 31 | } 32 | 33 | func (r64 *readed64) Readed() int64 { 34 | return atomic.LoadInt64(&r64.readed) 35 | } 36 | -------------------------------------------------------------------------------- /BaiduPCS-Go.exe.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | true 12 | 13 | 14 | -------------------------------------------------------------------------------- /internal/pcscommand/cd.go: -------------------------------------------------------------------------------- 1 | package pcscommand 2 | 3 | import ( 4 | "fmt" 5 | "github.com/iikira/BaiduPCS-Go/baidupcs" 6 | "github.com/iikira/BaiduPCS-Go/internal/pcsconfig" 7 | ) 8 | 9 | // RunChangeDirectory 执行更改工作目录 10 | func RunChangeDirectory(path string, isList bool) { 11 | path, err := getAbsPath(path) 12 | if err != nil { 13 | fmt.Println(err) 14 | return 15 | } 16 | 17 | data, err := GetBaiduPCS().FilesDirectoriesMeta(path) 18 | if err != nil { 19 | fmt.Println(err) 20 | return 21 | } 22 | 23 | if !data.Isdir { 24 | fmt.Printf("错误: %s 不是一个目录 (文件夹)\n", path) 25 | return 26 | } 27 | 28 | GetActiveUser().Workdir = path 29 | pcsconfig.Config.Save() 30 | 31 | fmt.Printf("改变工作目录: %s\n", path) 32 | 33 | if isList { 34 | RunLs(".", nil, baidupcs.DefaultOrderOptions) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/concurrent/go_below_19.go: -------------------------------------------------------------------------------- 1 | //+build !go1.9 2 | 3 | package concurrent 4 | 5 | import "sync" 6 | 7 | // Map implements a thread safe map for go version below 1.9 using mutex 8 | type Map struct { 9 | lock sync.RWMutex 10 | data map[interface{}]interface{} 11 | } 12 | 13 | // NewMap creates a thread safe map 14 | func NewMap() *Map { 15 | return &Map{ 16 | data: make(map[interface{}]interface{}, 32), 17 | } 18 | } 19 | 20 | // Load is same as sync.Map Load 21 | func (m *Map) Load(key interface{}) (elem interface{}, found bool) { 22 | m.lock.RLock() 23 | elem, found = m.data[key] 24 | m.lock.RUnlock() 25 | return 26 | } 27 | 28 | // Load is same as sync.Map Store 29 | func (m *Map) Store(key interface{}, elem interface{}) { 30 | m.lock.Lock() 31 | m.data[key] = elem 32 | m.lock.Unlock() 33 | } 34 | -------------------------------------------------------------------------------- /vendor/github.com/urfave/cli/cli.go: -------------------------------------------------------------------------------- 1 | // Package cli provides a minimal framework for creating and organizing command line 2 | // Go applications. cli is designed to be easy to understand and write, the most simple 3 | // cli application can be written as follows: 4 | // func main() { 5 | // cli.NewApp().Run(os.Args) 6 | // } 7 | // 8 | // Of course this application does not do much, so let's make this an actual application: 9 | // func main() { 10 | // app := cli.NewApp() 11 | // app.Name = "greet" 12 | // app.Usage = "say a greeting" 13 | // app.Action = func(c *cli.Context) error { 14 | // println("Greetings") 15 | // return nil 16 | // } 17 | // 18 | // app.Run(os.Args) 19 | // } 20 | package cli 21 | 22 | //go:generate python ./generate-flag-types cli -i flag-types.json -o flag_generated.go 23 | -------------------------------------------------------------------------------- /vendor/github.com/peterh/liner/input_darwin.go: -------------------------------------------------------------------------------- 1 | // +build darwin 2 | 3 | package liner 4 | 5 | import "syscall" 6 | 7 | const ( 8 | getTermios = syscall.TIOCGETA 9 | setTermios = syscall.TIOCSETA 10 | ) 11 | 12 | const ( 13 | // Input flags 14 | inpck = 0x010 15 | istrip = 0x020 16 | icrnl = 0x100 17 | ixon = 0x200 18 | 19 | // Output flags 20 | opost = 0x1 21 | 22 | // Control flags 23 | cs8 = 0x300 24 | 25 | // Local flags 26 | isig = 0x080 27 | icanon = 0x100 28 | iexten = 0x400 29 | ) 30 | 31 | type termios struct { 32 | Iflag uintptr 33 | Oflag uintptr 34 | Cflag uintptr 35 | Lflag uintptr 36 | Cc [20]byte 37 | Ispeed uintptr 38 | Ospeed uintptr 39 | } 40 | 41 | // Terminal.app needs a column for the cursor when the input line is at the 42 | // bottom of the window. 43 | const cursorColumn = true 44 | -------------------------------------------------------------------------------- /vendor/github.com/kardianos/osext/README.md: -------------------------------------------------------------------------------- 1 | ### Extensions to the "os" package. 2 | 3 | [![GoDoc](https://godoc.org/github.com/kardianos/osext?status.svg)](https://godoc.org/github.com/kardianos/osext) 4 | 5 | ## Find the current Executable and ExecutableFolder. 6 | 7 | As of go1.8 the Executable function may be found in `os`. The Executable function 8 | in the std lib `os` package is used if available. 9 | 10 | There is sometimes utility in finding the current executable file 11 | that is running. This can be used for upgrading the current executable 12 | or finding resources located relative to the executable file. Both 13 | working directory and the os.Args[0] value are arbitrary and cannot 14 | be relied on; os.Args[0] can be "faked". 15 | 16 | Multi-platform and supports: 17 | * Linux 18 | * OS X 19 | * Windows 20 | * Plan 9 21 | * BSDs. 22 | -------------------------------------------------------------------------------- /vendor/github.com/json-iterator/go/Gopkg.toml: -------------------------------------------------------------------------------- 1 | # Gopkg.toml example 2 | # 3 | # Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md 4 | # for detailed Gopkg.toml documentation. 5 | # 6 | # required = ["github.com/user/thing/cmd/thing"] 7 | # ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] 8 | # 9 | # [[constraint]] 10 | # name = "github.com/user/project" 11 | # version = "1.0.0" 12 | # 13 | # [[constraint]] 14 | # name = "github.com/user/project2" 15 | # branch = "dev" 16 | # source = "github.com/myfork/project2" 17 | # 18 | # [[override]] 19 | # name = "github.com/x/y" 20 | # version = "2.4.0" 21 | 22 | ignored = ["github.com/davecgh/go-spew*","github.com/google/gofuzz*","github.com/stretchr/testify*"] 23 | 24 | [[constraint]] 25 | name = "github.com/modern-go/reflect2" 26 | version = "1.0.0" 27 | -------------------------------------------------------------------------------- /requester/downloader/config.go: -------------------------------------------------------------------------------- 1 | package downloader 2 | 3 | const ( 4 | //CacheSize 默认的下载缓存 5 | CacheSize = 8192 6 | ) 7 | 8 | var ( 9 | // MinParallelSize 单个线程最小的数据量 10 | MinParallelSize int64 = 128 * 1024 // 128kb 11 | ) 12 | 13 | //Config 下载配置 14 | type Config struct { 15 | MaxParallel int // 最大下载并发量 16 | CacheSize int // 下载缓冲 17 | InstanceStatePath string // 断点续传信息路径 18 | IsTest bool // 是否测试下载 19 | cacheSize int // 实际下载缓存 20 | parallel int // 实际的下载并行量 21 | } 22 | 23 | //NewConfig 返回默认配置 24 | func NewConfig() *Config { 25 | return &Config{ 26 | MaxParallel: 5, 27 | CacheSize: CacheSize, 28 | IsTest: false, 29 | } 30 | } 31 | 32 | //Fix 修复配置信息, 使其合法 33 | func (cfg *Config) Fix() { 34 | fixCacheSize(&cfg.CacheSize) 35 | if cfg.MaxParallel < 1 { 36 | cfg.MaxParallel = 1 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /baidupcs/cp_mv_rename.go: -------------------------------------------------------------------------------- 1 | package baidupcs 2 | 3 | // Rename 重命名文件/目录 4 | func (pcs *BaiduPCS) Rename(from, to string) (pcsError Error) { 5 | return pcs.cpmvOp(OperationRename, &CpMvJSON{ 6 | From: from, 7 | To: to, 8 | }) 9 | } 10 | 11 | // Copy 批量拷贝文件/目录 12 | func (pcs *BaiduPCS) Copy(cpmvJSON ...*CpMvJSON) (pcsError Error) { 13 | return pcs.cpmvOp(OperationCopy, cpmvJSON...) 14 | } 15 | 16 | // Move 批量移动文件/目录 17 | func (pcs *BaiduPCS) Move(cpmvJSON ...*CpMvJSON) (pcsError Error) { 18 | return pcs.cpmvOp(OperationMove, cpmvJSON...) 19 | } 20 | 21 | func (pcs *BaiduPCS) cpmvOp(op string, cpmvJSON ...*CpMvJSON) (pcsError Error) { 22 | dataReadCloser, err := pcs.prepareCpMvOp(op, cpmvJSON...) 23 | if err != nil { 24 | return 25 | } 26 | 27 | defer dataReadCloser.Close() 28 | 29 | errInfo := decodeJSONError(op, dataReadCloser) 30 | return errInfo 31 | } 32 | -------------------------------------------------------------------------------- /vendor/github.com/iikira/Baidu-Login/http_server_page.go: -------------------------------------------------------------------------------- 1 | package baidulogin 2 | 3 | import ( 4 | "log" 5 | "net/http" 6 | "text/template" 7 | ) 8 | 9 | func indexPage(w http.ResponseWriter, r *http.Request) { 10 | sess, _ := globalSessions.SessionStart(w, r) // session start 11 | registerBaiduClient(&sess) // 如果没有 baiduClient , 就添加 12 | 13 | // get file contents as string 14 | contents, err := templateFilesBox.String("index.html") 15 | if err != nil { 16 | log.Println(err) 17 | return 18 | } 19 | tmpl, err := template.New("index.html").Parse(contents) 20 | if err != nil { 21 | panic(err) 22 | } 23 | 24 | err = tmpl.Execute(w, Version) 25 | if err != nil { 26 | panic(err) 27 | } 28 | } 29 | 30 | func favicon(w http.ResponseWriter, r *http.Request) { 31 | w.Header().Set("Location", "//www.baidu.com/favicon.ico") 32 | http.Error(w, "", 302) 33 | } 34 | -------------------------------------------------------------------------------- /requester/rio/rio.go: -------------------------------------------------------------------------------- 1 | // Package rio rquester io 工具包 2 | package rio 3 | 4 | import ( 5 | "io" 6 | ) 7 | 8 | // Lener 返回32-bit长度接口 9 | type Lener interface { 10 | Len() int 11 | } 12 | 13 | // Lener64 返回64-bit长度接口 14 | type Lener64 interface { 15 | Len() int64 16 | } 17 | 18 | // ReaderLen 实现io.Reader和32-bit长度接口 19 | type ReaderLen interface { 20 | io.Reader 21 | Lener 22 | } 23 | 24 | // ReaderLen64 实现io.Reader和64-bit长度接口 25 | type ReaderLen64 interface { 26 | io.Reader 27 | Lener64 28 | } 29 | 30 | // WriterLen64 实现io.Writer和64-bit长度接口 31 | type WriterLen64 interface { 32 | io.Writer 33 | Lener64 34 | } 35 | 36 | // WriteCloserAt 实现io.WriteCloser和io.WriterAt接口 37 | type WriteCloserAt interface { 38 | io.WriteCloser 39 | io.WriterAt 40 | } 41 | 42 | // WriteCloserLen64At 实现rio.WriteCloserAt和64-bit长度接口 43 | type WriteCloserLen64At interface { 44 | WriteCloserAt 45 | Lener64 46 | } 47 | -------------------------------------------------------------------------------- /vendor/github.com/GeertJohan/go.rice/sort.go: -------------------------------------------------------------------------------- 1 | package rice 2 | 3 | import "os" 4 | 5 | // SortByName allows an array of os.FileInfo objects 6 | // to be easily sorted by filename using sort.Sort(SortByName(array)) 7 | type SortByName []os.FileInfo 8 | 9 | func (f SortByName) Len() int { return len(f) } 10 | func (f SortByName) Less(i, j int) bool { return f[i].Name() < f[j].Name() } 11 | func (f SortByName) Swap(i, j int) { f[i], f[j] = f[j], f[i] } 12 | 13 | // SortByModified allows an array of os.FileInfo objects 14 | // to be easily sorted by modified date using sort.Sort(SortByModified(array)) 15 | type SortByModified []os.FileInfo 16 | 17 | func (f SortByModified) Len() int { return len(f) } 18 | func (f SortByModified) Less(i, j int) bool { return f[i].ModTime().Unix() > f[j].ModTime().Unix() } 19 | func (f SortByModified) Swap(i, j int) { f[i], f[j] = f[j], f[i] } 20 | -------------------------------------------------------------------------------- /baidupcs/quota.go: -------------------------------------------------------------------------------- 1 | package baidupcs 2 | 3 | import ( 4 | "github.com/json-iterator/go" 5 | ) 6 | 7 | type quotaInfo struct { 8 | *ErrInfo 9 | 10 | Quota int64 `json:"quota"` 11 | Used int64 `json:"used"` 12 | } 13 | 14 | // QuotaInfo 获取当前用户空间配额信息 15 | func (pcs *BaiduPCS) QuotaInfo() (quota, used int64, pcsError Error) { 16 | dataReadCloser, pcsError := pcs.PrepareQuotaInfo() 17 | if pcsError != nil { 18 | return 19 | } 20 | 21 | defer dataReadCloser.Close() 22 | 23 | quotaInfo := "aInfo{ 24 | ErrInfo: NewErrorInfo(OperationQuotaInfo), 25 | } 26 | 27 | d := jsoniter.NewDecoder(dataReadCloser) 28 | err := d.Decode(quotaInfo) 29 | if err != nil { 30 | quotaInfo.ErrInfo.jsonError(err) 31 | return 0, 0, quotaInfo.ErrInfo 32 | } 33 | 34 | if quotaInfo.ErrCode != 0 { 35 | return 0, 0, quotaInfo.ErrInfo 36 | } 37 | 38 | quota = quotaInfo.Quota 39 | used = quotaInfo.Used 40 | return 41 | } 42 | -------------------------------------------------------------------------------- /vendor/github.com/astaxie/beego/utils/caller.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 beego Author. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package utils 16 | 17 | import ( 18 | "reflect" 19 | "runtime" 20 | ) 21 | 22 | // GetFuncName get function name 23 | func GetFuncName(i interface{}) string { 24 | return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name() 25 | } 26 | -------------------------------------------------------------------------------- /vendor/github.com/iikira/Baidu-Login/bdcrypto/hmac.go: -------------------------------------------------------------------------------- 1 | package bdcrypto 2 | 3 | import ( 4 | "crypto/hmac" 5 | "crypto/md5" 6 | "crypto/sha1" 7 | "crypto/sha256" 8 | "crypto/sha512" 9 | ) 10 | 11 | // HmacSHA1 HMAC-SHA-1签名认证 12 | func HmacSHA1(key, origData []byte) (sum []byte) { 13 | mac := hmac.New(sha1.New, key) 14 | mac.Write(origData) 15 | return mac.Sum(nil) 16 | } 17 | 18 | // HmacSHA256 HMAC-SHA-256签名认证 19 | func HmacSHA256(key, origData []byte) (sum []byte) { 20 | mac := hmac.New(sha256.New, key) 21 | mac.Write(origData) 22 | return mac.Sum(nil) 23 | } 24 | 25 | // HmacSHA512 HMAC-SHA-512签名认证 26 | func HmacSHA512(key, origData []byte) (sum []byte) { 27 | mac := hmac.New(sha512.New, key) 28 | mac.Write(origData) 29 | return mac.Sum(nil) 30 | } 31 | 32 | // HmacMD5 HMAC-SHA512-签名认证 33 | func HmacMD5(key, origData []byte) (sum []byte) { 34 | mac := hmac.New(md5.New, key) 35 | mac.Write(origData) 36 | return mac.Sum(nil) 37 | } 38 | -------------------------------------------------------------------------------- /vendor/github.com/mattn/go-runewidth/README.mkd: -------------------------------------------------------------------------------- 1 | go-runewidth 2 | ============ 3 | 4 | [![Build Status](https://travis-ci.org/mattn/go-runewidth.png?branch=master)](https://travis-ci.org/mattn/go-runewidth) 5 | [![Coverage Status](https://coveralls.io/repos/mattn/go-runewidth/badge.png?branch=HEAD)](https://coveralls.io/r/mattn/go-runewidth?branch=HEAD) 6 | [![GoDoc](https://godoc.org/github.com/mattn/go-runewidth?status.svg)](http://godoc.org/github.com/mattn/go-runewidth) 7 | [![Go Report Card](https://goreportcard.com/badge/github.com/mattn/go-runewidth)](https://goreportcard.com/report/github.com/mattn/go-runewidth) 8 | 9 | Provides functions to get fixed width of the character or string. 10 | 11 | Usage 12 | ----- 13 | 14 | ```go 15 | runewidth.StringWidth("つのだ☆HIRO") == 12 16 | ``` 17 | 18 | 19 | Author 20 | ------ 21 | 22 | Yasuhiro Matsumoto 23 | 24 | License 25 | ------- 26 | 27 | under the MIT License: http://mattn.mit-license.org/2013 28 | -------------------------------------------------------------------------------- /internal/pcsweb/middleware.go: -------------------------------------------------------------------------------- 1 | package pcsweb 2 | 3 | import ( 4 | "net/http" 5 | ) 6 | 7 | func middleware(next http.HandlerFunc) http.HandlerFunc { 8 | return func(w http.ResponseWriter, r *http.Request) { 9 | // next handler 10 | next.ServeHTTP(w, r) 11 | } 12 | } 13 | 14 | func activeAuthMiddleware(next http.HandlerFunc) http.HandlerFunc { 15 | next2 := middleware(next) 16 | 17 | // TODO web登录 18 | 19 | return func(w http.ResponseWriter, r *http.Request) { 20 | next2.ServeHTTP(w, r) 21 | } 22 | } 23 | 24 | // rootMiddleware 根目录中间件 25 | func rootMiddleware(w http.ResponseWriter, r *http.Request) { 26 | if r.URL.Path == "/" { 27 | // 跳转到 /index.html 28 | w.Header().Set("Location", "/index.html") 29 | http.Error(w, "", 301) 30 | } else { 31 | w.Header().Set("X-Content-Type-Options", "nosniff") 32 | w.WriteHeader(404) 33 | 34 | tmpl := boxTmplParse("index", "index.html", "404.html") 35 | checkErr(tmpl.Execute(w, nil)) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/reflect2/reflect2_kind.go: -------------------------------------------------------------------------------- 1 | package reflect2 2 | 3 | import ( 4 | "reflect" 5 | "unsafe" 6 | ) 7 | 8 | // DefaultTypeOfKind return the non aliased default type for the kind 9 | func DefaultTypeOfKind(kind reflect.Kind) Type { 10 | return kindTypes[kind] 11 | } 12 | 13 | var kindTypes = map[reflect.Kind]Type{ 14 | reflect.Bool: TypeOf(true), 15 | reflect.Uint8: TypeOf(uint8(0)), 16 | reflect.Int8: TypeOf(int8(0)), 17 | reflect.Uint16: TypeOf(uint16(0)), 18 | reflect.Int16: TypeOf(int16(0)), 19 | reflect.Uint32: TypeOf(uint32(0)), 20 | reflect.Int32: TypeOf(int32(0)), 21 | reflect.Uint64: TypeOf(uint64(0)), 22 | reflect.Int64: TypeOf(int64(0)), 23 | reflect.Uint: TypeOf(uint(0)), 24 | reflect.Int: TypeOf(int(0)), 25 | reflect.Float32: TypeOf(float32(0)), 26 | reflect.Float64: TypeOf(float64(0)), 27 | reflect.Uintptr: TypeOf(uintptr(0)), 28 | reflect.String: TypeOf(""), 29 | reflect.UnsafePointer: TypeOf(unsafe.Pointer(nil)), 30 | } -------------------------------------------------------------------------------- /vendor/github.com/json-iterator/go/fuzzy_mode_convert_table.md: -------------------------------------------------------------------------------- 1 | | json type \ dest type | bool | int | uint | float |string| 2 | | --- | --- | --- | --- |--|--| 3 | | number | positive => true
negative => true
zero => false| 23.2 => 23
-32.1 => -32| 12.1 => 12
-12.1 => 0|as normal|same as origin| 4 | | string | empty string => false
string "0" => false
other strings => true | "123.32" => 123
"-123.4" => -123
"123.23xxxw" => 123
"abcde12" => 0
"-32.1" => -32| 13.2 => 13
-1.1 => 0 |12.1 => 12.1
-12.3 => -12.3
12.4xxa => 12.4
+1.1e2 =>110 |same as origin| 5 | | bool | true => true
false => false| true => 1
false => 0 | true => 1
false => 0 |true => 1
false => 0|true => "true"
false => "false"| 6 | | object | true | 0 | 0 |0|originnal json| 7 | | array | empty array => false
nonempty array => true| [] => 0
[1,2] => 1 | [] => 0
[1,2] => 1 |[] => 0
[1,2] => 1|original json| -------------------------------------------------------------------------------- /vendor/github.com/json-iterator/go/jsoniter.go: -------------------------------------------------------------------------------- 1 | // Package jsoniter implements encoding and decoding of JSON as defined in 2 | // RFC 4627 and provides interfaces with identical syntax of standard lib encoding/json. 3 | // Converting from encoding/json to jsoniter is no more than replacing the package with jsoniter 4 | // and variable type declarations (if any). 5 | // jsoniter interfaces gives 100% compatibility with code using standard lib. 6 | // 7 | // "JSON and Go" 8 | // (https://golang.org/doc/articles/json_and_go.html) 9 | // gives a description of how Marshal/Unmarshal operate 10 | // between arbitrary or predefined json objects and bytes, 11 | // and it applies to jsoniter.Marshal/Unmarshal as well. 12 | // 13 | // Besides, jsoniter.Iterator provides a different set of interfaces 14 | // iterating given bytes/string/reader 15 | // and yielding parsed elements one by one. 16 | // This set of interfaces reads input as required and gives 17 | // better performance. 18 | package jsoniter 19 | -------------------------------------------------------------------------------- /vendor/github.com/iikira/baidu-tools/pan/parser.go: -------------------------------------------------------------------------------- 1 | package pan 2 | 3 | import ( 4 | "crypto/hmac" 5 | "crypto/sha1" 6 | "fmt" 7 | "regexp" 8 | "strconv" 9 | "time" 10 | ) 11 | 12 | const ( 13 | // BDKey 百度 HMAC-SHA1 密钥 14 | BDKey = "B8ec24caf34ef7227c66767d29ffd3fb" 15 | ) 16 | 17 | var ( 18 | // YunDataExp 解析网盘分享首页的数据的正则表达式 19 | YunDataExp = regexp.MustCompile(`window\.yunData[\s]?=[\s]?(.*?);`) 20 | ) 21 | 22 | // MustParseInt64 将字符串转换为 int64, 忽略错误 23 | func MustParseInt64(s string) (i int64) { 24 | i, _ = strconv.ParseInt(s, 10, 64) 25 | return 26 | } 27 | 28 | // MustParseInt 将字符串转换为 int, 忽略错误 29 | func MustParseInt(s string) (i int) { 30 | i, _ = strconv.Atoi(s) 31 | return 32 | } 33 | 34 | // signature 签名 35 | func (si *SharedInfo) signature() { 36 | si.Timestamp = time.Now().Unix() 37 | orig := fmt.Sprintf("%d_%d__%d", si.ShareID, si.UK, si.Timestamp) 38 | 39 | mac := hmac.New(sha1.New, []byte(BDKey)) 40 | mac.Write([]byte(orig)) 41 | si.Sign = mac.Sum(nil) 42 | } 43 | -------------------------------------------------------------------------------- /requester/uploader/example.go: -------------------------------------------------------------------------------- 1 | package uploader 2 | 3 | import ( 4 | "fmt" 5 | "github.com/iikira/BaiduPCS-Go/pcsutil/converter" 6 | "github.com/iikira/BaiduPCS-Go/requester/rio" 7 | ) 8 | 9 | // DoUpload 执行上传 10 | func DoUpload(uploadURL string, readerlen64 rio.ReaderLen64, checkFunc CheckFunc) { 11 | u := NewUploader(uploadURL, readerlen64) 12 | u.SetCheckFunc(checkFunc) 13 | 14 | exitChan := make(chan struct{}) 15 | 16 | u.OnExecute(func() { 17 | statusChan := u.GetStatusChan() 18 | for { 19 | select { 20 | case <-exitChan: 21 | return 22 | case v, ok := <-statusChan: 23 | if !ok { 24 | return 25 | } 26 | 27 | fmt.Printf("\r ↑ %s/%s %s/s in %s ............", 28 | converter.ConvertFileSize(v.Uploaded(), 2), 29 | converter.ConvertFileSize(v.TotalSize(), 2), 30 | converter.ConvertFileSize(v.SpeedsPerSecond(), 2), 31 | v.TimeElapsed(), 32 | ) 33 | } 34 | } 35 | }) 36 | 37 | u.Execute() 38 | close(exitChan) 39 | 40 | return 41 | } 42 | -------------------------------------------------------------------------------- /vendor/github.com/kardianos/osext/osext_windows.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //+build !go1.8 6 | 7 | package osext 8 | 9 | import ( 10 | "syscall" 11 | "unicode/utf16" 12 | "unsafe" 13 | ) 14 | 15 | var ( 16 | kernel = syscall.MustLoadDLL("kernel32.dll") 17 | getModuleFileNameProc = kernel.MustFindProc("GetModuleFileNameW") 18 | ) 19 | 20 | // GetModuleFileName() with hModule = NULL 21 | func executable() (exePath string, err error) { 22 | return getModuleFileName() 23 | } 24 | 25 | func getModuleFileName() (string, error) { 26 | var n uint32 27 | b := make([]uint16, syscall.MAX_PATH) 28 | size := uint32(len(b)) 29 | 30 | r0, _, e1 := getModuleFileNameProc.Call(0, uintptr(unsafe.Pointer(&b[0])), uintptr(size)) 31 | n = uint32(r0) 32 | if n == 0 { 33 | return "", e1 34 | } 35 | return string(utf16.Decode(b[0:n])), nil 36 | } 37 | -------------------------------------------------------------------------------- /internal/pcsupdate/updatefile.go: -------------------------------------------------------------------------------- 1 | package pcsupdate 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | "os" 7 | "path/filepath" 8 | ) 9 | 10 | func update(targetPath string, src io.Reader) error { 11 | info, err := os.Stat(targetPath) 12 | if err != nil { 13 | fmt.Printf("Warning: %s\n", err) 14 | return nil 15 | } 16 | 17 | privMode := info.Mode() 18 | 19 | oldPath := filepath.Join(filepath.Dir(targetPath), "old"+filepath.Base(targetPath)) 20 | 21 | err = os.Rename(targetPath, oldPath) 22 | if err != nil { 23 | return err 24 | } 25 | 26 | newFile, err := os.OpenFile(targetPath, os.O_CREATE|os.O_WRONLY, privMode) 27 | if err != nil { 28 | return err 29 | } 30 | 31 | _, err = io.Copy(newFile, src) 32 | if err != nil { 33 | return err 34 | } 35 | 36 | err = newFile.Close() 37 | if err != nil { 38 | fmt.Printf("Warning: 关闭文件发生错误: %s\n", err) 39 | } 40 | 41 | err = os.Remove(oldPath) 42 | if err != nil { 43 | fmt.Printf("Warning: 移除旧文件发生错误: %s\n", err) 44 | } 45 | return nil 46 | } 47 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/reflect2/Gopkg.toml: -------------------------------------------------------------------------------- 1 | # Gopkg.toml example 2 | # 3 | # Refer to https://golang.github.io/dep/docs/Gopkg.toml.html 4 | # for detailed Gopkg.toml documentation. 5 | # 6 | # required = ["github.com/user/thing/cmd/thing"] 7 | # ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] 8 | # 9 | # [[constraint]] 10 | # name = "github.com/user/project" 11 | # version = "1.0.0" 12 | # 13 | # [[constraint]] 14 | # name = "github.com/user/project2" 15 | # branch = "dev" 16 | # source = "github.com/myfork/project2" 17 | # 18 | # [[override]] 19 | # name = "github.com/x/y" 20 | # version = "2.4.0" 21 | # 22 | # [prune] 23 | # non-go = false 24 | # go-tests = true 25 | # unused-packages = true 26 | 27 | ignored = ["github.com/modern-go/test","github.com/modern-go/test/must","github.com/modern-go/test/should"] 28 | 29 | [[constraint]] 30 | name = "github.com/modern-go/concurrent" 31 | version = "1.0.0" 32 | 33 | [prune] 34 | go-tests = true 35 | unused-packages = true 36 | -------------------------------------------------------------------------------- /vendor/github.com/peterh/liner/unixmode.go: -------------------------------------------------------------------------------- 1 | // +build linux darwin freebsd openbsd netbsd 2 | 3 | package liner 4 | 5 | import ( 6 | "syscall" 7 | "unsafe" 8 | ) 9 | 10 | func (mode *termios) ApplyMode() error { 11 | _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(syscall.Stdin), setTermios, uintptr(unsafe.Pointer(mode))) 12 | 13 | if errno != 0 { 14 | return errno 15 | } 16 | return nil 17 | } 18 | 19 | // TerminalMode returns the current terminal input mode as an InputModeSetter. 20 | // 21 | // This function is provided for convenience, and should 22 | // not be necessary for most users of liner. 23 | func TerminalMode() (ModeApplier, error) { 24 | mode, errno := getMode(syscall.Stdin) 25 | 26 | if errno != 0 { 27 | return nil, errno 28 | } 29 | return mode, nil 30 | } 31 | 32 | func getMode(handle int) (*termios, syscall.Errno) { 33 | var mode termios 34 | _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(handle), getTermios, uintptr(unsafe.Pointer(&mode))) 35 | 36 | return &mode, errno 37 | } 38 | -------------------------------------------------------------------------------- /pcspath/pcspath.go: -------------------------------------------------------------------------------- 1 | // Package pcspath 网盘路径工具包 2 | package pcspath 3 | 4 | import ( 5 | "path" 6 | ) 7 | 8 | // PCSPath 百度 PCS 路径 9 | type PCSPath struct { 10 | WorkdirDestination *string // 指向工作目录 11 | SubPath string // 相对于工作目录的子目录 12 | } 13 | 14 | // NewPCSPath 返回 PCSPath 指针对象 15 | func NewPCSPath(workdirDestination *string, pcsSubPath string) *PCSPath { 16 | pp := &PCSPath{ 17 | WorkdirDestination: workdirDestination, 18 | SubPath: pcsSubPath, 19 | } 20 | pp.CleanPath() 21 | return pp 22 | } 23 | 24 | // CleanPath 过滤处理目录 25 | func (pp *PCSPath) CleanPath() { 26 | pp.SubPath = path.Clean(pp.SubPath) 27 | *pp.WorkdirDestination = path.Clean(*pp.WorkdirDestination) 28 | } 29 | 30 | // EscapeBracket 转义文件名中的中括号 31 | func (pp *PCSPath) EscapeBracket() { 32 | pp.SubPath = EscapeBracketOne(pp.SubPath) 33 | *pp.WorkdirDestination = EscapeBracketOne(*pp.WorkdirDestination) 34 | } 35 | 36 | // SetSubPath 设置子目录 37 | func (pp *PCSPath) SetSubPath(pcsSubPath string) { 38 | pp.SubPath = path.Clean(pcsSubPath) 39 | } 40 | -------------------------------------------------------------------------------- /vendor/github.com/iikira/baidu-tools/randominfo/randominfo.go: -------------------------------------------------------------------------------- 1 | // Package randominfo 提供随机信息生成服务 2 | package randominfo 3 | 4 | import ( 5 | "crypto/md5" 6 | cryptorand "crypto/rand" 7 | "encoding/binary" 8 | "encoding/hex" 9 | "strconv" 10 | "strings" 11 | "time" 12 | ) 13 | 14 | // RamdomNumber 返回[min, max]随机数字 15 | func RamdomNumber(min, max uint64) (v uint64) { 16 | if min > max { 17 | min, max = max, min 18 | } 19 | binary.Read(cryptorand.Reader, binary.BigEndian, &v) 20 | return v%(max-min) + min 21 | } 22 | 23 | // RamdomBytes 随机字节数组 24 | func RamdomBytes(n int) []byte { 25 | b := make([]byte, n) 26 | cryptorand.Read(b) 27 | return b 28 | } 29 | 30 | // RamdomMD5String 随机md5字符串 31 | func RamdomMD5String() string { 32 | m := md5.New() 33 | m.Write(RamdomBytes(4)) 34 | m.Write([]byte(strconv.FormatInt(time.Now().UnixNano(), 16))) 35 | return hex.EncodeToString(m.Sum(nil)) 36 | } 37 | 38 | // RamdomMD5UpperString 随机md5字符串, 大写 39 | func RamdomMD5UpperString() string { 40 | return strings.ToUpper(RamdomMD5String()) 41 | } 42 | -------------------------------------------------------------------------------- /.github/RELEASE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # 更新日志: 2 | 3 | 1. 修复下载进度超出100%; 4 | 2. 修复修改文件夹名称导致文件夹消失; 5 | 3. 修复上传失败不输出错误; 6 | 4. 下载支持以流式文件的方式下载; 7 | 5. ls列目录,增加详细显示选项; 8 | 6. emm...; 9 | 10 | 个人项目bug在所难免! 欢迎提 issue 和 pull request!!. 11 | 12 | # 下载说明 13 | 14 | ## 解释 CPU架构 15 | 16 | |amd|arm| mips| 说明 | 17 | |-----|----------------|------------------|------------------| 18 | |amd64, x64 |arm64 | mips64, mips64le |适用于64位CPU或操作系统的计算机| 19 | |386, x86 |armv5, armv7 | mips, mipsle |适用于32位CPU或操作系统的计算机| 20 | 21 | ## 注意区别 `arm` 和 `amd`, 不要搞错了!!!! 22 | 23 | ## 下载 24 | 25 | * PC/电脑: 26 | 请选择对应的系统 (windows, linux, darwin(苹果系统), freebsd), 对应的CPU架构 (一般情况下是 amd), 对应的CPU或操作系统位数 (详见上表), 下载. 27 | 28 | * 移动设备: 29 | 请选择对应的系统(android, darwin(ios系统)), 对应的CPU架构 (一般情况下是 arm, 除了少数手机的CPU架构要选 amd, 例如联想K800, 联想K900等), 对应的CPU或操作系统位数 (详见上表), 下载. 30 | 31 | * mips: 32 | 请选择对应的CPU架构, 对应的CPU或操作系统位数 (详见上表), 下载. 33 | 需要启用fpu才可以正常运行程序, 否则可能会出现 `Illegal instruction` 错误. 34 | 35 | ## 注意 36 | 37 | 相关的关键词, 均能在文件名中找到. 38 | 39 | 文件格式均为zip压缩包格式, 切勿未解压程序就直接运行!! 程序解压之后才可以正常使用. 40 | -------------------------------------------------------------------------------- /vendor/github.com/kardianos/osext/osext.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Extensions to the standard "os" package. 6 | package osext // import "github.com/kardianos/osext" 7 | 8 | import "path/filepath" 9 | 10 | var cx, ce = executableClean() 11 | 12 | func executableClean() (string, error) { 13 | p, err := executable() 14 | return filepath.Clean(p), err 15 | } 16 | 17 | // Executable returns an absolute path that can be used to 18 | // re-invoke the current program. 19 | // It may not be valid after the current program exits. 20 | func Executable() (string, error) { 21 | return cx, ce 22 | } 23 | 24 | // Returns same path as Executable, returns just the folder 25 | // path. Excludes the executable name and any trailing slash. 26 | func ExecutableFolder() (string, error) { 27 | p, err := Executable() 28 | if err != nil { 29 | return "", err 30 | } 31 | 32 | return filepath.Dir(p), nil 33 | } 34 | -------------------------------------------------------------------------------- /vendor/github.com/bitly/go-simplejson/LICENSE: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any person obtaining a copy 2 | of this software and associated documentation files (the "Software"), to deal 3 | in the Software without restriction, including without limitation the rights 4 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 5 | copies of the Software, and to permit persons to whom the Software is 6 | furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in 9 | all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 14 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 15 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 17 | THE SOFTWARE. 18 | -------------------------------------------------------------------------------- /vendor/github.com/kardianos/osext/osext_procfs.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !go1.8,android !go1.8,linux !go1.8,netbsd !go1.8,solaris !go1.8,dragonfly 6 | 7 | package osext 8 | 9 | import ( 10 | "errors" 11 | "fmt" 12 | "os" 13 | "runtime" 14 | "strings" 15 | ) 16 | 17 | func executable() (string, error) { 18 | switch runtime.GOOS { 19 | case "linux", "android": 20 | const deletedTag = " (deleted)" 21 | execpath, err := os.Readlink("/proc/self/exe") 22 | if err != nil { 23 | return execpath, err 24 | } 25 | execpath = strings.TrimSuffix(execpath, deletedTag) 26 | execpath = strings.TrimPrefix(execpath, deletedTag) 27 | return execpath, nil 28 | case "netbsd": 29 | return os.Readlink("/proc/curproc/exe") 30 | case "dragonfly": 31 | return os.Readlink("/proc/curproc/file") 32 | case "solaris": 33 | return os.Readlink(fmt.Sprintf("/proc/%d/path/a.out", os.Getpid())) 34 | } 35 | return "", errors.New("ExecPath not implemented for " + runtime.GOOS) 36 | } 37 | -------------------------------------------------------------------------------- /vendor/github.com/json-iterator/go/pool.go: -------------------------------------------------------------------------------- 1 | package jsoniter 2 | 3 | import ( 4 | "io" 5 | ) 6 | 7 | // IteratorPool a thread safe pool of iterators with same configuration 8 | type IteratorPool interface { 9 | BorrowIterator(data []byte) *Iterator 10 | ReturnIterator(iter *Iterator) 11 | } 12 | 13 | // StreamPool a thread safe pool of streams with same configuration 14 | type StreamPool interface { 15 | BorrowStream(writer io.Writer) *Stream 16 | ReturnStream(stream *Stream) 17 | } 18 | 19 | func (cfg *frozenConfig) BorrowStream(writer io.Writer) *Stream { 20 | stream := cfg.streamPool.Get().(*Stream) 21 | stream.Reset(writer) 22 | return stream 23 | } 24 | 25 | func (cfg *frozenConfig) ReturnStream(stream *Stream) { 26 | stream.Error = nil 27 | stream.Attachment = nil 28 | cfg.streamPool.Put(stream) 29 | } 30 | 31 | func (cfg *frozenConfig) BorrowIterator(data []byte) *Iterator { 32 | iter := cfg.iteratorPool.Get().(*Iterator) 33 | iter.ResetBytes(data) 34 | return iter 35 | } 36 | 37 | func (cfg *frozenConfig) ReturnIterator(iter *Iterator) { 38 | iter.Error = nil 39 | iter.Attachment = nil 40 | cfg.iteratorPool.Put(iter) 41 | } 42 | -------------------------------------------------------------------------------- /vendor/github.com/olekukonko/tablewriter/LICENCE.md: -------------------------------------------------------------------------------- 1 | Copyright (C) 2014 by Oleku Konko 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /pcsutil/waitgroup/wait_group.go: -------------------------------------------------------------------------------- 1 | // Package waitgroup sync.WaitGroup extension 2 | package waitgroup 3 | 4 | import "sync" 5 | 6 | // WaitGroup 在 sync.WaitGroup 的基础上, 新增线程控制功能 7 | type WaitGroup struct { 8 | wg sync.WaitGroup 9 | p chan struct{} 10 | 11 | sync.RWMutex 12 | } 13 | 14 | // NewWaitGroup returns a pointer to a new `WaitGroup` object. 15 | // parallel 为最大并发数, 0 代表无限制 16 | func NewWaitGroup(parallel int) (w *WaitGroup) { 17 | w = &WaitGroup{ 18 | wg: sync.WaitGroup{}, 19 | } 20 | 21 | if parallel <= 0 { 22 | return 23 | } 24 | 25 | w.p = make(chan struct{}, parallel) 26 | return 27 | } 28 | 29 | // AddDelta sync.WaitGroup.Add(1) 30 | func (w *WaitGroup) AddDelta() { 31 | if w.p != nil { 32 | w.p <- struct{}{} 33 | } 34 | 35 | w.wg.Add(1) 36 | } 37 | 38 | // Done sync.WaitGroup.Done() 39 | func (w *WaitGroup) Done() { 40 | w.wg.Done() 41 | 42 | if w.p != nil { 43 | <-w.p 44 | } 45 | } 46 | 47 | // Wait 参照 sync.WaitGroup 的 Wait 方法 48 | func (w *WaitGroup) Wait() { 49 | w.wg.Wait() 50 | if w.p != nil { 51 | close(w.p) 52 | } 53 | } 54 | 55 | // Parallel 返回当前正在进行的任务数量 56 | func (w *WaitGroup) Parallel() int { 57 | return len(w.p) 58 | } 59 | -------------------------------------------------------------------------------- /vendor/github.com/json-iterator/go/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 json-iterator 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/fatih/color/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Fatih Arslan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /vendor/github.com/iikira/args/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) {{year}} {{fullname}} 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /vendor/github.com/shiena/ansicolor/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) [2014] [shiena] 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/urfave/cli/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Jeremy Saenz & Contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/daaku/go.zipexe/license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright © 2012-2015 Carlos Castillo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the “Software”), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/peterh/liner/COPYING: -------------------------------------------------------------------------------- 1 | Copyright © 2012 Peter Harris 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a 4 | copy of this software and associated documentation files (the "Software"), 5 | to deal in the Software without restriction, including without limitation 6 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | and/or sell copies of the Software, and to permit persons to whom the 8 | Software is furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice (including the next 11 | paragraph) shall be included in all copies or substantial portions of the 12 | Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | DEALINGS IN THE SOFTWARE. 21 | 22 | -------------------------------------------------------------------------------- /vendor/github.com/mattn/go-runewidth/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Yasuhiro Matsumoto 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/astaxie/beego/utils/captcha/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011-2014 Dmitry Chestnykh 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /internal/pcscommand/rm_mkdir.go: -------------------------------------------------------------------------------- 1 | package pcscommand 2 | 3 | import ( 4 | "fmt" 5 | "github.com/iikira/BaiduPCS-Go/pcspath" 6 | "github.com/iikira/BaiduPCS-Go/pcstable" 7 | "os" 8 | "strconv" 9 | ) 10 | 11 | // RunRemove 执行 批量删除文件/目录 12 | func RunRemove(paths ...string) { 13 | paths, err := getAllAbsPaths(paths...) 14 | if err != nil { 15 | fmt.Println(err) 16 | return 17 | } 18 | 19 | pnt := func() { 20 | tb := pcstable.NewTable(os.Stdout) 21 | tb.SetHeader([]string{"#", "文件/目录"}) 22 | for k := range paths { 23 | tb.Append([]string{strconv.Itoa(k), paths[k]}) 24 | } 25 | tb.Render() 26 | } 27 | 28 | err = GetBaiduPCS().Remove(paths...) 29 | if err != nil { 30 | fmt.Println(err) 31 | fmt.Println("操作失败, 以下文件/目录删除失败: ") 32 | pnt() 33 | return 34 | } 35 | 36 | fmt.Println("操作成功, 以下文件/目录已删除, 可在网盘文件回收站找回: ") 37 | pnt() 38 | } 39 | 40 | // RunMkdir 执行 创建目录 41 | func RunMkdir(path string) { 42 | activeUser := GetActiveUser() 43 | pcsPath := pcspath.NewPCSPath(&activeUser.Workdir, path) 44 | 45 | err := GetBaiduPCS().Mkdir(pcsPath.AbsPathNoMatch()) 46 | if err != nil { 47 | fmt.Printf("创建目录 %s 失败, %s\n", path, err) 48 | return 49 | } 50 | 51 | fmt.Println("创建目录成功:", path) 52 | } 53 | -------------------------------------------------------------------------------- /internal/pcscommand/export.go: -------------------------------------------------------------------------------- 1 | package pcscommand 2 | 3 | import ( 4 | "fmt" 5 | "github.com/iikira/BaiduPCS-Go/baidupcs" 6 | "path" 7 | "strings" 8 | ) 9 | 10 | // RunExport 执行导出文件和目录 11 | func RunExport(pcspaths []string, rootPath string) { 12 | pcspaths, err := getAllAbsPaths(pcspaths...) 13 | if err != nil { 14 | fmt.Println(err) 15 | return 16 | } 17 | 18 | pcs := GetBaiduPCS() 19 | 20 | for _, pcspath := range pcspaths { 21 | getPath := func(p string) string { 22 | if rootPath == "" { 23 | return p 24 | } 25 | 26 | // 是一个单独文件 27 | if pcspath == p { 28 | return path.Join(rootPath, strings.TrimPrefix(p, path.Dir(pcspath))) 29 | } 30 | 31 | return path.Join(rootPath, strings.TrimPrefix(p, pcspath)) 32 | } 33 | 34 | var d int 35 | pcs.FilesDirectoriesRecurseList(pcspath, baidupcs.DefaultOrderOptions, func(depth int, fd *baidupcs.FileDirectory) { 36 | if fd.Isdir { 37 | if depth > d { 38 | d = depth 39 | } else { 40 | fmt.Printf("BaiduPCS-Go mkdir \"%s\"\n", getPath(fd.Path)) 41 | d = 0 42 | } 43 | return 44 | } 45 | 46 | fmt.Printf("BaiduPCS-Go rapidupload -length=%d -md5=%s \"%s\"\n", fd.Size, fd.MD5, getPath(fd.Path)) 47 | }) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /vendor/github.com/json-iterator/go/any_nil.go: -------------------------------------------------------------------------------- 1 | package jsoniter 2 | 3 | type nilAny struct { 4 | baseAny 5 | } 6 | 7 | func (any *nilAny) LastError() error { 8 | return nil 9 | } 10 | 11 | func (any *nilAny) ValueType() ValueType { 12 | return NilValue 13 | } 14 | 15 | func (any *nilAny) MustBeValid() Any { 16 | return any 17 | } 18 | 19 | func (any *nilAny) ToBool() bool { 20 | return false 21 | } 22 | 23 | func (any *nilAny) ToInt() int { 24 | return 0 25 | } 26 | 27 | func (any *nilAny) ToInt32() int32 { 28 | return 0 29 | } 30 | 31 | func (any *nilAny) ToInt64() int64 { 32 | return 0 33 | } 34 | 35 | func (any *nilAny) ToUint() uint { 36 | return 0 37 | } 38 | 39 | func (any *nilAny) ToUint32() uint32 { 40 | return 0 41 | } 42 | 43 | func (any *nilAny) ToUint64() uint64 { 44 | return 0 45 | } 46 | 47 | func (any *nilAny) ToFloat32() float32 { 48 | return 0 49 | } 50 | 51 | func (any *nilAny) ToFloat64() float64 { 52 | return 0 53 | } 54 | 55 | func (any *nilAny) ToString() string { 56 | return "" 57 | } 58 | 59 | func (any *nilAny) WriteTo(stream *Stream) { 60 | stream.WriteNil() 61 | } 62 | 63 | func (any *nilAny) Parse() *Iterator { 64 | return nil 65 | } 66 | 67 | func (any *nilAny) GetInterface() interface{} { 68 | return nil 69 | } 70 | -------------------------------------------------------------------------------- /versioninfo.json: -------------------------------------------------------------------------------- 1 | { 2 | "FixedFileInfo": { 3 | "FileVersion": { 4 | "Major": 3, 5 | "Minor": 5, 6 | "Patch": 3, 7 | "Build": 0 8 | }, 9 | "ProductVersion": { 10 | "Major": 3, 11 | "Minor": 5, 12 | "Patch": 3, 13 | "Build": 0 14 | }, 15 | "FileFlagsMask": "3f", 16 | "FileFlags ": "00", 17 | "FileOS": "040004", 18 | "FileType": "01", 19 | "FileSubType": "00" 20 | }, 21 | "StringFileInfo": { 22 | "Comments": "", 23 | "CompanyName": "iikira", 24 | "FileDescription": "百度网盘客户端", 25 | "FileVersion": "v3.5.3", 26 | "InternalName": "", 27 | "LegalCopyright": "© 2016-2018 iikira.", 28 | "LegalTrademarks": "", 29 | "OriginalFilename": "", 30 | "PrivateBuild": "", 31 | "ProductName": "BaiduPCS-Go", 32 | "ProductVersion": "v3.5.3", 33 | "SpecialBuild": "" 34 | }, 35 | "VarFileInfo": { 36 | "Translation": { 37 | "LangID": "0409", 38 | "CharsetID": "04B0" 39 | } 40 | }, 41 | "IconPath": "assets/BaiduPCS-Go.ico", 42 | "ManifestPath": "BaiduPCS-Go.exe.manifest" 43 | } -------------------------------------------------------------------------------- /vendor/github.com/modern-go/reflect2/unsafe_ptr.go: -------------------------------------------------------------------------------- 1 | package reflect2 2 | 3 | import ( 4 | "unsafe" 5 | "reflect" 6 | ) 7 | 8 | type UnsafePtrType struct { 9 | unsafeType 10 | } 11 | 12 | func newUnsafePtrType(cfg *frozenConfig, type1 reflect.Type) *UnsafePtrType { 13 | return &UnsafePtrType{ 14 | unsafeType: *newUnsafeType(cfg, type1), 15 | } 16 | } 17 | 18 | func (type2 *UnsafePtrType) IsNil(obj interface{}) bool { 19 | if obj == nil { 20 | return true 21 | } 22 | objEFace := unpackEFace(obj) 23 | assertType("Type.IsNil argument 1", type2.ptrRType, objEFace.rtype) 24 | return type2.UnsafeIsNil(objEFace.data) 25 | } 26 | 27 | func (type2 *UnsafePtrType) UnsafeIsNil(ptr unsafe.Pointer) bool { 28 | if ptr == nil { 29 | return true 30 | } 31 | return *(*unsafe.Pointer)(ptr) == nil 32 | } 33 | 34 | func (type2 *UnsafePtrType) LikePtr() bool { 35 | return true 36 | } 37 | 38 | func (type2 *UnsafePtrType) Indirect(obj interface{}) interface{} { 39 | objEFace := unpackEFace(obj) 40 | assertType("Type.Indirect argument 1", type2.ptrRType, objEFace.rtype) 41 | return type2.UnsafeIndirect(objEFace.data) 42 | } 43 | 44 | func (type2 *UnsafePtrType) UnsafeIndirect(ptr unsafe.Pointer) interface{} { 45 | return packEFace(type2.rtype, *(*unsafe.Pointer)(ptr)) 46 | } 47 | -------------------------------------------------------------------------------- /internal/pcscommand/tree.go: -------------------------------------------------------------------------------- 1 | package pcscommand 2 | 3 | import ( 4 | "fmt" 5 | "github.com/iikira/BaiduPCS-Go/baidupcs" 6 | "strings" 7 | ) 8 | 9 | const ( 10 | indentPrefix = "│ " 11 | pathPrefix = "├──" 12 | lastFilePrefix = "└──" 13 | ) 14 | 15 | func getTree(path string, depth int) { 16 | var ( 17 | err error 18 | files baidupcs.FileDirectoryList 19 | ) 20 | if depth == 0 { 21 | path, err = getAbsPath(path) 22 | if err != nil { 23 | fmt.Println(err) 24 | return 25 | } 26 | } 27 | 28 | files, err = GetBaiduPCS().FilesDirectoriesList(path, baidupcs.DefaultOrderOptions) 29 | if err != nil { 30 | fmt.Println(err) 31 | return 32 | } 33 | 34 | var ( 35 | prefix = pathPrefix 36 | fN = len(files) 37 | indentPrefixStr = strings.Repeat(indentPrefix, depth) 38 | ) 39 | for i, file := range files { 40 | if file.Isdir { 41 | fmt.Printf("%v%v %v/\n", indentPrefixStr, pathPrefix, file.Filename) 42 | getTree(file.Path, depth+1) 43 | continue 44 | } 45 | 46 | if i+1 == fN { 47 | prefix = lastFilePrefix 48 | } 49 | 50 | fmt.Printf("%v%v %v\n", indentPrefixStr, prefix, file.Filename) 51 | } 52 | 53 | return 54 | } 55 | 56 | // RunTree 列出树形图 57 | func RunTree(path string) { 58 | getTree(path, 0) 59 | } 60 | -------------------------------------------------------------------------------- /pcsliner/linehistory.go: -------------------------------------------------------------------------------- 1 | package pcsliner 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | // LineHistory 命令行历史 9 | type LineHistory struct { 10 | historyFilePath string 11 | historyFile *os.File 12 | } 13 | 14 | // NewLineHistory 设置历史 15 | func NewLineHistory(filePath string) (lh *LineHistory, err error) { 16 | lh = &LineHistory{ 17 | historyFilePath: filePath, 18 | } 19 | 20 | lh.historyFile, err = os.OpenFile(filePath, os.O_RDWR|os.O_CREATE, 0644) 21 | if err != nil { 22 | return nil, err 23 | } 24 | 25 | return lh, nil 26 | } 27 | 28 | // DoWriteHistory 执行写入历史 29 | func (pl *PCSLiner) DoWriteHistory() (err error) { 30 | if pl.History == nil { 31 | return fmt.Errorf("history not set") 32 | } 33 | 34 | pl.History.historyFile, err = os.Create(pl.History.historyFilePath) 35 | if err != nil { 36 | return fmt.Errorf("写入历史错误, %s", err) 37 | } 38 | 39 | _, err = pl.State.WriteHistory(pl.History.historyFile) 40 | if err != nil { 41 | return fmt.Errorf("写入历史错误: %s", err) 42 | } 43 | 44 | return nil 45 | } 46 | 47 | // ReadHistory 读取历史 48 | func (pl *PCSLiner) ReadHistory() (err error) { 49 | if pl.History == nil { 50 | return fmt.Errorf("history not set") 51 | } 52 | 53 | _, err = pl.State.ReadHistory(pl.History.historyFile) 54 | return err 55 | } 56 | -------------------------------------------------------------------------------- /requester/downloader/range.go: -------------------------------------------------------------------------------- 1 | package downloader 2 | 3 | import ( 4 | "fmt" 5 | "sync/atomic" 6 | ) 7 | 8 | //Range 请求范围 9 | type Range struct { 10 | Begin int64 11 | End int64 12 | } 13 | 14 | //RangeList 请求范围列表 15 | type RangeList []*Range 16 | 17 | //Len 长度 18 | func (r *Range) Len() int64 { 19 | return r.LoadEnd() - r.LoadBegin() + 1 20 | } 21 | 22 | //LoadBegin 读取Begin, 原子操作 23 | func (r *Range) LoadBegin() int64 { 24 | return atomic.LoadInt64(&r.Begin) 25 | } 26 | 27 | //AddBegin 增加Begin, 原子操作 28 | func (r *Range) AddBegin(i int64) (newi int64) { 29 | return atomic.AddInt64(&r.Begin, i) 30 | } 31 | 32 | //LoadEnd 读取End, 原子操作 33 | func (r *Range) LoadEnd() int64 { 34 | return atomic.LoadInt64(&r.End) 35 | } 36 | 37 | //StoreBegin 储存End, 原子操作 38 | func (r *Range) StoreBegin(end int64) { 39 | atomic.StoreInt64(&r.Begin, end) 40 | } 41 | 42 | //StoreEnd 储存End, 原子操作 43 | func (r *Range) StoreEnd(end int64) { 44 | atomic.StoreInt64(&r.End, end) 45 | } 46 | 47 | func (r *Range) String() string { 48 | return fmt.Sprintf("{%d-%d}", r.LoadBegin(), r.LoadEnd()) 49 | } 50 | 51 | //Len 获取所有的Range长度 52 | func (rl *RangeList) Len() int64 { 53 | var l int64 54 | for _, wrange := range *rl { 55 | if wrange == nil { 56 | continue 57 | } 58 | l += wrange.Len() 59 | } 60 | return l 61 | } 62 | -------------------------------------------------------------------------------- /vendor/github.com/urfave/cli/category.go: -------------------------------------------------------------------------------- 1 | package cli 2 | 3 | // CommandCategories is a slice of *CommandCategory. 4 | type CommandCategories []*CommandCategory 5 | 6 | // CommandCategory is a category containing commands. 7 | type CommandCategory struct { 8 | Name string 9 | Commands Commands 10 | } 11 | 12 | func (c CommandCategories) Less(i, j int) bool { 13 | return c[i].Name < c[j].Name 14 | } 15 | 16 | func (c CommandCategories) Len() int { 17 | return len(c) 18 | } 19 | 20 | func (c CommandCategories) Swap(i, j int) { 21 | c[i], c[j] = c[j], c[i] 22 | } 23 | 24 | // AddCommand adds a command to a category. 25 | func (c CommandCategories) AddCommand(category string, command Command) CommandCategories { 26 | for _, commandCategory := range c { 27 | if commandCategory.Name == category { 28 | commandCategory.Commands = append(commandCategory.Commands, command) 29 | return c 30 | } 31 | } 32 | return append(c, &CommandCategory{Name: category, Commands: []Command{command}}) 33 | } 34 | 35 | // VisibleCommands returns a slice of the Commands with Hidden=false 36 | func (c *CommandCategory) VisibleCommands() []Command { 37 | ret := []Command{} 38 | for _, command := range c.Commands { 39 | if !command.Hidden { 40 | ret = append(ret, command) 41 | } 42 | } 43 | return ret 44 | } 45 | -------------------------------------------------------------------------------- /requester/downloader/example.go: -------------------------------------------------------------------------------- 1 | package downloader 2 | 3 | import ( 4 | "fmt" 5 | "github.com/iikira/BaiduPCS-Go/pcsutil/converter" 6 | "io" 7 | "os" 8 | ) 9 | 10 | // DoDownload 执行下载 11 | func DoDownload(durl string, savePath string, cfg *Config) { 12 | var ( 13 | file io.WriterAt 14 | err error 15 | ) 16 | 17 | if savePath != "" { 18 | file, err = os.Create(savePath) 19 | if err != nil { 20 | fmt.Println(err) 21 | return 22 | } 23 | } else { 24 | file = nil 25 | } 26 | 27 | download := NewDownloader(durl, file, cfg) 28 | 29 | exitDownloadFunc := make(chan struct{}) 30 | 31 | download.OnExecute(func() { 32 | dc := download.GetDownloadStatusChan() 33 | var ts string 34 | 35 | for { 36 | select { 37 | case v, ok := <-dc: 38 | if !ok { // channel 已经关闭 39 | return 40 | } 41 | 42 | if v.TotalSize() <= 0 { 43 | ts = converter.ConvertFileSize(v.Downloaded(), 2) 44 | } else { 45 | ts = converter.ConvertFileSize(v.TotalSize(), 2) 46 | } 47 | 48 | fmt.Printf("\r ↓ %s/%s %s/s in %s ............", 49 | converter.ConvertFileSize(v.Downloaded(), 2), 50 | ts, 51 | converter.ConvertFileSize(v.SpeedsPerSecond(), 2), 52 | v.TimeElapsed(), 53 | ) 54 | } 55 | } 56 | }) 57 | 58 | download.Execute() 59 | close(exitDownloadFunc) 60 | } 61 | -------------------------------------------------------------------------------- /requester/rio/speeds/speeds.go: -------------------------------------------------------------------------------- 1 | // Package speeds 速度计算工具包 2 | package speeds 3 | 4 | import ( 5 | "sync" 6 | "sync/atomic" 7 | "time" 8 | "unsafe" 9 | ) 10 | 11 | //Adder 增加 12 | type Adder interface { 13 | Add(int64) 14 | } 15 | 16 | // Speeds 统计下载速度 17 | type Speeds struct { 18 | readed int64 19 | timeElapsed time.Duration 20 | inited bool 21 | nowTime time.Time 22 | once sync.Once 23 | } 24 | 25 | // Init 初始化 26 | func (sps *Speeds) Init() { 27 | sps.once.Do(func() { 28 | if sps.nowTime.Unix() == 0 { 29 | sps.nowTime = time.Now() 30 | } 31 | sps.inited = true 32 | }) 33 | } 34 | 35 | // Add 原子操作, 增加数据量 36 | func (sps *Speeds) Add(readed int64) { 37 | // 初始化 38 | if !sps.inited { 39 | sps.Init() 40 | } 41 | 42 | atomic.AddInt64(&sps.readed, readed) 43 | } 44 | 45 | // GetSpeedsPerSecond 结束统计速度, 并返回每秒的速度 46 | func (sps *Speeds) GetSpeedsPerSecond() (speeds int64) { 47 | if !sps.inited { 48 | sps.Init() 49 | } 50 | 51 | int64Ptr := (*int64)(unsafe.Pointer(&sps.timeElapsed)) 52 | atomic.StoreInt64(int64Ptr, (int64)(time.Since(sps.nowTime))) 53 | if atomic.LoadInt64(int64Ptr) == 0 { 54 | return 0 55 | } 56 | 57 | speeds = int64(float64(atomic.LoadInt64(&sps.readed)) / sps.timeElapsed.Seconds()) 58 | 59 | atomic.StoreInt64(&sps.readed, 0) 60 | sps.nowTime = time.Now() 61 | return 62 | } 63 | -------------------------------------------------------------------------------- /requester/downloader/utils.go: -------------------------------------------------------------------------------- 1 | package downloader 2 | 3 | import ( 4 | "github.com/iikira/BaiduPCS-Go/requester" 5 | mathrand "math/rand" 6 | "mime" 7 | "net/url" 8 | "path" 9 | "time" 10 | ) 11 | 12 | // RandomNumber 生成指定区间随机数 13 | func RandomNumber(min, max int) int { 14 | s := mathrand.NewSource(time.Now().UnixNano()) 15 | r := mathrand.New(s) 16 | if min > max { 17 | min, max = max, min 18 | } 19 | return r.Intn(max-min) + min 20 | } 21 | 22 | // GetFileName 获取文件名 23 | func GetFileName(uri string, client *requester.HTTPClient) (filename string, err error) { 24 | if client == nil { 25 | client = requester.NewHTTPClient() 26 | } 27 | 28 | resp, err := client.Req("HEAD", uri, nil, nil) 29 | if resp != nil { 30 | defer resp.Body.Close() 31 | } 32 | if err != nil { 33 | return "", err 34 | } 35 | 36 | _, params, err := mime.ParseMediaType(resp.Header.Get("Content-Disposition")) 37 | if err != nil { 38 | return "", err 39 | } 40 | 41 | filename, err = url.QueryUnescape(params["filename"]) 42 | if err != nil { 43 | return 44 | } 45 | 46 | if filename == "" { 47 | filename = path.Base(uri) 48 | } 49 | 50 | return 51 | } 52 | 53 | //trigger 用于触发事件 54 | func trigger(f func()) { 55 | if f == nil { 56 | return 57 | } 58 | go f() 59 | } 60 | 61 | func fixCacheSize(size *int) { 62 | if *size < 1024 { 63 | *size = 1024 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /vendor/github.com/urfave/cli/funcs.go: -------------------------------------------------------------------------------- 1 | package cli 2 | 3 | // BashCompleteFunc is an action to execute when the bash-completion flag is set 4 | type BashCompleteFunc func(*Context) 5 | 6 | // BeforeFunc is an action to execute before any subcommands are run, but after 7 | // the context is ready if a non-nil error is returned, no subcommands are run 8 | type BeforeFunc func(*Context) error 9 | 10 | // AfterFunc is an action to execute after any subcommands are run, but after the 11 | // subcommand has finished it is run even if Action() panics 12 | type AfterFunc func(*Context) error 13 | 14 | // ActionFunc is the action to execute when no subcommands are specified 15 | type ActionFunc func(*Context) error 16 | 17 | // CommandNotFoundFunc is executed if the proper command cannot be found 18 | type CommandNotFoundFunc func(*Context, string) 19 | 20 | // OnUsageErrorFunc is executed if an usage error occurs. This is useful for displaying 21 | // customized usage error messages. This function is able to replace the 22 | // original error messages. If this function is not set, the "Incorrect usage" 23 | // is displayed and the execution is interrupted. 24 | type OnUsageErrorFunc func(context *Context, err error, isSubcommand bool) error 25 | 26 | // FlagStringFunc is used by the help generation to display a flag, which is 27 | // expected to be a single line. 28 | type FlagStringFunc func(Flag) string 29 | -------------------------------------------------------------------------------- /vendor/github.com/GeertJohan/go.rice/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Geert-Johan Riemer 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 14 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 17 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 20 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /pcsliner/pcsliner.go: -------------------------------------------------------------------------------- 1 | // Package pcsliner 命令行 readline 工具包 2 | package pcsliner 3 | 4 | import ( 5 | "github.com/peterh/liner" 6 | ) 7 | 8 | // PCSLiner 封装 *liner.State, 提供更简便的操作 9 | type PCSLiner struct { 10 | State *liner.State 11 | History *LineHistory 12 | 13 | tmode liner.ModeApplier 14 | lmode liner.ModeApplier 15 | 16 | paused bool 17 | } 18 | 19 | // NewLiner 返回 *PCSLiner, 默认设置允许 Ctrl+C 结束 20 | func NewLiner() *PCSLiner { 21 | pl := &PCSLiner{} 22 | pl.tmode, _ = liner.TerminalMode() 23 | 24 | line := liner.NewLiner() 25 | pl.lmode, _ = liner.TerminalMode() 26 | 27 | line.SetMultiLineMode(true) 28 | line.SetCtrlCAborts(true) 29 | 30 | pl.State = line 31 | 32 | return pl 33 | } 34 | 35 | // Pause 暂停服务 36 | func (pl *PCSLiner) Pause() error { 37 | if pl.paused { 38 | panic("PCSLiner already paused") 39 | } 40 | 41 | pl.paused = true 42 | pl.DoWriteHistory() 43 | 44 | return pl.tmode.ApplyMode() 45 | } 46 | 47 | // Resume 恢复服务 48 | func (pl *PCSLiner) Resume() error { 49 | if !pl.paused { 50 | panic("PCSLiner is not paused") 51 | } 52 | 53 | pl.paused = false 54 | 55 | return pl.lmode.ApplyMode() 56 | } 57 | 58 | // Close 关闭服务 59 | func (pl *PCSLiner) Close() (err error) { 60 | err = pl.State.Close() 61 | if err != nil { 62 | return err 63 | } 64 | 65 | if pl.History != nil && pl.History.historyFile != nil { 66 | return pl.History.historyFile.Close() 67 | } 68 | 69 | return nil 70 | } 71 | -------------------------------------------------------------------------------- /pcsutil/pcstime/time.go: -------------------------------------------------------------------------------- 1 | // Package pcstime 时间工具包 2 | package pcstime 3 | 4 | import ( 5 | "fmt" 6 | "time" 7 | ) 8 | 9 | var ( 10 | // CSTLocation 东八区时区 11 | CSTLocation = time.FixedZone("CST", 8*3600) 12 | ) 13 | 14 | /* 15 | BeijingTimeOption 根据给定的 get 返回时间格式. 16 | 17 | get: 时间格式 18 | 19 | "Refer": 2017-7-21 12:02:32.000 20 | "printLog": 2017-7-21_12:02:32 21 | "day": 21 22 | "ymd": 2017-7-21 23 | "hour": 12 24 | 默认时间戳: 1500609752 25 | */ 26 | func BeijingTimeOption(get string) string { 27 | //获取北京(东八区)时间 28 | now := time.Now().In(CSTLocation) 29 | year, mon, day := now.Date() 30 | hour, min, sec := now.Clock() 31 | millisecond := now.Nanosecond() / 1e6 32 | switch get { 33 | case "Refer": 34 | return fmt.Sprintf("%d-%d-%d %02d:%02d:%02d.%03d", year, mon, day, hour, min, sec, millisecond) 35 | case "printLog": 36 | return fmt.Sprintf("%d-%d-%d_%02dh%02dm%02ds", year, mon, day, hour, min, sec) 37 | case "day": 38 | return fmt.Sprint(day) 39 | case "ymd": 40 | return fmt.Sprintf("%d-%d-%d", year, mon, day) 41 | case "hour": 42 | return fmt.Sprint(hour) 43 | default: 44 | return fmt.Sprint(time.Now().Unix()) 45 | } 46 | } 47 | 48 | // FormatTime 将 Unix 时间戳, 转换为字符串 49 | func FormatTime(t int64) string { 50 | tt := time.Unix(t, 0).In(CSTLocation) 51 | year, mon, day := tt.Date() 52 | hour, min, sec := tt.Clock() 53 | return fmt.Sprintf("%d-%02d-%02d %02d:%02d:%02d", year, mon, day, hour, min, sec) 54 | } 55 | -------------------------------------------------------------------------------- /vendor/github.com/astaxie/beego/utils/rand.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 beego Author. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package utils 16 | 17 | import ( 18 | "crypto/rand" 19 | r "math/rand" 20 | "time" 21 | ) 22 | 23 | var alphaNum = []byte(`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`) 24 | 25 | // RandomCreateBytes generate random []byte by specify chars. 26 | func RandomCreateBytes(n int, alphabets ...byte) []byte { 27 | if len(alphabets) == 0 { 28 | alphabets = alphaNum 29 | } 30 | var bytes = make([]byte, n) 31 | var randBy bool 32 | if num, err := rand.Read(bytes); num != n || err != nil { 33 | r.Seed(time.Now().UnixNano()) 34 | randBy = true 35 | } 36 | for i, b := range bytes { 37 | if randBy { 38 | bytes[i] = alphabets[r.Intn(len(alphabets))] 39 | } else { 40 | bytes[i] = alphabets[b%byte(len(alphabets))] 41 | } 42 | } 43 | return bytes 44 | } 45 | -------------------------------------------------------------------------------- /vendor/github.com/json-iterator/go/any_int64.go: -------------------------------------------------------------------------------- 1 | package jsoniter 2 | 3 | import ( 4 | "strconv" 5 | ) 6 | 7 | type int64Any struct { 8 | baseAny 9 | val int64 10 | } 11 | 12 | func (any *int64Any) LastError() error { 13 | return nil 14 | } 15 | 16 | func (any *int64Any) ValueType() ValueType { 17 | return NumberValue 18 | } 19 | 20 | func (any *int64Any) MustBeValid() Any { 21 | return any 22 | } 23 | 24 | func (any *int64Any) ToBool() bool { 25 | return any.val != 0 26 | } 27 | 28 | func (any *int64Any) ToInt() int { 29 | return int(any.val) 30 | } 31 | 32 | func (any *int64Any) ToInt32() int32 { 33 | return int32(any.val) 34 | } 35 | 36 | func (any *int64Any) ToInt64() int64 { 37 | return any.val 38 | } 39 | 40 | func (any *int64Any) ToUint() uint { 41 | return uint(any.val) 42 | } 43 | 44 | func (any *int64Any) ToUint32() uint32 { 45 | return uint32(any.val) 46 | } 47 | 48 | func (any *int64Any) ToUint64() uint64 { 49 | return uint64(any.val) 50 | } 51 | 52 | func (any *int64Any) ToFloat32() float32 { 53 | return float32(any.val) 54 | } 55 | 56 | func (any *int64Any) ToFloat64() float64 { 57 | return float64(any.val) 58 | } 59 | 60 | func (any *int64Any) ToString() string { 61 | return strconv.FormatInt(any.val, 10) 62 | } 63 | 64 | func (any *int64Any) WriteTo(stream *Stream) { 65 | stream.WriteInt64(any.val) 66 | } 67 | 68 | func (any *int64Any) Parse() *Iterator { 69 | return nil 70 | } 71 | 72 | func (any *int64Any) GetInterface() interface{} { 73 | return any.val 74 | } 75 | -------------------------------------------------------------------------------- /vendor/github.com/json-iterator/go/any_int32.go: -------------------------------------------------------------------------------- 1 | package jsoniter 2 | 3 | import ( 4 | "strconv" 5 | ) 6 | 7 | type int32Any struct { 8 | baseAny 9 | val int32 10 | } 11 | 12 | func (any *int32Any) LastError() error { 13 | return nil 14 | } 15 | 16 | func (any *int32Any) ValueType() ValueType { 17 | return NumberValue 18 | } 19 | 20 | func (any *int32Any) MustBeValid() Any { 21 | return any 22 | } 23 | 24 | func (any *int32Any) ToBool() bool { 25 | return any.val != 0 26 | } 27 | 28 | func (any *int32Any) ToInt() int { 29 | return int(any.val) 30 | } 31 | 32 | func (any *int32Any) ToInt32() int32 { 33 | return any.val 34 | } 35 | 36 | func (any *int32Any) ToInt64() int64 { 37 | return int64(any.val) 38 | } 39 | 40 | func (any *int32Any) ToUint() uint { 41 | return uint(any.val) 42 | } 43 | 44 | func (any *int32Any) ToUint32() uint32 { 45 | return uint32(any.val) 46 | } 47 | 48 | func (any *int32Any) ToUint64() uint64 { 49 | return uint64(any.val) 50 | } 51 | 52 | func (any *int32Any) ToFloat32() float32 { 53 | return float32(any.val) 54 | } 55 | 56 | func (any *int32Any) ToFloat64() float64 { 57 | return float64(any.val) 58 | } 59 | 60 | func (any *int32Any) ToString() string { 61 | return strconv.FormatInt(int64(any.val), 10) 62 | } 63 | 64 | func (any *int32Any) WriteTo(stream *Stream) { 65 | stream.WriteInt32(any.val) 66 | } 67 | 68 | func (any *int32Any) Parse() *Iterator { 69 | return nil 70 | } 71 | 72 | func (any *int32Any) GetInterface() interface{} { 73 | return any.val 74 | } 75 | -------------------------------------------------------------------------------- /vendor/github.com/json-iterator/go/any_uint64.go: -------------------------------------------------------------------------------- 1 | package jsoniter 2 | 3 | import ( 4 | "strconv" 5 | ) 6 | 7 | type uint64Any struct { 8 | baseAny 9 | val uint64 10 | } 11 | 12 | func (any *uint64Any) LastError() error { 13 | return nil 14 | } 15 | 16 | func (any *uint64Any) ValueType() ValueType { 17 | return NumberValue 18 | } 19 | 20 | func (any *uint64Any) MustBeValid() Any { 21 | return any 22 | } 23 | 24 | func (any *uint64Any) ToBool() bool { 25 | return any.val != 0 26 | } 27 | 28 | func (any *uint64Any) ToInt() int { 29 | return int(any.val) 30 | } 31 | 32 | func (any *uint64Any) ToInt32() int32 { 33 | return int32(any.val) 34 | } 35 | 36 | func (any *uint64Any) ToInt64() int64 { 37 | return int64(any.val) 38 | } 39 | 40 | func (any *uint64Any) ToUint() uint { 41 | return uint(any.val) 42 | } 43 | 44 | func (any *uint64Any) ToUint32() uint32 { 45 | return uint32(any.val) 46 | } 47 | 48 | func (any *uint64Any) ToUint64() uint64 { 49 | return any.val 50 | } 51 | 52 | func (any *uint64Any) ToFloat32() float32 { 53 | return float32(any.val) 54 | } 55 | 56 | func (any *uint64Any) ToFloat64() float64 { 57 | return float64(any.val) 58 | } 59 | 60 | func (any *uint64Any) ToString() string { 61 | return strconv.FormatUint(any.val, 10) 62 | } 63 | 64 | func (any *uint64Any) WriteTo(stream *Stream) { 65 | stream.WriteUint64(any.val) 66 | } 67 | 68 | func (any *uint64Any) Parse() *Iterator { 69 | return nil 70 | } 71 | 72 | func (any *uint64Any) GetInterface() interface{} { 73 | return any.val 74 | } 75 | -------------------------------------------------------------------------------- /vendor/github.com/json-iterator/go/iter_array.go: -------------------------------------------------------------------------------- 1 | package jsoniter 2 | 3 | // ReadArray read array element, tells if the array has more element to read. 4 | func (iter *Iterator) ReadArray() (ret bool) { 5 | c := iter.nextToken() 6 | switch c { 7 | case 'n': 8 | iter.skipThreeBytes('u', 'l', 'l') 9 | return false // null 10 | case '[': 11 | c = iter.nextToken() 12 | if c != ']' { 13 | iter.unreadByte() 14 | return true 15 | } 16 | return false 17 | case ']': 18 | return false 19 | case ',': 20 | return true 21 | default: 22 | iter.ReportError("ReadArray", "expect [ or , or ] or n, but found "+string([]byte{c})) 23 | return 24 | } 25 | } 26 | 27 | // ReadArrayCB read array with callback 28 | func (iter *Iterator) ReadArrayCB(callback func(*Iterator) bool) (ret bool) { 29 | c := iter.nextToken() 30 | if c == '[' { 31 | c = iter.nextToken() 32 | if c != ']' { 33 | iter.unreadByte() 34 | if !callback(iter) { 35 | return false 36 | } 37 | c = iter.nextToken() 38 | for c == ',' { 39 | if !callback(iter) { 40 | return false 41 | } 42 | c = iter.nextToken() 43 | } 44 | if c != ']' { 45 | iter.ReportError("ReadArrayCB", "expect ] in the end, but found "+string([]byte{c})) 46 | return false 47 | } 48 | return true 49 | } 50 | return true 51 | } 52 | if c == 'n' { 53 | iter.skipThreeBytes('u', 'l', 'l') 54 | return true // null 55 | } 56 | iter.ReportError("ReadArrayCB", "expect [ or n, but found "+string([]byte{c})) 57 | return false 58 | } 59 | -------------------------------------------------------------------------------- /vendor/github.com/json-iterator/go/any_uint32.go: -------------------------------------------------------------------------------- 1 | package jsoniter 2 | 3 | import ( 4 | "strconv" 5 | ) 6 | 7 | type uint32Any struct { 8 | baseAny 9 | val uint32 10 | } 11 | 12 | func (any *uint32Any) LastError() error { 13 | return nil 14 | } 15 | 16 | func (any *uint32Any) ValueType() ValueType { 17 | return NumberValue 18 | } 19 | 20 | func (any *uint32Any) MustBeValid() Any { 21 | return any 22 | } 23 | 24 | func (any *uint32Any) ToBool() bool { 25 | return any.val != 0 26 | } 27 | 28 | func (any *uint32Any) ToInt() int { 29 | return int(any.val) 30 | } 31 | 32 | func (any *uint32Any) ToInt32() int32 { 33 | return int32(any.val) 34 | } 35 | 36 | func (any *uint32Any) ToInt64() int64 { 37 | return int64(any.val) 38 | } 39 | 40 | func (any *uint32Any) ToUint() uint { 41 | return uint(any.val) 42 | } 43 | 44 | func (any *uint32Any) ToUint32() uint32 { 45 | return any.val 46 | } 47 | 48 | func (any *uint32Any) ToUint64() uint64 { 49 | return uint64(any.val) 50 | } 51 | 52 | func (any *uint32Any) ToFloat32() float32 { 53 | return float32(any.val) 54 | } 55 | 56 | func (any *uint32Any) ToFloat64() float64 { 57 | return float64(any.val) 58 | } 59 | 60 | func (any *uint32Any) ToString() string { 61 | return strconv.FormatInt(int64(any.val), 10) 62 | } 63 | 64 | func (any *uint32Any) WriteTo(stream *Stream) { 65 | stream.WriteUint32(any.val) 66 | } 67 | 68 | func (any *uint32Any) Parse() *Iterator { 69 | return nil 70 | } 71 | 72 | func (any *uint32Any) GetInterface() interface{} { 73 | return any.val 74 | } 75 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/reflect2/safe_field.go: -------------------------------------------------------------------------------- 1 | package reflect2 2 | 3 | import ( 4 | "reflect" 5 | "unsafe" 6 | ) 7 | 8 | type safeField struct { 9 | reflect.StructField 10 | } 11 | 12 | func (field *safeField) Offset() uintptr { 13 | return field.StructField.Offset 14 | } 15 | 16 | func (field *safeField) Name() string { 17 | return field.StructField.Name 18 | } 19 | 20 | func (field *safeField) PkgPath() string { 21 | return field.StructField.PkgPath 22 | } 23 | 24 | func (field *safeField) Type() Type { 25 | panic("not implemented") 26 | } 27 | 28 | func (field *safeField) Tag() reflect.StructTag { 29 | return field.StructField.Tag 30 | } 31 | 32 | func (field *safeField) Index() []int { 33 | return field.StructField.Index 34 | } 35 | 36 | func (field *safeField) Anonymous() bool { 37 | return field.StructField.Anonymous 38 | } 39 | 40 | func (field *safeField) Set(obj interface{}, value interface{}) { 41 | val := reflect.ValueOf(obj).Elem() 42 | val.FieldByIndex(field.Index()).Set(reflect.ValueOf(value).Elem()) 43 | } 44 | 45 | func (field *safeField) UnsafeSet(obj unsafe.Pointer, value unsafe.Pointer) { 46 | panic("unsafe operation is not supported") 47 | } 48 | 49 | func (field *safeField) Get(obj interface{}) interface{} { 50 | val := reflect.ValueOf(obj).Elem().FieldByIndex(field.Index()) 51 | ptr := reflect.New(val.Type()) 52 | ptr.Elem().Set(val) 53 | return ptr.Interface() 54 | } 55 | 56 | func (field *safeField) UnsafeGet(obj unsafe.Pointer) unsafe.Pointer { 57 | panic("does not support unsafe operation") 58 | } -------------------------------------------------------------------------------- /baidupcs/util.go: -------------------------------------------------------------------------------- 1 | package baidupcs 2 | 3 | import ( 4 | "errors" 5 | "github.com/json-iterator/go" 6 | "io" 7 | "path" 8 | ) 9 | 10 | // Isdir 检查路径在网盘中是否为目录 11 | func (pcs *BaiduPCS) Isdir(pcspath string) (isdir bool, pcsError Error) { 12 | if path.Clean(pcspath) == "/" { 13 | return true, nil 14 | } 15 | 16 | f, pcsError := pcs.FilesDirectoriesMeta(pcspath) 17 | if pcsError != nil { 18 | return false, pcsError 19 | } 20 | 21 | return f.Isdir, nil 22 | } 23 | 24 | func (pcs *BaiduPCS) checkIsdir(op string, targetPath string) Error { 25 | // 检测文件是否存在于网盘路径 26 | // 很重要, 如果文件存在会直接覆盖!!! 即使是根目录! 27 | isdir, pcsError := pcs.Isdir(targetPath) 28 | if pcsError != nil { 29 | // 忽略远程服务端返回的错误 30 | if pcsError.ErrorType() != ErrTypeRemoteError { 31 | return pcsError 32 | } 33 | } 34 | 35 | errInfo := NewErrorInfo(op) 36 | if isdir { 37 | errInfo.errType = ErrTypeOthers 38 | errInfo.err = errors.New("保存路径不可以覆盖目录") 39 | return errInfo 40 | } 41 | return nil 42 | } 43 | 44 | // GetHTTPScheme 获取 http 协议, https 或 http 45 | func GetHTTPScheme(https bool) (scheme string) { 46 | if https { 47 | return "https" 48 | } 49 | return "http" 50 | } 51 | 52 | // decodeJSONError 解析json中的远端服务器返回的错误 53 | func decodeJSONError(op string, data io.Reader) Error { 54 | errInfo := NewErrorInfo(op) 55 | 56 | d := jsoniter.NewDecoder(data) 57 | err := d.Decode(errInfo) 58 | if err != nil { 59 | errInfo.jsonError(err) 60 | return errInfo 61 | } 62 | 63 | if errInfo.ErrCode != 0 { 64 | return errInfo 65 | } 66 | 67 | return nil 68 | } 69 | -------------------------------------------------------------------------------- /vendor/github.com/shiena/ansicolor/ansicolor.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 shiena Authors. All rights reserved. 2 | // Use of this source code is governed by a MIT-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package ansicolor provides color console in Windows as ANSICON. 6 | package ansicolor 7 | 8 | import "io" 9 | 10 | type outputMode int 11 | 12 | // DiscardNonColorEscSeq supports the divided color escape sequence. 13 | // But non-color escape sequence is not output. 14 | // Please use the OutputNonColorEscSeq If you want to output a non-color 15 | // escape sequences such as ncurses. However, it does not support the divided 16 | // color escape sequence. 17 | const ( 18 | _ outputMode = iota 19 | DiscardNonColorEscSeq 20 | OutputNonColorEscSeq 21 | ) 22 | 23 | // NewAnsiColorWriter creates and initializes a new ansiColorWriter 24 | // using io.Writer w as its initial contents. 25 | // In the console of Windows, which change the foreground and background 26 | // colors of the text by the escape sequence. 27 | // In the console of other systems, which writes to w all text. 28 | func NewAnsiColorWriter(w io.Writer) io.Writer { 29 | return NewModeAnsiColorWriter(w, DiscardNonColorEscSeq) 30 | } 31 | 32 | // NewModeAnsiColorWriter create and initializes a new ansiColorWriter 33 | // by specifying the outputMode. 34 | func NewModeAnsiColorWriter(w io.Writer, mode outputMode) io.Writer { 35 | if _, ok := w.(*ansiColorWriter); !ok { 36 | return &ansiColorWriter{ 37 | w: w, 38 | mode: mode, 39 | } 40 | } 41 | return w 42 | } 43 | -------------------------------------------------------------------------------- /internal/pcsweb/pcsweb.go: -------------------------------------------------------------------------------- 1 | // Package pcsweb web前端包 2 | package pcsweb 3 | 4 | import ( 5 | "fmt" 6 | "github.com/GeertJohan/go.rice" 7 | "net/http" 8 | ) 9 | 10 | var ( 11 | staticBox *rice.Box // go.rice 文件盒子 12 | templatesBox *rice.Box // go.rice 文件盒子 13 | ) 14 | 15 | func boxInit() (err error) { 16 | staticBox, err = rice.FindBox("static") 17 | if err != nil { 18 | return 19 | } 20 | 21 | templatesBox, err = rice.FindBox("template") 22 | if err != nil { 23 | return 24 | } 25 | 26 | return nil 27 | } 28 | 29 | // StartServer 开启web服务 30 | func StartServer(port uint) error { 31 | if port <= 0 || port > 65535 { 32 | return fmt.Errorf("invalid port %d", port) 33 | } 34 | 35 | err := boxInit() 36 | if err != nil { 37 | return err 38 | } 39 | 40 | http.HandleFunc("/", rootMiddleware) 41 | http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(staticBox.HTTPBox()))) 42 | http.HandleFunc("/about.html", middleware(aboutPage)) 43 | http.HandleFunc("/index.html", middleware(indexPage)) 44 | http.HandleFunc("/cgi-bin/baidu/pcs/file/list", activeAuthMiddleware(fileList)) 45 | return http.ListenAndServe(fmt.Sprintf(":%d", port), nil) 46 | } 47 | 48 | func aboutPage(w http.ResponseWriter, r *http.Request) { 49 | tmpl := boxTmplParse("index", "index.html", "about.html") 50 | checkErr(tmpl.Execute(w, nil)) 51 | } 52 | 53 | func indexPage(w http.ResponseWriter, r *http.Request) { 54 | r.ParseForm() 55 | 56 | tmpl := boxTmplParse("index", "index.html", "baidu/userinfo.html") 57 | checkErr(tmpl.Execute(w, r.Form.Get("path"))) 58 | } 59 | -------------------------------------------------------------------------------- /vendor/github.com/peterh/liner/fallbackinput.go: -------------------------------------------------------------------------------- 1 | // +build !windows,!linux,!darwin,!openbsd,!freebsd,!netbsd 2 | 3 | package liner 4 | 5 | import ( 6 | "bufio" 7 | "errors" 8 | "os" 9 | ) 10 | 11 | // State represents an open terminal 12 | type State struct { 13 | commonState 14 | } 15 | 16 | // Prompt displays p, and then waits for user input. Prompt does not support 17 | // line editing on this operating system. 18 | func (s *State) Prompt(p string) (string, error) { 19 | return s.promptUnsupported(p) 20 | } 21 | 22 | // PasswordPrompt is not supported in this OS. 23 | func (s *State) PasswordPrompt(p string) (string, error) { 24 | return "", errors.New("liner: function not supported in this terminal") 25 | } 26 | 27 | // NewLiner initializes a new *State 28 | // 29 | // Note that this operating system uses a fallback mode without line 30 | // editing. Patches welcome. 31 | func NewLiner() *State { 32 | var s State 33 | s.r = bufio.NewReader(os.Stdin) 34 | return &s 35 | } 36 | 37 | // Close returns the terminal to its previous mode 38 | func (s *State) Close() error { 39 | return nil 40 | } 41 | 42 | // TerminalSupported returns false because line editing is not 43 | // supported on this platform. 44 | func TerminalSupported() bool { 45 | return false 46 | } 47 | 48 | type noopMode struct{} 49 | 50 | func (n noopMode) ApplyMode() error { 51 | return nil 52 | } 53 | 54 | // TerminalMode returns a noop InputModeSetter on this platform. 55 | func TerminalMode() (ModeApplier, error) { 56 | return noopMode{}, nil 57 | } 58 | 59 | const cursorColumn = true 60 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/reflect2/unsafe_eface.go: -------------------------------------------------------------------------------- 1 | package reflect2 2 | 3 | import ( 4 | "unsafe" 5 | "reflect" 6 | ) 7 | 8 | type eface struct { 9 | rtype unsafe.Pointer 10 | data unsafe.Pointer 11 | } 12 | 13 | func unpackEFace(obj interface{}) *eface { 14 | return (*eface)(unsafe.Pointer(&obj)) 15 | } 16 | 17 | func packEFace(rtype unsafe.Pointer, data unsafe.Pointer) interface{} { 18 | var i interface{} 19 | e := (*eface)(unsafe.Pointer(&i)) 20 | e.rtype = rtype 21 | e.data = data 22 | return i 23 | } 24 | 25 | type UnsafeEFaceType struct { 26 | unsafeType 27 | } 28 | 29 | func newUnsafeEFaceType(cfg *frozenConfig, type1 reflect.Type) *UnsafeEFaceType { 30 | return &UnsafeEFaceType{ 31 | unsafeType: *newUnsafeType(cfg, type1), 32 | } 33 | } 34 | 35 | func (type2 *UnsafeEFaceType) IsNil(obj interface{}) bool { 36 | if obj == nil { 37 | return true 38 | } 39 | objEFace := unpackEFace(obj) 40 | assertType("Type.IsNil argument 1", type2.ptrRType, objEFace.rtype) 41 | return type2.UnsafeIsNil(objEFace.data) 42 | } 43 | 44 | func (type2 *UnsafeEFaceType) UnsafeIsNil(ptr unsafe.Pointer) bool { 45 | if ptr == nil { 46 | return true 47 | } 48 | return unpackEFace(*(*interface{})(ptr)).data == nil 49 | } 50 | 51 | func (type2 *UnsafeEFaceType) Indirect(obj interface{}) interface{} { 52 | objEFace := unpackEFace(obj) 53 | assertType("Type.Indirect argument 1", type2.ptrRType, objEFace.rtype) 54 | return type2.UnsafeIndirect(objEFace.data) 55 | } 56 | 57 | func (type2 *UnsafeEFaceType) UnsafeIndirect(ptr unsafe.Pointer) interface{} { 58 | return *(*interface{})(ptr) 59 | } -------------------------------------------------------------------------------- /vendor/github.com/olekukonko/tablewriter/csv.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 Oleku Konko All rights reserved. 2 | // Use of this source code is governed by a MIT 3 | // license that can be found in the LICENSE file. 4 | 5 | // This module is a Table Writer API for the Go Programming Language. 6 | // The protocols were written in pure Go and works on windows and unix systems 7 | 8 | package tablewriter 9 | 10 | import ( 11 | "encoding/csv" 12 | "io" 13 | "os" 14 | ) 15 | 16 | // Start A new table by importing from a CSV file 17 | // Takes io.Writer and csv File name 18 | func NewCSV(writer io.Writer, fileName string, hasHeader bool) (*Table, error) { 19 | file, err := os.Open(fileName) 20 | if err != nil { 21 | return &Table{}, err 22 | } 23 | defer file.Close() 24 | csvReader := csv.NewReader(file) 25 | t, err := NewCSVReader(writer, csvReader, hasHeader) 26 | return t, err 27 | } 28 | 29 | // Start a New Table Writer with csv.Reader 30 | // This enables customisation such as reader.Comma = ';' 31 | // See http://golang.org/src/pkg/encoding/csv/reader.go?s=3213:3671#L94 32 | func NewCSVReader(writer io.Writer, csvReader *csv.Reader, hasHeader bool) (*Table, error) { 33 | t := NewWriter(writer) 34 | if hasHeader { 35 | // Read the first row 36 | headers, err := csvReader.Read() 37 | if err != nil { 38 | return &Table{}, err 39 | } 40 | t.SetHeader(headers) 41 | } 42 | for { 43 | record, err := csvReader.Read() 44 | if err == io.EOF { 45 | break 46 | } else if err != nil { 47 | return &Table{}, err 48 | } 49 | t.Append(record) 50 | } 51 | return t, nil 52 | } 53 | -------------------------------------------------------------------------------- /vendor/github.com/kardianos/osext/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/reflect2/unsafe_iface.go: -------------------------------------------------------------------------------- 1 | package reflect2 2 | 3 | import ( 4 | "unsafe" 5 | "reflect" 6 | ) 7 | 8 | type iface struct { 9 | itab *itab 10 | data unsafe.Pointer 11 | } 12 | 13 | type itab struct { 14 | ignore unsafe.Pointer 15 | rtype unsafe.Pointer 16 | } 17 | 18 | func IFaceToEFace(ptr unsafe.Pointer) interface{} { 19 | iface := (*iface)(ptr) 20 | if iface.itab == nil { 21 | return nil 22 | } 23 | return packEFace(iface.itab.rtype, iface.data) 24 | } 25 | 26 | type UnsafeIFaceType struct { 27 | unsafeType 28 | } 29 | 30 | func newUnsafeIFaceType(cfg *frozenConfig, type1 reflect.Type) *UnsafeIFaceType { 31 | return &UnsafeIFaceType{ 32 | unsafeType: *newUnsafeType(cfg, type1), 33 | } 34 | } 35 | 36 | func (type2 *UnsafeIFaceType) Indirect(obj interface{}) interface{} { 37 | objEFace := unpackEFace(obj) 38 | assertType("Type.Indirect argument 1", type2.ptrRType, objEFace.rtype) 39 | return type2.UnsafeIndirect(objEFace.data) 40 | } 41 | 42 | func (type2 *UnsafeIFaceType) UnsafeIndirect(ptr unsafe.Pointer) interface{} { 43 | return IFaceToEFace(ptr) 44 | } 45 | 46 | func (type2 *UnsafeIFaceType) IsNil(obj interface{}) bool { 47 | if obj == nil { 48 | return true 49 | } 50 | objEFace := unpackEFace(obj) 51 | assertType("Type.IsNil argument 1", type2.ptrRType, objEFace.rtype) 52 | return type2.UnsafeIsNil(objEFace.data) 53 | } 54 | 55 | func (type2 *UnsafeIFaceType) UnsafeIsNil(ptr unsafe.Pointer) bool { 56 | if ptr == nil { 57 | return true 58 | } 59 | iface := (*iface)(ptr) 60 | if iface.itab == nil { 61 | return true 62 | } 63 | return false 64 | } -------------------------------------------------------------------------------- /pcscache/dir_cache.go: -------------------------------------------------------------------------------- 1 | // Package pcscache 缓存包 2 | package pcscache 3 | 4 | import ( 5 | "github.com/iikira/BaiduPCS-Go/baidupcs" 6 | "time" 7 | ) 8 | 9 | type dirCache struct { 10 | fdl map[string]*baidupcs.FileDirectoryList 11 | lifeTime time.Duration // 生命周期 12 | gcStarted bool 13 | } 14 | 15 | // Set 设置网盘目录缓存 16 | func (dc *dirCache) Set(path string, dirInfo *baidupcs.FileDirectoryList) { 17 | dc.fdl[path] = dirInfo 18 | } 19 | 20 | // Existed 检测缓存是否存在 21 | func (dc *dirCache) Existed(path string) bool { 22 | _, existed := dc.fdl[path] 23 | return existed 24 | } 25 | 26 | // Get 取出网盘目录缓存 27 | func (dc *dirCache) Get(path string) *baidupcs.FileDirectoryList { 28 | return dc.fdl[path] 29 | } 30 | 31 | // FindFileDirectory 网盘目录缓存内查找文件 32 | func (dc *dirCache) FindFileDirectory(path, filename string) *baidupcs.FileDirectory { 33 | fdl := dc.Get(path) 34 | if fdl == nil { 35 | return nil 36 | } 37 | for _, fd := range *fdl { 38 | if fd.Filename == filename { 39 | return fd 40 | } 41 | } 42 | return nil 43 | } 44 | 45 | func (dc *dirCache) SetLifeTime(t time.Duration) { 46 | dc.lifeTime = t 47 | } 48 | 49 | // GC 缓存回收 50 | func (dc *dirCache) GC() { 51 | if dc.gcStarted { 52 | return 53 | } 54 | 55 | dc.gcStarted = true 56 | go func() { 57 | for { 58 | time.Sleep(dc.lifeTime) // 这样可以动态修改 lifetime 59 | dc.DelAll() 60 | } 61 | }() 62 | } 63 | 64 | // Del 删除网盘目录缓存 65 | func (dc *dirCache) Del(path string) { 66 | delete(dc.fdl, path) 67 | } 68 | 69 | // DelAll 清空网盘目录缓存 70 | func (dc *dirCache) DelAll() { 71 | for k := range dc.fdl { 72 | delete(dc.fdl, k) 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /vendor/github.com/iikira/args/README.md: -------------------------------------------------------------------------------- 1 | args 2 | ==== 3 | 4 | command line argument parser 5 | 6 | Given a string (the "command line") it splits into words separated by white spaces, respecting quotes (single and double) and the escape character (backslash) 7 | 8 | ## Installation 9 | 10 | $ go get github.com/gobs/args 11 | 12 | ## Documentation 13 | http://godoc.org/github.com/gobs/args 14 | 15 | ## Example 16 | 17 | import "github.com/gobs/args" 18 | 19 | s := `one two three "double quotes" 'single quotes' arg\ with\ spaces "\"quotes\" in 'quotes'" '"quotes" in \'quotes'"` 20 | 21 | for i, arg := range GetArgs(s) { 22 | fmt.Println(i, arg) 23 | } 24 | 25 | You can also "parse" the arguments and divide them in "options" and "parameters": 26 | 27 | import "github.com/gobs/args" 28 | 29 | s := "-l --number=42 -where=here -- -not-an-option- one two three" 30 | parsed := ParseArgs(s) 31 | 32 | fmt.Println("options:", parsed.Options) 33 | fmt.Println("arguments:", parsed.Arguments) 34 | 35 | Or parse using flag.FlagSet: 36 | 37 | import "github.com/gobs/args" 38 | 39 | s := "-l --number=42 -where=here -- -not-an-option- one two three" 40 | flags := args.NewFlags("test") 41 | 42 | list := flags.Bool("l", false, "list something") 43 | num := flags.Int("number", 0, "a number option") 44 | where := flags.String("where", "", "a string option") 45 | 46 | flags.Usage() 47 | 48 | args.ParseFlags(flags, s) 49 | 50 | fmt.Println("list:", *list) 51 | fmt.Println("num:", *num) 52 | fmt.Println("where:", *where) 53 | fmt.Println("args:", flags.Args()) 54 | -------------------------------------------------------------------------------- /vendor/github.com/json-iterator/go/any_float.go: -------------------------------------------------------------------------------- 1 | package jsoniter 2 | 3 | import ( 4 | "strconv" 5 | ) 6 | 7 | type floatAny struct { 8 | baseAny 9 | val float64 10 | } 11 | 12 | func (any *floatAny) Parse() *Iterator { 13 | return nil 14 | } 15 | 16 | func (any *floatAny) ValueType() ValueType { 17 | return NumberValue 18 | } 19 | 20 | func (any *floatAny) MustBeValid() Any { 21 | return any 22 | } 23 | 24 | func (any *floatAny) LastError() error { 25 | return nil 26 | } 27 | 28 | func (any *floatAny) ToBool() bool { 29 | return any.ToFloat64() != 0 30 | } 31 | 32 | func (any *floatAny) ToInt() int { 33 | return int(any.val) 34 | } 35 | 36 | func (any *floatAny) ToInt32() int32 { 37 | return int32(any.val) 38 | } 39 | 40 | func (any *floatAny) ToInt64() int64 { 41 | return int64(any.val) 42 | } 43 | 44 | func (any *floatAny) ToUint() uint { 45 | if any.val > 0 { 46 | return uint(any.val) 47 | } 48 | return 0 49 | } 50 | 51 | func (any *floatAny) ToUint32() uint32 { 52 | if any.val > 0 { 53 | return uint32(any.val) 54 | } 55 | return 0 56 | } 57 | 58 | func (any *floatAny) ToUint64() uint64 { 59 | if any.val > 0 { 60 | return uint64(any.val) 61 | } 62 | return 0 63 | } 64 | 65 | func (any *floatAny) ToFloat32() float32 { 66 | return float32(any.val) 67 | } 68 | 69 | func (any *floatAny) ToFloat64() float64 { 70 | return any.val 71 | } 72 | 73 | func (any *floatAny) ToString() string { 74 | return strconv.FormatFloat(any.val, 'E', -1, 64) 75 | } 76 | 77 | func (any *floatAny) WriteTo(stream *Stream) { 78 | stream.WriteFloat64(any.val) 79 | } 80 | 81 | func (any *floatAny) GetInterface() interface{} { 82 | return any.val 83 | } 84 | -------------------------------------------------------------------------------- /pcsverbose/pcsverbose.go: -------------------------------------------------------------------------------- 1 | // Package pcsverbose 调试包 2 | package pcsverbose 3 | 4 | import ( 5 | "fmt" 6 | "io" 7 | "os" 8 | ) 9 | 10 | const ( 11 | // EnvVerbose 启用调试环境变量 12 | EnvVerbose = "BAIDUPCS_GO_VERBOSE" 13 | ) 14 | 15 | var ( 16 | // IsVerbose 是否调试 17 | IsVerbose = os.Getenv(EnvVerbose) == "1" 18 | 19 | // Outputs 输出 20 | Outputs = []io.Writer{os.Stderr} 21 | ) 22 | 23 | // PCSVerbose 调试 24 | type PCSVerbose struct { 25 | Module string 26 | } 27 | 28 | // New 根据module, 初始化PCSVerbose 29 | func New(module string) *PCSVerbose { 30 | return &PCSVerbose{ 31 | Module: module, 32 | } 33 | } 34 | 35 | // Info 提示 36 | func (pv *PCSVerbose) Info(l string) { 37 | Verbosef("DEBUG: %s INFO: %s\n", pv.Module, l) 38 | } 39 | 40 | // Infof 提示, 格式输出 41 | func (pv *PCSVerbose) Infof(format string, a ...interface{}) { 42 | Verbosef("DEBUG: %s INFO: %s", pv.Module, fmt.Sprintf(format, a...)) 43 | } 44 | 45 | // Warn 警告 46 | func (pv *PCSVerbose) Warn(l string) { 47 | Verbosef("DEBUG: %s WARN: %s\n", pv.Module, l) 48 | } 49 | 50 | // Warnf 警告, 格式输出 51 | func (pv *PCSVerbose) Warnf(format string, a ...interface{}) { 52 | Verbosef("DEBUG: %s WARN: %s", pv.Module, fmt.Sprintf(format, a...)) 53 | } 54 | 55 | // Verbosef 调试格式输出 56 | func Verbosef(format string, a ...interface{}) (n int, err error) { 57 | if IsVerbose { 58 | for _, Output := range Outputs { 59 | n, err = fmt.Fprintf(Output, format, a...) 60 | } 61 | } 62 | return 63 | } 64 | 65 | // Verboseln 调试输出一行 66 | func Verboseln(a ...interface{}) (n int, err error) { 67 | if IsVerbose { 68 | for _, Output := range Outputs { 69 | n, err = fmt.Fprintln(Output, a...) 70 | } 71 | } 72 | return 73 | } 74 | -------------------------------------------------------------------------------- /baidupcs/jsontable.go: -------------------------------------------------------------------------------- 1 | package baidupcs 2 | 3 | import ( 4 | "github.com/iikira/BaiduPCS-Go/pcstable" 5 | "github.com/json-iterator/go" 6 | "strconv" 7 | "strings" 8 | ) 9 | 10 | // PathJSON 网盘路径 11 | type PathJSON struct { 12 | Path string `json:"path"` 13 | } 14 | 15 | // PathsListJSON 网盘路径列表 16 | type PathsListJSON struct { 17 | List []*PathJSON `json:"list"` 18 | } 19 | 20 | // CpMvJSON 源文件目录的地址和目标文件目录的地址 21 | type CpMvJSON struct { 22 | From string `json:"from"` // 源文件或目录 23 | To string `json:"to"` // 目标文件或目录 24 | } 25 | 26 | // CpMvListJSON []*CpMvJSON 对象数组 27 | type CpMvListJSON struct { 28 | List []*CpMvJSON `json:"list"` 29 | } 30 | 31 | // JSON json 数据构造 32 | func (plj *PathsListJSON) JSON(paths ...string) (data []byte, err error) { 33 | plj.List = make([]*PathJSON, len(paths)) 34 | 35 | for k := range paths { 36 | plj.List[k] = &PathJSON{ 37 | Path: paths[k], 38 | } 39 | } 40 | 41 | data, err = jsoniter.Marshal(plj) 42 | return 43 | } 44 | 45 | // JSON json 数据构造 46 | func (cj *CpMvJSON) JSON() (data []byte, err error) { 47 | data, err = jsoniter.Marshal(cj) 48 | return 49 | } 50 | 51 | // JSON json 数据构造 52 | func (clj *CpMvListJSON) JSON() (data []byte, err error) { 53 | data, err = jsoniter.Marshal(clj) 54 | return 55 | } 56 | 57 | func (clj *CpMvListJSON) String() string { 58 | builder := &strings.Builder{} 59 | 60 | tb := pcstable.NewTable(builder) 61 | tb.SetHeader([]string{"#", "原路径", "目标路径"}) 62 | 63 | for k := range clj.List { 64 | if clj.List[k] == nil { 65 | continue 66 | } 67 | tb.Append([]string{strconv.Itoa(k), clj.List[k].From, clj.List[k].To}) 68 | } 69 | 70 | tb.Render() 71 | return builder.String() 72 | } 73 | -------------------------------------------------------------------------------- /vendor/github.com/GeertJohan/go.rice/config.go: -------------------------------------------------------------------------------- 1 | package rice 2 | 3 | // LocateMethod defines how a box is located. 4 | type LocateMethod int 5 | 6 | const ( 7 | LocateFS = LocateMethod(iota) // Locate on the filesystem according to package path. 8 | LocateAppended // Locate boxes appended to the executable. 9 | LocateEmbedded // Locate embedded boxes. 10 | LocateWorkingDirectory // Locate on the binary working directory 11 | ) 12 | 13 | // Config allows customizing the box lookup behavior. 14 | type Config struct { 15 | // LocateOrder defines the priority order that boxes are searched for. By 16 | // default, the package global FindBox searches for embedded boxes first, 17 | // then appended boxes, and then finally boxes on the filesystem. That 18 | // search order may be customized by provided the ordered list here. Leaving 19 | // out a particular method will omit that from the search space. For 20 | // example, []LocateMethod{LocateEmbedded, LocateAppended} will never search 21 | // the filesystem for boxes. 22 | LocateOrder []LocateMethod 23 | } 24 | 25 | // FindBox searches for boxes using the LocateOrder of the config. 26 | func (c *Config) FindBox(boxName string) (*Box, error) { 27 | return findBox(boxName, c.LocateOrder) 28 | } 29 | 30 | // MustFindBox searches for boxes using the LocateOrder of the config, like 31 | // FindBox does. It does not return an error, instead it panics when an error 32 | // occurs. 33 | func (c *Config) MustFindBox(boxName string) *Box { 34 | box, err := findBox(boxName, c.LocateOrder) 35 | if err != nil { 36 | panic(err) 37 | } 38 | return box 39 | } 40 | -------------------------------------------------------------------------------- /Gopkg.toml: -------------------------------------------------------------------------------- 1 | # Gopkg.toml example 2 | # 3 | # Refer to https://golang.github.io/dep/docs/Gopkg.toml.html 4 | # for detailed Gopkg.toml documentation. 5 | # 6 | # required = ["github.com/user/thing/cmd/thing"] 7 | # ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] 8 | # 9 | # [[constraint]] 10 | # name = "github.com/user/project" 11 | # version = "1.0.0" 12 | # 13 | # [[constraint]] 14 | # name = "github.com/user/project2" 15 | # branch = "dev" 16 | # source = "github.com/myfork/project2" 17 | # 18 | # [[override]] 19 | # name = "github.com/x/y" 20 | # version = "2.4.0" 21 | # 22 | # [prune] 23 | # non-go = false 24 | # go-tests = true 25 | # unused-packages = true 26 | 27 | 28 | [[constraint]] 29 | branch = "master" 30 | name = "github.com/GeertJohan/go.rice" 31 | 32 | [[constraint]] 33 | name = "github.com/fatih/color" 34 | version = "0.1.0" 35 | 36 | [[constraint]] 37 | branch = "master" 38 | name = "github.com/iikira/Baidu-Login" 39 | 40 | [[constraint]] 41 | branch = "master" 42 | name = "github.com/iikira/args" 43 | 44 | [[constraint]] 45 | branch = "master" 46 | name = "github.com/iikira/baidu-tools" 47 | 48 | [[constraint]] 49 | name = "github.com/json-iterator/go" 50 | version = "1.1.3" 51 | 52 | [[constraint]] 53 | branch = "master" 54 | name = "github.com/kardianos/osext" 55 | 56 | [[constraint]] 57 | branch = "master" 58 | name = "github.com/olekukonko/tablewriter" 59 | 60 | [[constraint]] 61 | branch = "master" 62 | name = "github.com/peterh/liner" 63 | 64 | [[constraint]] 65 | name = "github.com/urfave/cli" 66 | version = "1.20.0" 67 | 68 | [prune] 69 | go-tests = true 70 | unused-packages = true 71 | -------------------------------------------------------------------------------- /requester/rio/multi.go: -------------------------------------------------------------------------------- 1 | package rio 2 | 3 | import ( 4 | "io" 5 | ) 6 | 7 | // MultiReaderLen 合并多个ReaderLen 8 | func MultiReaderLen(readerLens ...ReaderLen) ReaderLen { 9 | // TODO: 和copy对比 10 | r := make([]io.Reader, 0, len(readerLens)) 11 | for k := range readerLens { 12 | if readerLens[k] == nil { 13 | continue 14 | } 15 | r = append(r, readerLens[k]) 16 | } 17 | return &multiReaderLen{ 18 | mrls: readerLens, 19 | multiReader: io.MultiReader(r...), 20 | } 21 | } 22 | 23 | type multiReaderLen struct { 24 | mrls []ReaderLen 25 | multiReader io.Reader 26 | } 27 | 28 | func (mrl *multiReaderLen) Read(p []byte) (n int, err error) { 29 | return mrl.multiReader.Read(p) 30 | } 31 | 32 | func (mrl *multiReaderLen) Len() int { 33 | var i int 34 | for k := range mrl.mrls { 35 | i += mrl.mrls[k].Len() 36 | } 37 | return i 38 | } 39 | 40 | // MultiReaderLen64 合并多个ReaderLen64 41 | func MultiReaderLen64(readerLen64s ...ReaderLen64) ReaderLen64 { 42 | // TODO: 和copy对比 43 | r := make([]io.Reader, 0, len(readerLen64s)) 44 | for k := range readerLen64s { 45 | if readerLen64s[k] == nil { 46 | continue 47 | } 48 | r = append(r, readerLen64s[k]) 49 | } 50 | return &multiReaderLen64{ 51 | mrl64s: readerLen64s, 52 | multiReader: io.MultiReader(r...), 53 | } 54 | } 55 | 56 | type multiReaderLen64 struct { 57 | mrl64s []ReaderLen64 58 | multiReader io.Reader 59 | } 60 | 61 | func (mrl64 *multiReaderLen64) Read(p []byte) (n int, err error) { 62 | return mrl64.multiReader.Read(p) 63 | } 64 | 65 | func (mrl64 *multiReaderLen64) Len() int64 { 66 | var l int64 67 | for k := range mrl64.mrl64s { 68 | l += mrl64.mrl64s[k].Len() 69 | } 70 | return l 71 | } 72 | -------------------------------------------------------------------------------- /vendor/github.com/mattn/go-runewidth/runewidth_posix.go: -------------------------------------------------------------------------------- 1 | // +build !windows,!js 2 | 3 | package runewidth 4 | 5 | import ( 6 | "os" 7 | "regexp" 8 | "strings" 9 | ) 10 | 11 | var reLoc = regexp.MustCompile(`^[a-z][a-z][a-z]?(?:_[A-Z][A-Z])?\.(.+)`) 12 | 13 | var mblenTable = map[string]int{ 14 | "utf-8": 6, 15 | "utf8": 6, 16 | "jis": 8, 17 | "eucjp": 3, 18 | "euckr": 2, 19 | "euccn": 2, 20 | "sjis": 2, 21 | "cp932": 2, 22 | "cp51932": 2, 23 | "cp936": 2, 24 | "cp949": 2, 25 | "cp950": 2, 26 | "big5": 2, 27 | "gbk": 2, 28 | "gb2312": 2, 29 | } 30 | 31 | func isEastAsian(locale string) bool { 32 | charset := strings.ToLower(locale) 33 | r := reLoc.FindStringSubmatch(locale) 34 | if len(r) == 2 { 35 | charset = strings.ToLower(r[1]) 36 | } 37 | 38 | if strings.HasSuffix(charset, "@cjk_narrow") { 39 | return false 40 | } 41 | 42 | for pos, b := range []byte(charset) { 43 | if b == '@' { 44 | charset = charset[:pos] 45 | break 46 | } 47 | } 48 | max := 1 49 | if m, ok := mblenTable[charset]; ok { 50 | max = m 51 | } 52 | if max > 1 && (charset[0] != 'u' || 53 | strings.HasPrefix(locale, "ja") || 54 | strings.HasPrefix(locale, "ko") || 55 | strings.HasPrefix(locale, "zh")) { 56 | return true 57 | } 58 | return false 59 | } 60 | 61 | // IsEastAsian return true if the current locale is CJK 62 | func IsEastAsian() bool { 63 | locale := os.Getenv("LC_CTYPE") 64 | if locale == "" { 65 | locale = os.Getenv("LANG") 66 | } 67 | 68 | // ignore C locale 69 | if locale == "POSIX" || locale == "C" { 70 | return false 71 | } 72 | if len(locale) > 1 && locale[0] == 'C' && (locale[1] == '.' || locale[1] == '-') { 73 | return false 74 | } 75 | 76 | return isEastAsian(locale) 77 | } 78 | -------------------------------------------------------------------------------- /requester/uploader/status.go: -------------------------------------------------------------------------------- 1 | package uploader 2 | 3 | import ( 4 | "time" 5 | ) 6 | 7 | // Status 上传状态 8 | type Status interface { 9 | TotalSize() int64 // 总大小 10 | Uploaded() int64 // 已上传数据 11 | SpeedsPerSecond() int64 // 每秒的上传速度 12 | TimeElapsed() time.Duration // 上传时间 13 | } 14 | 15 | // UploadStatus 上传状态 16 | type UploadStatus struct { 17 | totalSize int64 // 总大小 18 | uploaded int64 // 已上传数据 19 | speedsPerSecond int64 // 每秒的上传速度 20 | timeElapsed time.Duration // 上传时间 21 | } 22 | 23 | // TotalSize 返回总大小 24 | func (us *UploadStatus) TotalSize() int64 { 25 | return us.totalSize 26 | } 27 | 28 | // Uploaded 返回已上传数据 29 | func (us *UploadStatus) Uploaded() int64 { 30 | return us.uploaded 31 | } 32 | 33 | // SpeedsPerSecond 返回每秒的上传速度 34 | func (us *UploadStatus) SpeedsPerSecond() int64 { 35 | return us.speedsPerSecond 36 | } 37 | 38 | // TimeElapsed 返回上传时间 39 | func (us *UploadStatus) TimeElapsed() time.Duration { 40 | return us.timeElapsed 41 | } 42 | 43 | // GetStatusChan 获取上传状态 44 | func (u *Uploader) GetStatusChan() <-chan Status { 45 | c := make(chan Status) 46 | 47 | go func() { 48 | for { 49 | select { 50 | case <-u.finished: 51 | close(c) 52 | return 53 | default: 54 | if !u.executed { 55 | time.Sleep(1 * time.Second) 56 | continue 57 | } 58 | 59 | old := u.readed64.Readed() 60 | time.Sleep(1 * time.Second) // 每秒统计 61 | 62 | readed := u.readed64.Readed() 63 | c <- &UploadStatus{ 64 | totalSize: u.readed64.Len(), 65 | uploaded: readed, 66 | speedsPerSecond: readed - old, 67 | timeElapsed: time.Since(u.executeTime) / 1000000 * 1000000, 68 | } 69 | } 70 | } 71 | }() 72 | return c 73 | } 74 | -------------------------------------------------------------------------------- /vendor/github.com/json-iterator/go/any_invalid.go: -------------------------------------------------------------------------------- 1 | package jsoniter 2 | 3 | import "fmt" 4 | 5 | type invalidAny struct { 6 | baseAny 7 | err error 8 | } 9 | 10 | func newInvalidAny(path []interface{}) *invalidAny { 11 | return &invalidAny{baseAny{}, fmt.Errorf("%v not found", path)} 12 | } 13 | 14 | func (any *invalidAny) LastError() error { 15 | return any.err 16 | } 17 | 18 | func (any *invalidAny) ValueType() ValueType { 19 | return InvalidValue 20 | } 21 | 22 | func (any *invalidAny) MustBeValid() Any { 23 | panic(any.err) 24 | } 25 | 26 | func (any *invalidAny) ToBool() bool { 27 | return false 28 | } 29 | 30 | func (any *invalidAny) ToInt() int { 31 | return 0 32 | } 33 | 34 | func (any *invalidAny) ToInt32() int32 { 35 | return 0 36 | } 37 | 38 | func (any *invalidAny) ToInt64() int64 { 39 | return 0 40 | } 41 | 42 | func (any *invalidAny) ToUint() uint { 43 | return 0 44 | } 45 | 46 | func (any *invalidAny) ToUint32() uint32 { 47 | return 0 48 | } 49 | 50 | func (any *invalidAny) ToUint64() uint64 { 51 | return 0 52 | } 53 | 54 | func (any *invalidAny) ToFloat32() float32 { 55 | return 0 56 | } 57 | 58 | func (any *invalidAny) ToFloat64() float64 { 59 | return 0 60 | } 61 | 62 | func (any *invalidAny) ToString() string { 63 | return "" 64 | } 65 | 66 | func (any *invalidAny) WriteTo(stream *Stream) { 67 | } 68 | 69 | func (any *invalidAny) Get(path ...interface{}) Any { 70 | if any.err == nil { 71 | return &invalidAny{baseAny{}, fmt.Errorf("get %v from invalid", path)} 72 | } 73 | return &invalidAny{baseAny{}, fmt.Errorf("%v, get %v from invalid", any.err, path)} 74 | } 75 | 76 | func (any *invalidAny) Parse() *Iterator { 77 | return nil 78 | } 79 | 80 | func (any *invalidAny) GetInterface() interface{} { 81 | return nil 82 | } 83 | -------------------------------------------------------------------------------- /pcsutil/pcsutil.go: -------------------------------------------------------------------------------- 1 | // Package pcsutil 工具包 2 | package pcsutil 3 | 4 | import ( 5 | "compress/gzip" 6 | "flag" 7 | "io" 8 | "io/ioutil" 9 | "net/http/cookiejar" 10 | "net/url" 11 | "os" 12 | "strings" 13 | ) 14 | 15 | var ( 16 | // PipeInput 命令中是否为管道输入 17 | PipeInput bool 18 | ) 19 | 20 | func init() { 21 | fileInfo, err := os.Stdin.Stat() 22 | if err != nil { 23 | return 24 | } 25 | PipeInput = (fileInfo.Mode() & os.ModeNamedPipe) == os.ModeNamedPipe 26 | } 27 | 28 | // ContainsString 检测字符串是否在字符串数组里 29 | func ContainsString(ss []string, s string) bool { 30 | for k := range ss { 31 | if strings.Compare(ss[k], s) == 0 { 32 | return true 33 | } 34 | } 35 | return false 36 | } 37 | 38 | // GetURLCookieString 返回cookie字串 39 | func GetURLCookieString(urlString string, jar *cookiejar.Jar) string { 40 | url, _ := url.Parse(urlString) 41 | cookies := jar.Cookies(url) 42 | cookieString := "" 43 | for _, v := range cookies { 44 | cookieString += v.String() + "; " 45 | } 46 | cookieString = strings.TrimRight(cookieString, "; ") 47 | return cookieString 48 | } 49 | 50 | // DecompressGZIP 对 io.Reader 数据, 进行 gzip 解压 51 | func DecompressGZIP(r io.Reader) ([]byte, error) { 52 | gzipReader, err := gzip.NewReader(r) 53 | if err != nil { 54 | return nil, err 55 | } 56 | gzipReader.Close() 57 | return ioutil.ReadAll(gzipReader) 58 | } 59 | 60 | // FlagProvided 检测命令行是否提供名为 name 的 flag, 支持多个name(names) 61 | func FlagProvided(names ...string) bool { 62 | if len(names) == 0 { 63 | return false 64 | } 65 | var targetFlag *flag.Flag 66 | for _, name := range names { 67 | targetFlag = flag.Lookup(name) 68 | if targetFlag == nil { 69 | return false 70 | } 71 | if targetFlag.DefValue == targetFlag.Value.String() { 72 | return false 73 | } 74 | } 75 | return true 76 | } 77 | -------------------------------------------------------------------------------- /vendor/github.com/json-iterator/go/reflect_dynamic.go: -------------------------------------------------------------------------------- 1 | package jsoniter 2 | 3 | import ( 4 | "github.com/modern-go/reflect2" 5 | "reflect" 6 | "unsafe" 7 | ) 8 | 9 | type dynamicEncoder struct { 10 | valType reflect2.Type 11 | } 12 | 13 | func (encoder *dynamicEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { 14 | obj := encoder.valType.UnsafeIndirect(ptr) 15 | stream.WriteVal(obj) 16 | } 17 | 18 | func (encoder *dynamicEncoder) IsEmpty(ptr unsafe.Pointer) bool { 19 | return encoder.valType.UnsafeIndirect(ptr) == nil 20 | } 21 | 22 | type efaceDecoder struct { 23 | } 24 | 25 | func (decoder *efaceDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { 26 | pObj := (*interface{})(ptr) 27 | obj := *pObj 28 | if obj == nil { 29 | *pObj = iter.Read() 30 | return 31 | } 32 | typ := reflect2.TypeOf(obj) 33 | if typ.Kind() != reflect.Ptr { 34 | *pObj = iter.Read() 35 | return 36 | } 37 | ptrType := typ.(*reflect2.UnsafePtrType) 38 | ptrElemType := ptrType.Elem() 39 | if iter.WhatIsNext() == NilValue { 40 | if ptrElemType.Kind() != reflect.Ptr { 41 | iter.skipFourBytes('n', 'u', 'l', 'l') 42 | *pObj = nil 43 | return 44 | } 45 | } 46 | if reflect2.IsNil(obj) { 47 | obj := ptrElemType.New() 48 | iter.ReadVal(obj) 49 | *pObj = obj 50 | return 51 | } 52 | iter.ReadVal(obj) 53 | } 54 | 55 | type ifaceDecoder struct { 56 | valType *reflect2.UnsafeIFaceType 57 | } 58 | 59 | func (decoder *ifaceDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { 60 | if iter.ReadNil() { 61 | decoder.valType.UnsafeSet(ptr, decoder.valType.UnsafeNew()) 62 | return 63 | } 64 | obj := decoder.valType.UnsafeIndirect(ptr) 65 | if reflect2.IsNil(obj) { 66 | iter.ReportError("decode non empty interface", "can not unmarshal into nil") 67 | return 68 | } 69 | iter.ReadVal(obj) 70 | } 71 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/reflect2/unsafe_struct.go: -------------------------------------------------------------------------------- 1 | package reflect2 2 | 3 | import ( 4 | "reflect" 5 | "unsafe" 6 | ) 7 | 8 | type UnsafeStructType struct { 9 | unsafeType 10 | likePtr bool 11 | } 12 | 13 | func newUnsafeStructType(cfg *frozenConfig, type1 reflect.Type) *UnsafeStructType { 14 | return &UnsafeStructType{ 15 | unsafeType: *newUnsafeType(cfg, type1), 16 | likePtr: likePtrType(type1), 17 | } 18 | } 19 | 20 | func (type2 *UnsafeStructType) LikePtr() bool { 21 | return type2.likePtr 22 | } 23 | 24 | func (type2 *UnsafeStructType) Indirect(obj interface{}) interface{} { 25 | objEFace := unpackEFace(obj) 26 | assertType("Type.Indirect argument 1", type2.ptrRType, objEFace.rtype) 27 | return type2.UnsafeIndirect(objEFace.data) 28 | } 29 | 30 | func (type2 *UnsafeStructType) UnsafeIndirect(ptr unsafe.Pointer) interface{} { 31 | if type2.likePtr { 32 | return packEFace(type2.rtype, *(*unsafe.Pointer)(ptr)) 33 | } 34 | return packEFace(type2.rtype, ptr) 35 | } 36 | 37 | func (type2 *UnsafeStructType) FieldByName(name string) StructField { 38 | structField, found := type2.Type.FieldByName(name) 39 | if !found { 40 | return nil 41 | } 42 | return newUnsafeStructField(type2, structField) 43 | } 44 | 45 | func (type2 *UnsafeStructType) Field(i int) StructField { 46 | return newUnsafeStructField(type2, type2.Type.Field(i)) 47 | } 48 | 49 | func (type2 *UnsafeStructType) FieldByIndex(index []int) StructField { 50 | return newUnsafeStructField(type2, type2.Type.FieldByIndex(index)) 51 | } 52 | 53 | func (type2 *UnsafeStructType) FieldByNameFunc(match func(string) bool) StructField { 54 | structField, found := type2.Type.FieldByNameFunc(match) 55 | if !found { 56 | panic("field match condition not found in " + type2.Type.String()) 57 | } 58 | return newUnsafeStructField(type2, structField) 59 | } -------------------------------------------------------------------------------- /internal/pcscommand/cloud_dl.go: -------------------------------------------------------------------------------- 1 | package pcscommand 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | // RunCloudDlAddTask 执行添加离线下载任务 8 | func RunCloudDlAddTask(sourceURLs []string, savePath string) { 9 | var err error 10 | savePath, err = getAbsPath(savePath) 11 | if err != nil { 12 | fmt.Printf("%s\n", err) 13 | return 14 | } 15 | 16 | var taskid int64 17 | for k := range sourceURLs { 18 | taskid, err = GetBaiduPCS().CloudDlAddTask(sourceURLs[k], savePath+"/") 19 | if err != nil { 20 | fmt.Printf("[%d] %s, 地址: %s\n", k+1, err, sourceURLs[k]) 21 | continue 22 | } 23 | 24 | fmt.Printf("[%d] 添加离线任务成功, 任务ID(task_id): %d, 源地址: %s, 保存路径: %s\n", k+1, taskid, sourceURLs[k], savePath) 25 | } 26 | } 27 | 28 | // RunCloudDlQueryTask 精确查询离线下载任务 29 | func RunCloudDlQueryTask(taskIDs []int64) { 30 | cl, err := GetBaiduPCS().CloudDlQueryTask(taskIDs) 31 | if err != nil { 32 | fmt.Printf("%s\n", err) 33 | return 34 | } 35 | 36 | fmt.Println(cl) 37 | } 38 | 39 | // RunCloudDlListTask 查询离线下载任务列表 40 | func RunCloudDlListTask() { 41 | cl, err := GetBaiduPCS().CloudDlListTask() 42 | if err != nil { 43 | fmt.Printf("%s\n", err) 44 | return 45 | } 46 | 47 | fmt.Println(cl) 48 | } 49 | 50 | // RunCloudDlCancelTask 取消离线下载任务 51 | func RunCloudDlCancelTask(taskIDs []int64) { 52 | for _, id := range taskIDs { 53 | err := GetBaiduPCS().CloudDlCancelTask(id) 54 | if err != nil { 55 | fmt.Printf("[%d] %s\n", id, err) 56 | continue 57 | } 58 | 59 | fmt.Printf("[%d] 取消成功\n", id) 60 | } 61 | } 62 | 63 | // RunCloudDlDeleteTask 删除离线下载任务 64 | func RunCloudDlDeleteTask(taskIDs []int64) { 65 | for _, id := range taskIDs { 66 | err := GetBaiduPCS().CloudDlDeleteTask(id) 67 | if err != nil { 68 | fmt.Printf("[%d] %s\n", id, err) 69 | continue 70 | } 71 | 72 | fmt.Printf("[%d] 删除成功\n", id) 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /requester/downloader/cachepool/cachepool.go: -------------------------------------------------------------------------------- 1 | package cachepool 2 | 3 | import ( 4 | "sync" 5 | ) 6 | 7 | var ( 8 | //CachePool []byte 缓存池 2 9 | CachePool = cachePool2{} 10 | ) 11 | 12 | //Cache cache 13 | type Cache interface { 14 | Bytes() []byte 15 | Free() 16 | } 17 | 18 | type cache struct { 19 | isUsed bool 20 | b []byte 21 | } 22 | 23 | func (c *cache) Bytes() []byte { 24 | if !c.isUsed { 25 | return nil 26 | } 27 | return c.b 28 | } 29 | 30 | func (c *cache) Free() { 31 | c.isUsed = false 32 | } 33 | 34 | type cachePool2 struct { 35 | pool []*cache 36 | mu sync.Mutex 37 | } 38 | 39 | func (cp2 *cachePool2) Require(size int) Cache { 40 | cp2.mu.Lock() 41 | defer cp2.mu.Unlock() 42 | for k := range cp2.pool { 43 | if cp2.pool[k] == nil || cp2.pool[k].isUsed || len(cp2.pool[k].b) < size { 44 | continue 45 | } 46 | 47 | cp2.pool[k].isUsed = true 48 | return cp2.pool[k] 49 | } 50 | newCache := &cache{ 51 | isUsed: true, 52 | b: make([]byte, size), 53 | } 54 | cp2.addCache(newCache) 55 | return newCache 56 | } 57 | 58 | func (cp2 *cachePool2) addCache(newCache *cache) { 59 | for k := range cp2.pool { 60 | if cp2.pool[k] == nil { 61 | cp2.pool[k] = newCache 62 | return 63 | } 64 | } 65 | cp2.pool = append(cp2.pool, newCache) 66 | } 67 | 68 | func (cp2 *cachePool2) DeleteNotUsed() { 69 | cp2.mu.Lock() 70 | defer cp2.mu.Unlock() 71 | for k := range cp2.pool { 72 | if cp2.pool[k] == nil { 73 | continue 74 | } 75 | 76 | if !cp2.pool[k].isUsed { 77 | cp2.pool[k] = nil 78 | } 79 | } 80 | } 81 | 82 | func (cp2 *cachePool2) DeleteAll() { 83 | cp2.mu.Lock() 84 | defer cp2.mu.Unlock() 85 | for k := range cp2.pool { 86 | cp2.pool[k] = nil 87 | } 88 | } 89 | 90 | //Require 申请Cache 91 | func Require(size int) Cache { 92 | return CachePool.Require(size) 93 | } 94 | -------------------------------------------------------------------------------- /vendor/github.com/iikira/Baidu-Login/bdcrypto/archive.go: -------------------------------------------------------------------------------- 1 | package bdcrypto 2 | 3 | import ( 4 | "compress/gzip" 5 | "io" 6 | "os" 7 | ) 8 | 9 | // GZIPCompress GZIP 压缩 10 | func GZIPCompress(src io.Reader, writeTo io.Writer) (err error) { 11 | w := gzip.NewWriter(writeTo) 12 | _, err = io.Copy(w, src) 13 | if err != nil { 14 | return 15 | } 16 | 17 | w.Flush() 18 | return w.Close() 19 | } 20 | 21 | // GZIPUncompress GZIP 解压缩 22 | func GZIPUncompress(src io.Reader, writeTo io.Writer) (err error) { 23 | unReader, err := gzip.NewReader(src) 24 | if err != nil { 25 | return err 26 | } 27 | 28 | _, err = io.Copy(writeTo, unReader) 29 | if err != nil { 30 | return 31 | } 32 | 33 | return unReader.Close() 34 | } 35 | 36 | // GZIPCompressFile GZIP 压缩文件 37 | func GZIPCompressFile(filePath string) (err error) { 38 | return gzipCompressFile("en", filePath) 39 | } 40 | 41 | // GZIPUnompressFile GZIP 解压缩文件 42 | func GZIPUnompressFile(filePath string) (err error) { 43 | return gzipCompressFile("de", filePath) 44 | } 45 | 46 | func gzipCompressFile(op, filePath string) (err error) { 47 | f, err := os.Open(filePath) 48 | if err != nil { 49 | return 50 | } 51 | 52 | defer f.Close() 53 | 54 | fInfo, err := f.Stat() 55 | if err != nil { 56 | return 57 | } 58 | 59 | tempFilePath := filePath + ".gzip.tmp" 60 | // 保留文件权限 61 | tempFile, err := os.OpenFile(tempFilePath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, fInfo.Mode()) 62 | if err != nil { 63 | return 64 | } 65 | 66 | defer tempFile.Close() 67 | 68 | switch op { 69 | case "en": 70 | err = GZIPCompress(f, tempFile) 71 | case "de": 72 | err = GZIPUncompress(f, tempFile) 73 | default: 74 | panic("unknown op" + op) 75 | } 76 | 77 | if err != nil { 78 | os.Remove(tempFilePath) 79 | return 80 | } 81 | 82 | return os.Rename(tempFilePath, filePath) 83 | } 84 | -------------------------------------------------------------------------------- /vendor/github.com/iikira/Baidu-Login/README.md: -------------------------------------------------------------------------------- 1 | # 百度BDUSS获取工具 v1.2.1 Go语言 2 | [![GoDoc](https://godoc.org/github.com/iikira/Baidu-Login?status.svg)](https://godoc.org/github.com/iikira/Baidu-Login) 3 | 4 | ## 功能 5 | 6 | 增加 session 支持,数据安全性提高 7 | 8 | 百度: 获取百度帐号 BDUSS, PTOKEN, STOKEN 值 9 | 10 | 百度: 支持在线 手机/邮箱 安全验证(beta) 11 | 12 | ## 如何使用 13 | 14 | Go语言程序, 可直接下载使用 [点此查看发布页](https://github.com/iikira/Baidu-Login/releases) 15 | 16 | 在 (Linux, MacOS)终端/(Windows)命令提示符 中运行。 17 | 18 | Windows 也可双击程序运行。 19 | 20 | 本程序会开启本地 http 服务器, 默认端口为9090. 21 | 22 | 程序运行前带入参数 "-h" 以查看帮助. 23 | 24 | 程序会列出一些本地服务器网址, 浏览器访问网址即可使用。 25 | 26 | 请注意,程序重启后请刷新一遍网页,因为程序重启会导致 session 清空,否则可能会出现错误。 27 | 28 | ## 如何手动编译安装 29 | 30 | ### 1. 安装Go语言运行环境 31 | 32 | * 访问 [Go语言官网](https://golang.org) 下载安装Golang 33 | * 设置GOPATH环境变量 34 | 35 | Linux: 36 | ```shell 37 | export GOPATH=/path/to/your/gopath 38 | ``` 39 | Windows: 40 | ```shell 41 | set GOPATH=C:\path\to\your\gopath 42 | ``` 43 | 44 | 如果提示找不到 go 命令, 请先设置 PATH , 以Linux为例 45 | ```shell 46 | export PATH=$PATH:$GOROOT/bin 47 | ``` 48 | $GOROOT 即Go语言的安装目录 49 | 50 | ### 2. 安装 51 | 52 | #### 编译安装(需要设置GOPATH环境变量) 53 | ```shell 54 | go get -u -v github.com/iikira/Baidu-Login/cmd/Baidu-Login 55 | ``` 56 | 编译生成的文件在GOPATH的bin目录下 57 | 58 | ## 如何将静态资源打包进程序 59 | 60 | 强烈建议使用 go.rice 将 http-files 目录内的文件打包进程序 61 | 62 | 详情: [https://github.com/GeertJohan/go.rice](https://github.com/GeertJohan/go.rice) 63 | 64 | 设置好环境变量 GOPATH: 65 | ```shell 66 | export GOPATH=/path/to/your/gopath 67 | ``` 68 | 69 | 将 $GOPATH/bin 加入 PATH 环境变量 70 | ```shell 71 | export PATH=$PATH:$GOPATH/bin 72 | ``` 73 | 74 | 安装 go.rice 相关依赖: 75 | ```shell 76 | go get -u -v github.com/GeertJohan/go.rice 77 | go get -u -v github.com/GeertJohan/go.rice/rice 78 | ``` 79 | 80 | 将 $GOPATH/bin / %GOPATH%\bin 加入PATH环境变量, 最后执行以下命令编译程序: 81 | ```shell 82 | rice embed-go 83 | go build 84 | ``` 85 | -------------------------------------------------------------------------------- /vendor/github.com/peterh/liner/output.go: -------------------------------------------------------------------------------- 1 | // +build linux darwin openbsd freebsd netbsd 2 | 3 | package liner 4 | 5 | import ( 6 | "fmt" 7 | "os" 8 | "strings" 9 | "syscall" 10 | "unsafe" 11 | ) 12 | 13 | func (s *State) cursorPos(x int) { 14 | if s.useCHA { 15 | // 'G' is "Cursor Character Absolute (CHA)" 16 | fmt.Printf("\x1b[%dG", x+1) 17 | } else { 18 | // 'C' is "Cursor Forward (CUF)" 19 | fmt.Print("\r") 20 | if x > 0 { 21 | fmt.Printf("\x1b[%dC", x) 22 | } 23 | } 24 | } 25 | 26 | func (s *State) eraseLine() { 27 | fmt.Print("\x1b[0K") 28 | } 29 | 30 | func (s *State) eraseScreen() { 31 | fmt.Print("\x1b[H\x1b[2J") 32 | } 33 | 34 | func (s *State) moveUp(lines int) { 35 | fmt.Printf("\x1b[%dA", lines) 36 | } 37 | 38 | func (s *State) moveDown(lines int) { 39 | fmt.Printf("\x1b[%dB", lines) 40 | } 41 | 42 | func (s *State) emitNewLine() { 43 | fmt.Print("\n") 44 | } 45 | 46 | type winSize struct { 47 | row, col uint16 48 | xpixel, ypixel uint16 49 | } 50 | 51 | func (s *State) getColumns() bool { 52 | var ws winSize 53 | ok, _, _ := syscall.Syscall(syscall.SYS_IOCTL, uintptr(syscall.Stdout), 54 | syscall.TIOCGWINSZ, uintptr(unsafe.Pointer(&ws))) 55 | if int(ok) < 0 { 56 | return false 57 | } 58 | s.columns = int(ws.col) 59 | return true 60 | } 61 | 62 | func (s *State) checkOutput() { 63 | // xterm is known to support CHA 64 | if strings.Contains(strings.ToLower(os.Getenv("TERM")), "xterm") { 65 | s.useCHA = true 66 | return 67 | } 68 | 69 | // The test for functional ANSI CHA is unreliable (eg the Windows 70 | // telnet command does not support reading the cursor position with 71 | // an ANSI DSR request, despite setting TERM=ansi) 72 | 73 | // Assume CHA isn't supported (which should be safe, although it 74 | // does result in occasional visible cursor jitter) 75 | s.useCHA = false 76 | } 77 | -------------------------------------------------------------------------------- /vendor/github.com/json-iterator/go/reflect_json_raw_message.go: -------------------------------------------------------------------------------- 1 | package jsoniter 2 | 3 | import ( 4 | "encoding/json" 5 | "github.com/modern-go/reflect2" 6 | "unsafe" 7 | ) 8 | 9 | var jsonRawMessageType = reflect2.TypeOfPtr((*json.RawMessage)(nil)).Elem() 10 | var jsoniterRawMessageType = reflect2.TypeOfPtr((*RawMessage)(nil)).Elem() 11 | 12 | func createEncoderOfJsonRawMessage(ctx *ctx, typ reflect2.Type) ValEncoder { 13 | if typ == jsonRawMessageType { 14 | return &jsonRawMessageCodec{} 15 | } 16 | if typ == jsoniterRawMessageType { 17 | return &jsoniterRawMessageCodec{} 18 | } 19 | return nil 20 | } 21 | 22 | func createDecoderOfJsonRawMessage(ctx *ctx, typ reflect2.Type) ValDecoder { 23 | if typ == jsonRawMessageType { 24 | return &jsonRawMessageCodec{} 25 | } 26 | if typ == jsoniterRawMessageType { 27 | return &jsoniterRawMessageCodec{} 28 | } 29 | return nil 30 | } 31 | 32 | type jsonRawMessageCodec struct { 33 | } 34 | 35 | func (codec *jsonRawMessageCodec) Decode(ptr unsafe.Pointer, iter *Iterator) { 36 | *((*json.RawMessage)(ptr)) = json.RawMessage(iter.SkipAndReturnBytes()) 37 | } 38 | 39 | func (codec *jsonRawMessageCodec) Encode(ptr unsafe.Pointer, stream *Stream) { 40 | stream.WriteRaw(string(*((*json.RawMessage)(ptr)))) 41 | } 42 | 43 | func (codec *jsonRawMessageCodec) IsEmpty(ptr unsafe.Pointer) bool { 44 | return len(*((*json.RawMessage)(ptr))) == 0 45 | } 46 | 47 | type jsoniterRawMessageCodec struct { 48 | } 49 | 50 | func (codec *jsoniterRawMessageCodec) Decode(ptr unsafe.Pointer, iter *Iterator) { 51 | *((*RawMessage)(ptr)) = RawMessage(iter.SkipAndReturnBytes()) 52 | } 53 | 54 | func (codec *jsoniterRawMessageCodec) Encode(ptr unsafe.Pointer, stream *Stream) { 55 | stream.WriteRaw(string(*((*RawMessage)(ptr)))) 56 | } 57 | 58 | func (codec *jsoniterRawMessageCodec) IsEmpty(ptr unsafe.Pointer) bool { 59 | return len(*((*RawMessage)(ptr))) == 0 60 | } 61 | -------------------------------------------------------------------------------- /requester/downloader/loadbalance.go: -------------------------------------------------------------------------------- 1 | package downloader 2 | 3 | import ( 4 | "net/http" 5 | "sync/atomic" 6 | ) 7 | 8 | // LoadBalancerResponse 负载均衡响应状态 9 | type LoadBalancerResponse struct { 10 | URL string 11 | Referer string 12 | } 13 | 14 | // LoadBalancerResponseList 负载均衡列表 15 | type LoadBalancerResponseList struct { 16 | lbr []*LoadBalancerResponse 17 | cursor int32 18 | } 19 | 20 | // NewLoadBalancerResponseList 初始化负载均衡列表 21 | func NewLoadBalancerResponseList(lbr []*LoadBalancerResponse) *LoadBalancerResponseList { 22 | return &LoadBalancerResponseList{ 23 | lbr: lbr, 24 | } 25 | } 26 | 27 | // SequentialGet 顺序获取 28 | func (lbrl *LoadBalancerResponseList) SequentialGet() *LoadBalancerResponse { 29 | if len(lbrl.lbr) == 0 { 30 | return nil 31 | } 32 | 33 | if int(lbrl.cursor) >= len(lbrl.lbr) { 34 | lbrl.cursor = 0 35 | } 36 | 37 | lbr := lbrl.lbr[int(lbrl.cursor)] 38 | atomic.AddInt32(&lbrl.cursor, 1) 39 | return lbr 40 | } 41 | 42 | // RandomGet 随机获取 43 | func (lbrl *LoadBalancerResponseList) RandomGet() *LoadBalancerResponse { 44 | return lbrl.lbr[RandomNumber(0, len(lbrl.lbr))] 45 | } 46 | 47 | // AddLoadBalanceServer 增加负载均衡服务器 48 | func (der *Downloader) AddLoadBalanceServer(urls ...string) { 49 | der.loadBalansers = append(der.loadBalansers, urls...) 50 | } 51 | 52 | // ServerEqual 检测负载均衡的服务器是否一致 53 | func ServerEqual(resp, subResp *http.Response) bool { 54 | if resp == nil || subResp == nil { 55 | return false 56 | } 57 | 58 | if resp.ContentLength != subResp.ContentLength { 59 | return false 60 | } 61 | 62 | header, subHeader := resp.Header, subResp.Header 63 | if header.Get("Content-MD5") != subHeader.Get("Content-MD5") { 64 | return false 65 | } 66 | if header.Get("Content-Type") != subHeader.Get("Content-Type") { 67 | return false 68 | } 69 | if header.Get("x-bs-meta-crc32") != subHeader.Get("x-bs-meta-crc32") { 70 | return false 71 | } 72 | return true 73 | } 74 | -------------------------------------------------------------------------------- /internal/pcscommand/bg_fg.go: -------------------------------------------------------------------------------- 1 | package pcscommand 2 | 3 | import ( 4 | "fmt" 5 | "github.com/iikira/BaiduPCS-Go/pcstable" 6 | "os" 7 | "strconv" 8 | "strings" 9 | "sync" 10 | "sync/atomic" 11 | ) 12 | 13 | var ( 14 | // BgMap 后台 15 | BgMap = BgTasks{ 16 | tasks: sync.Map{}, 17 | sig: make(chan int64), 18 | } 19 | ) 20 | 21 | type ( 22 | // BgTasks 后台任务 23 | BgTasks struct { 24 | lastID int64 25 | tasks sync.Map 26 | started bool 27 | sig chan int64 28 | } 29 | // BgDTaskItem 后台任务详情 30 | BgDTaskItem struct { 31 | id int 32 | downloadOptions *DownloadOptions 33 | pcspaths []string 34 | } 35 | ) 36 | 37 | // NewID 返回生成的 ID 38 | func (b *BgTasks) NewID() int64 { 39 | id := atomic.AddInt64(&b.lastID, 1) 40 | return id 41 | } 42 | 43 | // TaskID 返回后台任务 id 44 | func (t *BgDTaskItem) TaskID() int { 45 | return t.id 46 | } 47 | 48 | // PrintAllBgTask 输出所有的后台任务 49 | func (b *BgTasks) PrintAllBgTask() { 50 | tb := pcstable.NewTable(os.Stdout) 51 | tb.SetHeader([]string{"task_id", "files"}) 52 | b.tasks.Range(func(id, v interface{}) bool { 53 | tb.Append([]string{strconv.FormatInt(id.(int64), 10), strings.Join(v.(*BgDTaskItem).pcspaths, ",")}) 54 | return true 55 | }) 56 | tb.Render() 57 | } 58 | 59 | // RunBgDownload 执行后台下载 60 | func RunBgDownload(paths []string, options *DownloadOptions) { 61 | if !BgMap.started { 62 | go func() { 63 | for { 64 | select { 65 | case id := <-BgMap.sig: 66 | BgMap.tasks.Delete(id) 67 | fmt.Printf("任务:%d 已完成\n", id) 68 | } 69 | } 70 | }() 71 | } else { 72 | BgMap.started = true 73 | } 74 | 75 | if options.Out == nil { 76 | options.Out, _ = os.Open(os.DevNull) 77 | } 78 | 79 | task := new(BgDTaskItem) 80 | task.pcspaths = paths 81 | 82 | id := BgMap.NewID() 83 | BgMap.tasks.Store(id, task) 84 | 85 | go func(taskID int64) { 86 | RunDownload(paths, options) 87 | BgMap.sig <- taskID 88 | }(id) 89 | } 90 | -------------------------------------------------------------------------------- /vendor/github.com/peterh/liner/width.go: -------------------------------------------------------------------------------- 1 | package liner 2 | 3 | import ( 4 | "unicode" 5 | 6 | "github.com/mattn/go-runewidth" 7 | ) 8 | 9 | // These character classes are mostly zero width (when combined). 10 | // A few might not be, depending on the user's font. Fixing this 11 | // is non-trivial, given that some terminals don't support 12 | // ANSI DSR/CPR 13 | var zeroWidth = []*unicode.RangeTable{ 14 | unicode.Mn, 15 | unicode.Me, 16 | unicode.Cc, 17 | unicode.Cf, 18 | } 19 | 20 | // countGlyphs considers zero-width characters to be zero glyphs wide, 21 | // and members of Chinese, Japanese, and Korean scripts to be 2 glyphs wide. 22 | func countGlyphs(s []rune) int { 23 | n := 0 24 | for _, r := range s { 25 | // speed up the common case 26 | if r < 127 { 27 | n++ 28 | continue 29 | } 30 | 31 | n += runewidth.RuneWidth(r) 32 | } 33 | return n 34 | } 35 | 36 | func countMultiLineGlyphs(s []rune, columns int, start int) int { 37 | n := start 38 | for _, r := range s { 39 | if r < 127 { 40 | n++ 41 | continue 42 | } 43 | switch runewidth.RuneWidth(r) { 44 | case 0: 45 | case 1: 46 | n++ 47 | case 2: 48 | n += 2 49 | // no room for a 2-glyphs-wide char in the ending 50 | // so skip a column and display it at the beginning 51 | if n%columns == 1 { 52 | n++ 53 | } 54 | } 55 | } 56 | return n 57 | } 58 | 59 | func getPrefixGlyphs(s []rune, num int) []rune { 60 | p := 0 61 | for n := 0; n < num && p < len(s); p++ { 62 | // speed up the common case 63 | if s[p] < 127 { 64 | n++ 65 | continue 66 | } 67 | if !unicode.IsOneOf(zeroWidth, s[p]) { 68 | n++ 69 | } 70 | } 71 | for p < len(s) && unicode.IsOneOf(zeroWidth, s[p]) { 72 | p++ 73 | } 74 | return s[:p] 75 | } 76 | 77 | func getSuffixGlyphs(s []rune, num int) []rune { 78 | p := len(s) 79 | for n := 0; n < num && p > 0; p-- { 80 | // speed up the common case 81 | if s[p-1] < 127 { 82 | n++ 83 | continue 84 | } 85 | if !unicode.IsOneOf(zeroWidth, s[p-1]) { 86 | n++ 87 | } 88 | } 89 | return s[p:] 90 | } 91 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/concurrent/README.md: -------------------------------------------------------------------------------- 1 | # concurrent 2 | 3 | [![Sourcegraph](https://sourcegraph.com/github.com/modern-go/concurrent/-/badge.svg)](https://sourcegraph.com/github.com/modern-go/concurrent?badge) 4 | [![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](http://godoc.org/github.com/modern-go/concurrent) 5 | [![Build Status](https://travis-ci.org/modern-go/concurrent.svg?branch=master)](https://travis-ci.org/modern-go/concurrent) 6 | [![codecov](https://codecov.io/gh/modern-go/concurrent/branch/master/graph/badge.svg)](https://codecov.io/gh/modern-go/concurrent) 7 | [![rcard](https://goreportcard.com/badge/github.com/modern-go/concurrent)](https://goreportcard.com/report/github.com/modern-go/concurrent) 8 | [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://raw.githubusercontent.com/modern-go/concurrent/master/LICENSE) 9 | 10 | * concurrent.Map: backport sync.Map for go below 1.9 11 | * concurrent.Executor: goroutine with explicit ownership and cancellable 12 | 13 | # concurrent.Map 14 | 15 | because sync.Map is only available in go 1.9, we can use concurrent.Map to make code portable 16 | 17 | ```go 18 | m := concurrent.NewMap() 19 | m.Store("hello", "world") 20 | elem, found := m.Load("hello") 21 | // elem will be "world" 22 | // found will be true 23 | ``` 24 | 25 | # concurrent.Executor 26 | 27 | ```go 28 | executor := concurrent.NewUnboundedExecutor() 29 | executor.Go(func(ctx context.Context) { 30 | everyMillisecond := time.NewTicker(time.Millisecond) 31 | for { 32 | select { 33 | case <-ctx.Done(): 34 | fmt.Println("goroutine exited") 35 | return 36 | case <-everyMillisecond.C: 37 | // do something 38 | } 39 | } 40 | }) 41 | time.Sleep(time.Second) 42 | executor.StopAndWaitForever() 43 | fmt.Println("executor stopped") 44 | ``` 45 | 46 | attach goroutine to executor instance, so that we can 47 | 48 | * cancel it by stop the executor with Stop/StopAndWait/StopAndWaitForever 49 | * handle panic by callback: the default behavior will no longer crash your application -------------------------------------------------------------------------------- /vendor/github.com/iikira/Baidu-Login/bdcrypto/ecb/ecb.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Electronic Code Book (ECB) mode. 6 | 7 | // ECB provides confidentiality by assigning a fixed ciphertext block to each 8 | // plaintext block. 9 | 10 | // See NIST SP 800-38A, pp 08-09 11 | 12 | package ecb 13 | 14 | import ( 15 | "crypto/cipher" 16 | ) 17 | 18 | type ecb struct { 19 | b cipher.Block 20 | blockSize int 21 | } 22 | 23 | func newECB(b cipher.Block) *ecb { 24 | return &ecb{ 25 | b: b, 26 | blockSize: b.BlockSize(), 27 | } 28 | } 29 | 30 | type ecbEncrypter ecb 31 | 32 | // NewECBEncrypter returns a BlockMode which encrypts in electronic code book 33 | // mode, using the given Block. 34 | func NewECBEncrypter(b cipher.Block) cipher.BlockMode { 35 | return (*ecbEncrypter)(newECB(b)) 36 | } 37 | 38 | func (x *ecbEncrypter) BlockSize() int { return x.blockSize } 39 | 40 | func (x *ecbEncrypter) CryptBlocks(dst, src []byte) { 41 | if len(src)%x.blockSize != 0 { 42 | panic("crypto/cipher: input not full blocks") 43 | } 44 | if len(dst) < len(src) { 45 | panic("crypto/cipher: output smaller than input") 46 | } 47 | for len(src) > 0 { 48 | x.b.Encrypt(dst, src[:x.blockSize]) 49 | src = src[x.blockSize:] 50 | dst = dst[x.blockSize:] 51 | } 52 | } 53 | 54 | type ecbDecrypter ecb 55 | 56 | // NewECBDecrypter returns a BlockMode which decrypts in electronic code book 57 | // mode, using the given Block. 58 | func NewECBDecrypter(b cipher.Block) cipher.BlockMode { 59 | return (*ecbDecrypter)(newECB(b)) 60 | } 61 | 62 | func (x *ecbDecrypter) BlockSize() int { return x.blockSize } 63 | 64 | func (x *ecbDecrypter) CryptBlocks(dst, src []byte) { 65 | if len(src)%x.blockSize != 0 { 66 | panic("crypto/cipher: input not full blocks") 67 | } 68 | if len(dst) < len(src) { 69 | panic("crypto/cipher: output smaller than input") 70 | } 71 | for len(src) > 0 { 72 | x.b.Decrypt(dst, src[:x.blockSize]) 73 | src = src[x.blockSize:] 74 | dst = dst[x.blockSize:] 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/reflect2/safe_type.go: -------------------------------------------------------------------------------- 1 | package reflect2 2 | 3 | import ( 4 | "reflect" 5 | "unsafe" 6 | ) 7 | 8 | type safeType struct { 9 | reflect.Type 10 | cfg *frozenConfig 11 | } 12 | 13 | func (type2 *safeType) New() interface{} { 14 | return reflect.New(type2.Type).Interface() 15 | } 16 | 17 | func (type2 *safeType) UnsafeNew() unsafe.Pointer { 18 | panic("does not support unsafe operation") 19 | } 20 | 21 | func (type2 *safeType) Elem() Type { 22 | return type2.cfg.Type2(type2.Type.Elem()) 23 | } 24 | 25 | func (type2 *safeType) Type1() reflect.Type { 26 | return type2.Type 27 | } 28 | 29 | func (type2 *safeType) PackEFace(ptr unsafe.Pointer) interface{} { 30 | panic("does not support unsafe operation") 31 | } 32 | 33 | func (type2 *safeType) Implements(thatType Type) bool { 34 | return type2.Type.Implements(thatType.Type1()) 35 | } 36 | 37 | func (type2 *safeType) RType() uintptr { 38 | panic("does not support unsafe operation") 39 | } 40 | 41 | func (type2 *safeType) Indirect(obj interface{}) interface{} { 42 | return reflect.Indirect(reflect.ValueOf(obj)).Interface() 43 | } 44 | 45 | func (type2 *safeType) UnsafeIndirect(ptr unsafe.Pointer) interface{} { 46 | panic("does not support unsafe operation") 47 | } 48 | 49 | func (type2 *safeType) LikePtr() bool { 50 | panic("does not support unsafe operation") 51 | } 52 | 53 | func (type2 *safeType) IsNullable() bool { 54 | return IsNullable(type2.Kind()) 55 | } 56 | 57 | func (type2 *safeType) IsNil(obj interface{}) bool { 58 | if obj == nil { 59 | return true 60 | } 61 | return reflect.ValueOf(obj).Elem().IsNil() 62 | } 63 | 64 | func (type2 *safeType) UnsafeIsNil(ptr unsafe.Pointer) bool { 65 | panic("does not support unsafe operation") 66 | } 67 | 68 | func (type2 *safeType) Set(obj interface{}, val interface{}) { 69 | reflect.ValueOf(obj).Elem().Set(reflect.ValueOf(val).Elem()) 70 | } 71 | 72 | func (type2 *safeType) UnsafeSet(ptr unsafe.Pointer, val unsafe.Pointer) { 73 | panic("does not support unsafe operation") 74 | } 75 | 76 | func (type2 *safeType) AssignableTo(anotherType Type) bool { 77 | return type2.Type1().AssignableTo(anotherType.Type1()) 78 | } -------------------------------------------------------------------------------- /vendor/github.com/modern-go/reflect2/type_map.go: -------------------------------------------------------------------------------- 1 | package reflect2 2 | 3 | import ( 4 | "unsafe" 5 | "reflect" 6 | "runtime" 7 | "strings" 8 | ) 9 | 10 | // typelinks1 for 1.5 ~ 1.6 11 | //go:linkname typelinks1 reflect.typelinks 12 | func typelinks1() [][]unsafe.Pointer 13 | 14 | // typelinks2 for 1.7 ~ 15 | //go:linkname typelinks2 reflect.typelinks 16 | func typelinks2() (sections []unsafe.Pointer, offset [][]int32) 17 | 18 | var types = map[string]reflect.Type{} 19 | 20 | func init() { 21 | ver := runtime.Version() 22 | if ver == "go1.5" || strings.HasPrefix(ver, "go1.5.") { 23 | loadGo15Types() 24 | } else if ver == "go1.6" || strings.HasPrefix(ver, "go1.6.") { 25 | loadGo15Types() 26 | } else { 27 | loadGo17Types() 28 | } 29 | } 30 | 31 | func loadGo15Types() { 32 | var obj interface{} = reflect.TypeOf(0) 33 | typePtrss := typelinks1() 34 | for _, typePtrs := range typePtrss { 35 | for _, typePtr := range typePtrs { 36 | (*emptyInterface)(unsafe.Pointer(&obj)).word = typePtr 37 | typ := obj.(reflect.Type) 38 | if typ.Kind() == reflect.Ptr && typ.Elem().Kind() == reflect.Struct { 39 | types[typ.Elem().String()] = typ.Elem() 40 | } 41 | if typ.Kind() == reflect.Slice && typ.Elem().Kind() == reflect.Ptr && 42 | typ.Elem().Elem().Kind() == reflect.Struct { 43 | types[typ.Elem().Elem().String()] = typ.Elem().Elem() 44 | } 45 | } 46 | } 47 | } 48 | 49 | func loadGo17Types() { 50 | var obj interface{} = reflect.TypeOf(0) 51 | sections, offset := typelinks2() 52 | for i, offs := range offset { 53 | rodata := sections[i] 54 | for _, off := range offs { 55 | (*emptyInterface)(unsafe.Pointer(&obj)).word = resolveTypeOff(unsafe.Pointer(rodata), off) 56 | typ := obj.(reflect.Type) 57 | if typ.Kind() == reflect.Ptr && typ.Elem().Kind() == reflect.Struct { 58 | types[typ.Elem().String()] = typ.Elem() 59 | } 60 | } 61 | } 62 | } 63 | 64 | type emptyInterface struct { 65 | typ unsafe.Pointer 66 | word unsafe.Pointer 67 | } 68 | 69 | // TypeByName return the type by its name, just like Class.forName in java 70 | func TypeByName(typeName string) Type { 71 | return Type2(types[typeName]) 72 | } 73 | -------------------------------------------------------------------------------- /requester/dial.go: -------------------------------------------------------------------------------- 1 | package requester 2 | 3 | import ( 4 | "context" 5 | "crypto/tls" 6 | "net" 7 | "strconv" 8 | "time" 9 | ) 10 | 11 | var ( 12 | dialer = &net.Dialer{ 13 | Timeout: 30 * time.Second, 14 | KeepAlive: 30 * time.Second, 15 | DualStack: true, 16 | } 17 | ) 18 | 19 | func getServerName(address string) string { 20 | host, _, err := net.SplitHostPort(address) 21 | if err != nil { 22 | return address 23 | } 24 | return host 25 | } 26 | 27 | func resolveTCP(ctx context.Context, address string) (tcpaddr *net.TCPAddr, err error) { 28 | host, port, err := net.SplitHostPort(address) 29 | if err != nil { 30 | return 31 | } 32 | 33 | addrs, err := net.DefaultResolver.LookupIPAddr(ctx, host) 34 | if err != nil { 35 | return 36 | } 37 | 38 | p, err := strconv.Atoi(port) 39 | if err != nil { 40 | return 41 | } 42 | 43 | return &net.TCPAddr{ 44 | IP: addrs[0].IP, 45 | Port: p, 46 | Zone: addrs[0].Zone, 47 | }, nil 48 | } 49 | 50 | func dialContext(ctx context.Context, network, address string) (conn net.Conn, err error) { 51 | switch network { 52 | case "tcp", "tcp4", "tcp6": 53 | // 检测缓存 54 | if TCPAddrCache.Existed(address) { 55 | return net.DialTCP(network, nil, TCPAddrCache.Get(address)) 56 | } 57 | 58 | var ( 59 | ta *net.TCPAddr 60 | ) 61 | 62 | // Resolve TCP address 63 | ta, err = resolveTCP(ctx, address) 64 | 65 | if err != nil { 66 | return nil, err 67 | } 68 | 69 | // 加入缓存 70 | TCPAddrCache.Set(address, ta) 71 | return net.DialTCP(network, nil, ta) 72 | } 73 | 74 | // 非 tcp 请求 75 | conn, err = dialer.DialContext(ctx, network, address) 76 | return 77 | } 78 | 79 | func dial(network, address string) (conn net.Conn, err error) { 80 | return dialContext(context.Background(), network, address) 81 | } 82 | 83 | func (h *HTTPClient) dialTLSFunc() func(network, address string) (tlsConn net.Conn, err error) { 84 | return func(network, address string) (tlsConn net.Conn, err error) { 85 | conn, err := dialContext(context.Background(), network, address) 86 | if err != nil { 87 | return nil, err 88 | } 89 | 90 | return tls.Client(conn, &tls.Config{ 91 | ServerName: getServerName(address), 92 | InsecureSkipVerify: !h.https, 93 | }), nil 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /vendor/github.com/json-iterator/go/iter_skip_strict.go: -------------------------------------------------------------------------------- 1 | //+build !jsoniter_sloppy 2 | 3 | package jsoniter 4 | 5 | import "fmt" 6 | 7 | func (iter *Iterator) skipNumber() { 8 | if !iter.trySkipNumber() { 9 | iter.unreadByte() 10 | iter.ReadFloat32() 11 | } 12 | } 13 | 14 | func (iter *Iterator) trySkipNumber() bool { 15 | dotFound := false 16 | for i := iter.head; i < iter.tail; i++ { 17 | c := iter.buf[i] 18 | switch c { 19 | case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': 20 | case '.': 21 | if dotFound { 22 | iter.ReportError("validateNumber", `more than one dot found in number`) 23 | return true // already failed 24 | } 25 | if i+1 == iter.tail { 26 | return false 27 | } 28 | c = iter.buf[i+1] 29 | switch c { 30 | case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': 31 | default: 32 | iter.ReportError("validateNumber", `missing digit after dot`) 33 | return true // already failed 34 | } 35 | dotFound = true 36 | default: 37 | switch c { 38 | case ',', ']', '}', ' ', '\t', '\n', '\r': 39 | if iter.head == i { 40 | return false // if - without following digits 41 | } 42 | iter.head = i 43 | return true // must be valid 44 | } 45 | return false // may be invalid 46 | } 47 | } 48 | return false 49 | } 50 | 51 | func (iter *Iterator) skipString() { 52 | if !iter.trySkipString() { 53 | iter.unreadByte() 54 | iter.ReadString() 55 | } 56 | } 57 | 58 | func (iter *Iterator) trySkipString() bool { 59 | for i := iter.head; i < iter.tail; i++ { 60 | c := iter.buf[i] 61 | if c == '"' { 62 | iter.head = i + 1 63 | return true // valid 64 | } else if c == '\\' { 65 | return false 66 | } else if c < ' ' { 67 | iter.ReportError("trySkipString", 68 | fmt.Sprintf(`invalid control character found: %d`, c)) 69 | return true // already failed 70 | } 71 | } 72 | return false 73 | } 74 | 75 | func (iter *Iterator) skipObject() { 76 | iter.unreadByte() 77 | iter.ReadObjectCB(func(iter *Iterator, field string) bool { 78 | iter.Skip() 79 | return true 80 | }) 81 | } 82 | 83 | func (iter *Iterator) skipArray() { 84 | iter.unreadByte() 85 | iter.ReadArrayCB(func(iter *Iterator) bool { 86 | iter.Skip() 87 | return true 88 | }) 89 | } 90 | -------------------------------------------------------------------------------- /vendor/github.com/iikira/baidu-tools/tieba/tiebautil/client_signature.go: -------------------------------------------------------------------------------- 1 | package tiebautil 2 | 3 | import ( 4 | "bytes" 5 | "crypto/md5" 6 | "encoding/hex" 7 | "github.com/iikira/baidu-tools/randominfo" 8 | "sort" 9 | "strconv" 10 | "strings" 11 | "unsafe" 12 | ) 13 | 14 | // TiebaClientSignature 根据给定贴吧客户端的post数据进行签名, 以通过百度服务器验证. 返回值为签名后的 post 15 | func TiebaClientSignature(post map[string]string) { 16 | if post == nil { 17 | post = map[string]string{} 18 | } 19 | 20 | // 已经签名, 则重新签名 21 | if _, ok := post["sign"]; ok { 22 | delete(post, "sign") 23 | } 24 | 25 | var ( 26 | bduss = post["BDUSS"] 27 | model = randominfo.GetPhoneModel(bduss) 28 | phoneIMEIStr = strconv.FormatUint(randominfo.SumIMEI(model+"_"+bduss), 10) 29 | m = md5.New() 30 | ) 31 | 32 | // 预设 33 | post["_client_type"] = "2" 34 | post["_client_version"] = "7.0.0.0" 35 | post["_phone_imei"] = phoneIMEIStr 36 | post["from"] = "mini_ad_wandoujia" 37 | post["model"] = model 38 | m.Write([]byte(bduss + "_" + post["_client_version"] + "_" + post["_phone_imei"] + "_" + post["from"])) 39 | post["cuid"] = strings.ToUpper(hex.EncodeToString(m.Sum(nil))) + "|" + StringReverse(phoneIMEIStr) 40 | 41 | keys := make([]string, 0, len(post)) 42 | for key := range post { 43 | keys = append(keys, key) 44 | } 45 | sort.Sort(sort.StringSlice(keys)) 46 | 47 | m.Reset() 48 | for _, key := range keys { 49 | m.Write([]byte(key + "=" + post[key])) 50 | } 51 | m.Write([]byte("tiebaclient!!!")) 52 | 53 | post["sign"] = strings.ToUpper(hex.EncodeToString(m.Sum(nil))) 54 | } 55 | 56 | // TiebaClientRawQuerySignature 给 rawQuery 进行贴吧客户端签名, 返回值为签名后的 rawQuery 57 | func TiebaClientRawQuerySignature(rawQuery string) (signedRawQuery string) { 58 | m := md5.New() 59 | m.Write(bytes.Replace(*(*[]byte)(unsafe.Pointer(&rawQuery)), []byte("&"), nil, -1)) 60 | m.Write([]byte("tiebaclient!!!")) 61 | 62 | signedRawQuery = rawQuery + "&sign=" + strings.ToUpper(hex.EncodeToString(m.Sum(nil))) 63 | return 64 | } 65 | 66 | // StringReverse 翻转字符串 67 | func StringReverse(s string) string { 68 | runes := []rune(s) 69 | for from, to := 0, len(runes)-1; from < to; from, to = from+1, to-1 { 70 | runes[from], runes[to] = runes[to], runes[from] 71 | } 72 | return string(runes) 73 | } 74 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/reflect2/unsafe_array.go: -------------------------------------------------------------------------------- 1 | package reflect2 2 | 3 | import ( 4 | "unsafe" 5 | "reflect" 6 | ) 7 | 8 | type UnsafeArrayType struct { 9 | unsafeType 10 | elemRType unsafe.Pointer 11 | pElemRType unsafe.Pointer 12 | elemSize uintptr 13 | likePtr bool 14 | } 15 | 16 | func newUnsafeArrayType(cfg *frozenConfig, type1 reflect.Type) *UnsafeArrayType { 17 | return &UnsafeArrayType{ 18 | unsafeType: *newUnsafeType(cfg, type1), 19 | elemRType: unpackEFace(type1.Elem()).data, 20 | pElemRType: unpackEFace(reflect.PtrTo(type1.Elem())).data, 21 | elemSize: type1.Elem().Size(), 22 | likePtr: likePtrType(type1), 23 | } 24 | } 25 | 26 | func (type2 *UnsafeArrayType) LikePtr() bool { 27 | return type2.likePtr 28 | } 29 | 30 | func (type2 *UnsafeArrayType) Indirect(obj interface{}) interface{} { 31 | objEFace := unpackEFace(obj) 32 | assertType("Type.Indirect argument 1", type2.ptrRType, objEFace.rtype) 33 | return type2.UnsafeIndirect(objEFace.data) 34 | } 35 | 36 | func (type2 *UnsafeArrayType) UnsafeIndirect(ptr unsafe.Pointer) interface{} { 37 | if type2.likePtr { 38 | return packEFace(type2.rtype, *(*unsafe.Pointer)(ptr)) 39 | } 40 | return packEFace(type2.rtype, ptr) 41 | } 42 | 43 | func (type2 *UnsafeArrayType) SetIndex(obj interface{}, index int, elem interface{}) { 44 | objEFace := unpackEFace(obj) 45 | assertType("ArrayType.SetIndex argument 1", type2.ptrRType, objEFace.rtype) 46 | elemEFace := unpackEFace(elem) 47 | assertType("ArrayType.SetIndex argument 3", type2.pElemRType, elemEFace.rtype) 48 | type2.UnsafeSetIndex(objEFace.data, index, elemEFace.data) 49 | } 50 | 51 | func (type2 *UnsafeArrayType) UnsafeSetIndex(obj unsafe.Pointer, index int, elem unsafe.Pointer) { 52 | elemPtr := arrayAt(obj, index, type2.elemSize, "i < s.Len") 53 | typedmemmove(type2.elemRType, elemPtr, elem) 54 | } 55 | 56 | func (type2 *UnsafeArrayType) GetIndex(obj interface{}, index int) interface{} { 57 | objEFace := unpackEFace(obj) 58 | assertType("ArrayType.GetIndex argument 1", type2.ptrRType, objEFace.rtype) 59 | elemPtr := type2.UnsafeGetIndex(objEFace.data, index) 60 | return packEFace(type2.pElemRType, elemPtr) 61 | } 62 | 63 | func (type2 *UnsafeArrayType) UnsafeGetIndex(obj unsafe.Pointer, index int) unsafe.Pointer { 64 | return arrayAt(obj, index, type2.elemSize, "i < s.Len") 65 | } 66 | -------------------------------------------------------------------------------- /vendor/github.com/bitly/go-simplejson/simplejson_go10.go: -------------------------------------------------------------------------------- 1 | // +build !go1.1 2 | 3 | package simplejson 4 | 5 | import ( 6 | "encoding/json" 7 | "errors" 8 | "io" 9 | "reflect" 10 | ) 11 | 12 | // NewFromReader returns a *Json by decoding from an io.Reader 13 | func NewFromReader(r io.Reader) (*Json, error) { 14 | j := new(Json) 15 | dec := json.NewDecoder(r) 16 | err := dec.Decode(&j.data) 17 | return j, err 18 | } 19 | 20 | // Implements the json.Unmarshaler interface. 21 | func (j *Json) UnmarshalJSON(p []byte) error { 22 | return json.Unmarshal(p, &j.data) 23 | } 24 | 25 | // Float64 coerces into a float64 26 | func (j *Json) Float64() (float64, error) { 27 | switch j.data.(type) { 28 | case float32, float64: 29 | return reflect.ValueOf(j.data).Float(), nil 30 | case int, int8, int16, int32, int64: 31 | return float64(reflect.ValueOf(j.data).Int()), nil 32 | case uint, uint8, uint16, uint32, uint64: 33 | return float64(reflect.ValueOf(j.data).Uint()), nil 34 | } 35 | return 0, errors.New("invalid value type") 36 | } 37 | 38 | // Int coerces into an int 39 | func (j *Json) Int() (int, error) { 40 | switch j.data.(type) { 41 | case float32, float64: 42 | return int(reflect.ValueOf(j.data).Float()), nil 43 | case int, int8, int16, int32, int64: 44 | return int(reflect.ValueOf(j.data).Int()), nil 45 | case uint, uint8, uint16, uint32, uint64: 46 | return int(reflect.ValueOf(j.data).Uint()), nil 47 | } 48 | return 0, errors.New("invalid value type") 49 | } 50 | 51 | // Int64 coerces into an int64 52 | func (j *Json) Int64() (int64, error) { 53 | switch j.data.(type) { 54 | case float32, float64: 55 | return int64(reflect.ValueOf(j.data).Float()), nil 56 | case int, int8, int16, int32, int64: 57 | return reflect.ValueOf(j.data).Int(), nil 58 | case uint, uint8, uint16, uint32, uint64: 59 | return int64(reflect.ValueOf(j.data).Uint()), nil 60 | } 61 | return 0, errors.New("invalid value type") 62 | } 63 | 64 | // Uint64 coerces into an uint64 65 | func (j *Json) Uint64() (uint64, error) { 66 | switch j.data.(type) { 67 | case float32, float64: 68 | return uint64(reflect.ValueOf(j.data).Float()), nil 69 | case int, int8, int16, int32, int64: 70 | return uint64(reflect.ValueOf(j.data).Int()), nil 71 | case uint, uint8, uint16, uint32, uint64: 72 | return reflect.ValueOf(j.data).Uint(), nil 73 | } 74 | return 0, errors.New("invalid value type") 75 | } 76 | -------------------------------------------------------------------------------- /pcspath/util.go: -------------------------------------------------------------------------------- 1 | package pcspath 2 | 3 | import ( 4 | "path" 5 | "strings" 6 | ) 7 | 8 | // EscapeBracketOne 转义中括号, 加一个反斜杠 9 | func EscapeBracketOne(s string) string { 10 | if !strings.Contains(s, "[") && !strings.Contains(s, "]") { 11 | return s 12 | } 13 | 14 | builder := &strings.Builder{} 15 | for k := range s { 16 | if s[k] != '[' && s[k] != ']' { 17 | builder.WriteByte(s[k]) 18 | continue 19 | } 20 | 21 | if k >= 1 && s[k-1] == '\\' { 22 | builder.WriteByte(s[k]) 23 | continue 24 | } 25 | builder.WriteString(`\`) 26 | builder.WriteByte(s[k]) 27 | } 28 | return builder.String() 29 | } 30 | 31 | // EscapeBracketTwo 转义中括号, 加两个反斜杠 32 | func EscapeBracketTwo(s string) string { 33 | if !strings.Contains(s, "[") && !strings.Contains(s, "]") { 34 | return s 35 | } 36 | 37 | builder := &strings.Builder{} 38 | for k := range s { 39 | if s[k] != '[' && s[k] != ']' { 40 | builder.WriteByte(s[k]) 41 | continue 42 | } 43 | 44 | if k >= 2 && s[k-1] == '\\' && s[k-2] == '\\' { 45 | builder.WriteByte(s[k]) 46 | continue 47 | } 48 | builder.WriteString(`\\`) 49 | builder.WriteByte(s[k]) 50 | } 51 | return builder.String() 52 | } 53 | 54 | // SplitAll 分割路径, "/"为分隔符 55 | func SplitAll(pcspath string) (elem []string) { 56 | pcspath = path.Clean(pcspath) 57 | 58 | raw := strings.Split(pcspath, "/") 59 | 60 | if !path.IsAbs(pcspath) { 61 | elem = append(elem, raw[0]) 62 | } 63 | 64 | for k := range raw[1:] { 65 | elem = append(elem, "/"+raw[k+1]) 66 | } 67 | 68 | return 69 | } 70 | 71 | // Escape 转义字符串的空格, 小括号, 中括号 72 | func Escape(pcspath string) string { 73 | if !strings.ContainsAny(pcspath, " []()") { 74 | return pcspath 75 | } 76 | 77 | var ( 78 | builder = &strings.Builder{} 79 | isSlash bool 80 | ) 81 | for _, s := range pcspath { 82 | switch s { 83 | case '\\': 84 | isSlash = !isSlash 85 | if !isSlash { 86 | builder.WriteRune('\\') 87 | } 88 | continue 89 | case ' ', '[', ']', '(', ')': 90 | builder.WriteString("\\") 91 | builder.WriteRune(s) 92 | isSlash = false 93 | continue 94 | default: 95 | isSlash = false 96 | builder.WriteRune(s) 97 | } 98 | } 99 | return builder.String() 100 | } 101 | 102 | // EscapeStrings 转义字符串数组所有元素的空格, 小括号, 中括号 103 | func EscapeStrings(ss []string) { 104 | for k := range ss { 105 | ss[k] = Escape(ss[k]) 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /pcsutil/converter/converter.go: -------------------------------------------------------------------------------- 1 | // Package converter 格式, 类型转换包 2 | package converter 3 | 4 | import ( 5 | "fmt" 6 | "strconv" 7 | "unsafe" 8 | ) 9 | 10 | const ( 11 | // B byte 12 | B = (int64)(1 << (10 * iota)) 13 | // KB kilobyte 14 | KB 15 | // MB megabyte 16 | MB 17 | // GB gigabyte 18 | GB 19 | // TB terabyte 20 | TB 21 | // PB petabyte 22 | PB 23 | ) 24 | 25 | // ConvertFileSize 文件大小格式化输出 26 | func ConvertFileSize(size int64, precision ...int) string { 27 | pint := "6" 28 | if len(precision) == 1 { 29 | pint = fmt.Sprint(precision[0]) 30 | } 31 | if size < 0 { 32 | return "0B" 33 | } 34 | if size < KB { 35 | return fmt.Sprintf("%dB", size) 36 | } 37 | if size < MB { 38 | return fmt.Sprintf("%."+pint+"fKB", float64(size)/float64(KB)) 39 | } 40 | if size < GB { 41 | return fmt.Sprintf("%."+pint+"fMB", float64(size)/float64(MB)) 42 | } 43 | if size < TB { 44 | return fmt.Sprintf("%."+pint+"fGB", float64(size)/float64(GB)) 45 | } 46 | if size < PB { 47 | return fmt.Sprintf("%."+pint+"fTB", float64(size)/float64(TB)) 48 | } 49 | return fmt.Sprintf("%."+pint+"fPB", float64(size)/float64(PB)) 50 | } 51 | 52 | // ToString unsafe 转换, 将 []byte 转换为 string 53 | func ToString(p []byte) string { 54 | return *(*string)(unsafe.Pointer(&p)) 55 | } 56 | 57 | // ToBytes unsafe 转换, 将 string 转换为 []byte 58 | func ToBytes(str string) []byte { 59 | return *(*[]byte)(unsafe.Pointer(&str)) 60 | } 61 | 62 | // IntToBool int 类型转换为 bool 63 | func IntToBool(i int) bool { 64 | return i != 0 65 | } 66 | 67 | // SliceStringToInt64 []string 转换为 []int64 68 | func SliceStringToInt64(ss []string) (si []int64) { 69 | si = make([]int64, 0, len(ss)) 70 | var ( 71 | i int64 72 | err error 73 | ) 74 | for k := range ss { 75 | i, err = strconv.ParseInt(ss[k], 10, 64) 76 | if err != nil { 77 | continue 78 | } 79 | si = append(si, i) 80 | } 81 | return 82 | } 83 | 84 | // MustInt 将string转换为int, 忽略错误 85 | func MustInt(s string) (n int) { 86 | n, _ = strconv.Atoi(s) 87 | return 88 | } 89 | 90 | // MustInt64 将string转换为int64, 忽略错误 91 | func MustInt64(s string) (i int64) { 92 | i, _ = strconv.ParseInt(s, 10, 64) 93 | return 94 | } 95 | 96 | // ShortDisplay 缩略显示字符串s, 显示长度为num, 缩略的内容用"..."填充 97 | func ShortDisplay(s string, num int) string { 98 | for k := range s { 99 | if k >= num { 100 | return string(s[:k]) + "..." 101 | } 102 | } 103 | return s 104 | } 105 | -------------------------------------------------------------------------------- /vendor/github.com/modern-go/reflect2/unsafe_field.go: -------------------------------------------------------------------------------- 1 | package reflect2 2 | 3 | import ( 4 | "reflect" 5 | "unsafe" 6 | ) 7 | 8 | type UnsafeStructField struct { 9 | reflect.StructField 10 | structType *UnsafeStructType 11 | rtype unsafe.Pointer 12 | ptrRType unsafe.Pointer 13 | } 14 | 15 | func newUnsafeStructField(structType *UnsafeStructType, structField reflect.StructField) *UnsafeStructField { 16 | return &UnsafeStructField{ 17 | StructField: structField, 18 | rtype: unpackEFace(structField.Type).data, 19 | ptrRType: unpackEFace(reflect.PtrTo(structField.Type)).data, 20 | structType: structType, 21 | } 22 | } 23 | 24 | func (field *UnsafeStructField) Offset() uintptr { 25 | return field.StructField.Offset 26 | } 27 | 28 | func (field *UnsafeStructField) Name() string { 29 | return field.StructField.Name 30 | } 31 | 32 | func (field *UnsafeStructField) PkgPath() string { 33 | return field.StructField.PkgPath 34 | } 35 | 36 | func (field *UnsafeStructField) Type() Type { 37 | return field.structType.cfg.Type2(field.StructField.Type) 38 | } 39 | 40 | func (field *UnsafeStructField) Tag() reflect.StructTag { 41 | return field.StructField.Tag 42 | } 43 | 44 | func (field *UnsafeStructField) Index() []int { 45 | return field.StructField.Index 46 | } 47 | 48 | func (field *UnsafeStructField) Anonymous() bool { 49 | return field.StructField.Anonymous 50 | } 51 | 52 | func (field *UnsafeStructField) Set(obj interface{}, value interface{}) { 53 | objEFace := unpackEFace(obj) 54 | assertType("StructField.SetIndex argument 1", field.structType.ptrRType, objEFace.rtype) 55 | valueEFace := unpackEFace(value) 56 | assertType("StructField.SetIndex argument 2", field.ptrRType, valueEFace.rtype) 57 | field.UnsafeSet(objEFace.data, valueEFace.data) 58 | } 59 | 60 | func (field *UnsafeStructField) UnsafeSet(obj unsafe.Pointer, value unsafe.Pointer) { 61 | fieldPtr := add(obj, field.StructField.Offset, "same as non-reflect &v.field") 62 | typedmemmove(field.rtype, fieldPtr, value) 63 | } 64 | 65 | func (field *UnsafeStructField) Get(obj interface{}) interface{} { 66 | objEFace := unpackEFace(obj) 67 | assertType("StructField.GetIndex argument 1", field.structType.ptrRType, objEFace.rtype) 68 | value := field.UnsafeGet(objEFace.data) 69 | return packEFace(field.ptrRType, value) 70 | } 71 | 72 | func (field *UnsafeStructField) UnsafeGet(obj unsafe.Pointer) unsafe.Pointer { 73 | return add(obj, field.StructField.Offset, "same as non-reflect &v.field") 74 | } 75 | -------------------------------------------------------------------------------- /requester/downloader/download_test.go: -------------------------------------------------------------------------------- 1 | package downloader 2 | 3 | import ( 4 | "fmt" 5 | "github.com/iikira/BaiduPCS-Go/pcsverbose" 6 | "github.com/iikira/BaiduPCS-Go/requester" 7 | "os" 8 | "testing" 9 | "time" 10 | ) 11 | 12 | var ( 13 | url1 = "https://dldir1.qq.com/qqfile/qq/TIM2.1.8/23475/TIM2.1.8.exe" 14 | url2 = "https://git.oschina.net/lufenping/pixabay_img/raw/master/tiny-20170712/lizard-2427248_1920.jpg" 15 | ) 16 | 17 | func TestRandomNumber(t *testing.T) { 18 | for i := 0; i < 10; i++ { 19 | fmt.Println(RandomNumber(0, 5)) 20 | } 21 | } 22 | 23 | func TestExample(t *testing.T) { 24 | DoDownload(url2, "lizard-2427248_1920.jpg", nil) 25 | } 26 | 27 | func TestDownloadTIM(t *testing.T) { 28 | pcsverbose.IsVerbose = true 29 | 30 | file, _ := os.OpenFile("tim.exe", os.O_CREATE|os.O_WRONLY, 0777) 31 | d := NewDownloader(url1, file, &Config{ 32 | MaxParallel: 10, 33 | CacheSize: 8192, 34 | InstanceStatePath: "tmp.txt", 35 | }) 36 | 37 | client := requester.NewHTTPClient() 38 | client.SetTimeout(10 * time.Second) 39 | d.SetClient(client) 40 | 41 | go func() { 42 | for { 43 | if d.monitor != nil { 44 | fmt.Println(d.monitor.ShowWorkers()) 45 | } 46 | time.Sleep(1e9) 47 | } 48 | }() 49 | go func() { 50 | time.Sleep(3e9) 51 | d.Pause() 52 | time.Sleep(5e9) 53 | d.Resume() 54 | time.Sleep(9e9) 55 | d.Pause() 56 | time.Sleep(5e9) 57 | d.Resume() 58 | time.Sleep(3e9) 59 | d.Cancel() 60 | fmt.Println("canceled") 61 | time.Sleep(3e9) 62 | }() 63 | err := d.Execute() 64 | if err != nil { 65 | fmt.Println(err) 66 | } 67 | } 68 | 69 | func newSlice() [][]byte { 70 | s := make([][]byte, 20) 71 | s[0] = []byte("kjashdfiuqwheirhwuq") 72 | s[9] = []byte("kjashdfiuqwheirhwuq") 73 | return s 74 | } 75 | 76 | func rangeSlice(f func(key int, by []byte) bool) { 77 | s := newSlice() 78 | for k := range s { 79 | if s[k] == nil { 80 | continue 81 | } 82 | if !f(k, s[k]) { 83 | break 84 | } 85 | } 86 | } 87 | 88 | func BenchmarkRange1(b *testing.B) { 89 | for i := 0; i < b.N; i++ { 90 | var a = 0 91 | rangeSlice(func(key int, s []byte) bool { 92 | a++ 93 | return true 94 | }) 95 | } 96 | } 97 | 98 | func BenchmarkRange2(b *testing.B) { 99 | for i := 0; i < b.N; i++ { 100 | s := newSlice() 101 | a := 0 102 | for k := range s { 103 | if s[k] == nil { 104 | continue 105 | } 106 | a++ 107 | } 108 | } 109 | } 110 | --------------------------------------------------------------------------------