Skip to content

Commit

Permalink
add qrcode export function
Browse files Browse the repository at this point in the history
  • Loading branch information
jicheng1014 committed Dec 19, 2022
1 parent 77905ce commit ee80bee
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
icon.png
qr.png
go_fir_cli
go_fir_cli.exe
*.apk
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

## 说明

这是一个 fir-cli [https://github.com/PGYER/fir-cli](https://github.com/PGYER/fir-cli) 的 go 版本, 用于上传文件到 betaqr.com (原fir.im)
这是一个 fir-cli [https://github.com/PGYER/fir-cli](https://github.com/PGYER/fir-cli) 的 go 版本, 用于上传文件到 [betaqr.com](https://www.betaqr.com) (原fir.im)

## 安装

下载自己对应的系统的文件, 赋值可执行. 若想在全局使用,放到 path 里即可.

- macOS 使用 darwin-amd64
- Linux 使用 amd64
- Windows 使用




Expand Down
8 changes: 5 additions & 3 deletions api/rio_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type FirApi struct {
ApiToken string
AppChangelog string
Email string
QrCodePngNeed bool
QrCodeAsciiNeed bool
ApiAppInfo *ApiAppInfo
uploadAppService *analysis.UploadAppService
appFileInfo *analysis.AppFileInfo
Expand Down Expand Up @@ -236,7 +238,7 @@ func (f *FirApi) Upload(file string) error {
fmt.Println(resp)

// 进行回调
resp, e = manualCallback(file, f.appFileInfo, uploadingInfo)
resp, e = f.manualCallback(file, f.appFileInfo, uploadingInfo)
if e != nil {
fmt.Println("上传成功, 但是回调失败", e.Error())
os.Exit(1)
Expand Down Expand Up @@ -335,7 +337,7 @@ func (f *FirApi) uploadAppFile(uploadingInfo AppPrepareUploadData, file string)
return resp, e
}

func manualCallback(file string, appInfo *analysis.AppFileInfo, uploadingInfo AppPrepareUploadData) (*resty.Response, error) {
func (f *FirApi) manualCallback(file string, appInfo *analysis.AppFileInfo, uploadingInfo AppPrepareUploadData) (*resty.Response, error) {
// manual callback
client := resty.New()

Expand All @@ -355,7 +357,7 @@ func manualCallback(file string, appInfo *analysis.AppFileInfo, uploadingInfo Ap
ReleaseType: appInfo.ReleaseType,
Token: uploadingInfo.Cert.Binary.Token,
Version: appInfo.Version,
Changelog: appInfo.Changelog,
Changelog: f.AppChangelog,
UserId: uploadingInfo.AppUserId,
}

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ require (

require (
github.com/klauspost/compress v1.15.12 // indirect
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
golang.org/x/net v0.0.0-20211029224645-99673261e6eb // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ github.com/klauspost/compress v1.15.12/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrD
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/shogo82148/androidbinary v1.0.3 h1:0E9bBCcDVwb2xJP3NwDkdfkxtOrys3DK/NjxnUq+bNI=
github.com/shogo82148/androidbinary v1.0.3/go.mod h1:TZXT25KBG2LxEC+kh7v2qvmwXfMwC/FNxKt7uTf8tJc=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
golang.org/x/net v0.0.0-20211029224645-99673261e6eb h1:pirldcYWx7rx7kE5r+9WsOXPXK0+WH5+uZ7uPmJ44uM=
golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
Expand Down
58 changes: 53 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package main

import (
"fmt"
"io/ioutil"
"os"

"betaqr.com/go_fir_cli/api"
"betaqr.com/go_fir_cli/constants"
"github.com/skip2/go-qrcode"
"gopkg.in/urfave/cli.v1"
)

Expand Down Expand Up @@ -33,7 +35,7 @@ func initCli() {
cli.Command{
Name: "version",
ShortName: "v",
Usage: "查看版本",
Usage: "查看 go_fir_cli 版本",
Action: func(c *cli.Context) error {
fmt.Println(constants.VERSION)
return nil
Expand Down Expand Up @@ -77,7 +79,19 @@ func uploadFile() cli.Command {
},
cli.StringFlag{
Name: "changelog, c",
Usage: "app 的更新日志",
Usage: "app 的更新日志, 可以是文件路径, 也可以是字符串",
},
cli.BoolFlag{
Name: "specific_release, s",
Usage: "生成的下载地址是否精确指定到 release, 默认为 false",
},
cli.BoolFlag{
Name: "qrcode, q",
Usage: "输出二维码文件 qrcode.png, 用于下载, 默认为 false",
},
cli.BoolFlag{
Name: "qrcodeascii, Q",
Usage: "输出二维码到终端, 默认为 false",
},
},
Action: func(c *cli.Context) error {
Expand All @@ -97,16 +111,50 @@ func uploadFile() cli.Command {

changelog := c.String("changelog")

// 检测 changelog 文件path是否存在
if changelog != "" {
_, err := os.Stat(changelog)
if err != nil {
// 文件不存在, 说明changlog 就是 changlog 字符串
} else {
//
str, e := ioutil.ReadFile(changelog)
if e != nil {

} else {
changelog = string(str)
}
}
}

api := api.FirApi{
ApiToken: token,
AppChangelog: changelog,
ApiToken: token,
AppChangelog: changelog,
QrCodePngNeed: c.Bool("qrcode"),
QrCodeAsciiNeed: c.Bool("qrcodeascii"),
}

api.Upload(file)
fmt.Println("上传成功")
fmt.Printf("下载页面: http://%s/%s\nReleaseID: %s\n", api.ApiAppInfo.DownloadDomain, api.ApiAppInfo.Short, api.ApiAppInfo.MasterReleaseId)
url := buildDownloadUrl(api.ApiAppInfo, c.Bool("specific_release"))
fmt.Printf("下载页面: %s\nReleaseID: %s\n", url, api.ApiAppInfo.MasterReleaseId)

if api.QrCodePngNeed {
fmt.Println("二维码文件: qrcode.png")
qrcode.WriteFile(url, qrcode.Medium, 256, "qr.png")
}

if api.QrCodeAsciiNeed {

}
return nil
},
}
}

func buildDownloadUrl(apiAppInfo *api.ApiAppInfo, includeRelease bool) string {
if includeRelease {
return fmt.Sprintf("http://%s/%s?release_id=%s", apiAppInfo.DownloadDomain, apiAppInfo.Short, apiAppInfo.MasterReleaseId)
}
return fmt.Sprintf("http://%s/%s", apiAppInfo.DownloadDomain, apiAppInfo.Short)
}

0 comments on commit ee80bee

Please sign in to comment.