diff --git a/build/upload.bat b/build/upload-dir.bat similarity index 100% rename from build/upload.bat rename to build/upload-dir.bat diff --git a/build/upload-web.bat b/build/upload-web.bat new file mode 100644 index 0000000..7758a44 --- /dev/null +++ b/build/upload-web.bat @@ -0,0 +1,2 @@ + %~dp0qcloudcos -op upload -path %1 -qpath / +pause \ No newline at end of file diff --git a/main.go b/main.go index 6afdeb0..6fbad27 100644 --- a/main.go +++ b/main.go @@ -26,6 +26,7 @@ var config TencentYunConfig var op string var path string +var qpath string var key string func loadKey() { @@ -74,6 +75,7 @@ func main() { helper.AesKey = []byte("3136352472abcdef") flag.StringVar(&op, "op", "", "操作:make-key[生成密钥] | set-key[设置密钥] | upload [上传文件] | list [获取文件]") flag.StringVar(&path, "path", "", "上传目录") + flag.StringVar(&qpath, "qpath", "", "云上传目的目录") flag.StringVar(&key, "key", "", "key") flag.Parse() @@ -120,7 +122,12 @@ func main() { initKey() if path != "" { - url := UploadDir(path) + url := "" + if qpath == "" { + url = UploadDir(path) + } else { + url = UploadDir(path, qpath) + } fmt.Println("url:", url) } else { flag.Usage() @@ -191,7 +198,9 @@ func getTencentYunCosFiles(prefix string) (*cos.BucketGetResult, error) { // 1.永久密钥 client := getTencentYunConf(&config) - + if prefix == "" { + prefix = strings.Replace(config.Root+"/", `//`, `/`, -1) + } res, _, err := client.Bucket.Get(context.Background(), &cos.BucketGetOptions{ Prefix: prefix, Delimiter: "/", @@ -237,7 +246,12 @@ func UploadDir(fpath string, qpaths ...string) string { } } - return config.BucketURL + "/" + strings.Replace(filepath.Join(config.Root, qpath), `\`, `/`, -1) + urlPath := "/" + strings.Replace(filepath.Join(config.Root, qpath), `\`, `/`, -1) + for strings.Index(urlPath, "//") > -1 { + urlPath = strings.Replace(urlPath, "//", "/", -1) + } + + return config.BucketURL + urlPath } func askSelect(title string, v ...string) (int, string) {