Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
jaronnie committed Jan 27, 2022
1 parent 09c5dae commit 03c7903
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 50 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.idea

dist/
32 changes: 32 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# CHANGELOG

## v1.0

* account
* put
* rm
* ls
41 changes: 10 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# qiniu-cli

merged from [https://github.com/nj-jay/qiniu-cli](https://github.com/nj-jay/qiniu-cli)


如果你选择了七牛云作为图床

而又不想在浏览器中上传图片或者文件等
Expand All @@ -19,16 +16,6 @@ qiniu-cli一个基于命令行的文件上传工具

[免费图床](free-pic)

体验版:http://tools.gocloudcoder.com/#/upload

## 下载

| 平台 | 下载地址 |
| ----- | ------------------------------------------------------------ |
| linux | [https://picture.nj-jay.com/qn_linux](https://picture.nj-jay.com/qn_linux) |
| win | [https://picture.nj-jay.com/qn_win.exe](https://picture.nj-jay.com/qn_win.exe) |
| mac | [https://picture.nj-jay.com/qn_mac](https://picture.nj-jay.com/qn_mac) |

## 配置

首先在七牛云上找到账号ak sk [链接](https://portal.qiniu.com/user/key)
Expand Down Expand Up @@ -89,29 +76,31 @@ qn put ../images/test.png
qn put test.png
# 结果为:
upload successfully
外链为:http://picture.nj-jay.com/test.png
外链为:http(s)://resource.jaronnie.com/test.png

# 你也可以上传多个文件
qn put ~/.pic/maven-compile.png ~/.pic/maven-package.png
# 结果为:
upload successfully
外链为:
http://picture.nj-jay.com/maven-compile.png
外链为:http(s)://resource.jaronnie.com/test.png

upload successfully
外链为:
http://picture.nj-jay.com/maven-package.png
外链为:http(s)://resource.jaronnie.com/test.png

## 如果你要覆盖上传 请使用-w选项
qn put -w test.png
qn put -w test1.png test2.png

# 可以将网页文件上传
qn put https://xx/test.png
外链为:http(s)://resource.jaronnie.com/test.png
```

使用qn -h查看支持的命令

## 与typora天然集成
## 与 Typora 天然集成

如果你使用的是typora这款软件编写markdown
如果你使用的是 typora 这款软件编写 markdown

那么这个工具将是你的不二之选

Expand All @@ -124,15 +113,5 @@ qn put -w test1.png test2.png
| 子命令 | 如何使用 | 注意事项 |
| ------- | -------------------------- | ------------------------------------------------------------ |
| account | qn account -w ak sk bucket | 替换你在七牛云上的ak sk bucket |
| put | qn put filename [filename] | filename可填写绝对路径和相对路径,注意使用/而不是\,可同时传多个文件,用空格隔开 |
| put | qn put [-w] filename [filename] | filename可填写绝对路径和相对路径,注意使用/而不是\,可同时传多个文件,用空格隔开 |
| ls | qn ls 或 qn ls *.xxx | xxx为文件的后缀 如 qn ls *.png |

## TODO

- [x] 支持通配符(批量传入)

- [ ] 改进路径问题(去除路径中的空格)

## 更新

* 4.20 可将网络上的文件上传到七牛中
16 changes: 9 additions & 7 deletions banner.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
_ _
(_) __ _ _ __ ___ _ __ _ __ (_) ___
| |/ _` | '__/ _ \| '_ \| '_ \| |/ _ \
| | (_| | | | (_) | | | | | | | | __/
_/ |\__,_|_| \___/|_| |_|_| |_|_|\___|
|__/

___
__ __ /\_ \ __
__ /\_\ ___ /\_\ __ __ ___\//\ \ /\_\
/'__`\/\ \ /' _ `\/\ \/\ \/\ \ _______ /'___\\ \ \ \/\ \
/\ \L\ \ \ \/\ \/\ \ \ \ \ \_\ \/\______\/\ \__/ \_\ \_\ \ \
\ \___, \ \_\ \_\ \_\ \_\ \____/\/______/\ \____\/\____\\ \_\
\/___/\ \/_/\/_/\/_/\/_/\/___/ \/____/\/____/ \/_/
\ \_\
\/_/
9 changes: 5 additions & 4 deletions cmd/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package cmd

import (
"fmt"
"io/ioutil"

"github.com/fatih/color"
"github.com/jaronnie/qiniu-cli/cmd/fs"
"github.com/spf13/cobra"
"io/ioutil"
)

var (
accountOver bool
)


var (
Acc fs.Account
Bm = fs.BucketManger{}
Expand Down Expand Up @@ -41,15 +42,15 @@ func Account(cmd *cobra.Command, params []string) {
if ak == "" || sk == "" || bucket == "" {
fmt.Println("please set your ak, sk, bucket in config file(default is ~/.qn.toml)")
} else {
fmt.Println(string(file))
color.Cyan(string(file))
fmt.Println("Reading from ~/.qn.toml")
fmt.Println("ak: ", ak)
fmt.Println("sk: ", sk)
fmt.Println("bucket: ", bucket)
}
} else if len(params) == 3 && accountOver {
Acc.InitAccount(params)
fmt.Println(string(file))
color.Cyan(string(file))
} else if len(params) == 3 && !accountOver {
fmt.Println("please use -w flags. For example, qn account -w ak sk bucket")
}
Expand Down
22 changes: 18 additions & 4 deletions cmd/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ package cmd
import (
"context"
"fmt"
"github.com/qiniu/go-sdk/v7/cdn"
"os"
"strings"

"github.com/qiniu/go-sdk/v7/auth/qbox"
"github.com/qiniu/go-sdk/v7/cdn"
"github.com/qiniu/go-sdk/v7/storage"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var (
overwrite bool
overwrite bool
defaultProtocol = "http"
)

type PutRet struct {
Expand Down Expand Up @@ -79,7 +81,8 @@ func putRemoteFile(path string, mac *qbox.Mac, bucket string, cfg storage.Config
fmt.Println(err)
}
domains, _ := bm.ListBucketDomains(bucket)
fmt.Println("http://" + domains[0].Domain + "/" + res.Key)

fmt.Println(getProtocol() + "://" + domains[0].Domain + "/" + res.Key)
}

func putLocalFile(path string, mac *qbox.Mac, bucket string, cfg storage.Config) {
Expand Down Expand Up @@ -144,7 +147,18 @@ func putLocalFile(path string, mac *qbox.Mac, bucket string, cfg storage.Config)
fmt.Println(err)
return
}
fmt.Println("https://" + domains[0].Domain + "/" + upload)
fmt.Println(getProtocol() + "://" + domains[0].Domain + "/" + upload)
}

func getProtocol() string {
protocol := viper.GetString("qn.protocol")
if protocol == "" {
return defaultProtocol
}
if protocol != "http" && protocol != "https" {
return defaultProtocol
}
return protocol
}

func init() {
Expand Down
5 changes: 2 additions & 3 deletions cmd/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package cmd
import (
"fmt"

"github.com/qiniu/go-sdk/v7/storage"
"github.com/qiniu/go-sdk/v7/cdn"
"github.com/qiniu/go-sdk/v7/storage"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -33,9 +33,8 @@ func rm(cmd *cobra.Command, args []string) {
return
}
fmt.Printf("delete %s successfully\n", args[0])
//删除只有还需要刷新cdn 几秒后就能看到效果! 还是挺不错的!
urlsToRefresh := []string{
"https://picture.nj-jay.com/banner.txt",
args[0],
}

cdnManager := cdn.NewCdnManager(mac)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/jaronnie/qiniu-cli
go 1.16

require (
github.com/fatih/color v1.13.0 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/magiconair/properties v1.8.4 // indirect
github.com/mitchellh/go-homedir v1.1.0
Expand All @@ -14,7 +15,6 @@ require (
github.com/spf13/cobra v1.1.1
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/viper v1.7.1
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 // indirect
golang.org/x/text v0.3.5 // indirect
gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
Expand Down Expand Up @@ -115,7 +117,12 @@ github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czP
github.com/magiconair/properties v1.8.4 h1:8KGKTcQQGm0Kv7vEbKFErAoAOFyyacLStRtQSeYtvkY=
github.com/magiconair/properties v1.8.4/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
Expand Down Expand Up @@ -262,8 +269,12 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
Expand Down

0 comments on commit 03c7903

Please sign in to comment.