Skip to content

Commit

Permalink
add --save-uploaded-info
Browse files Browse the repository at this point in the history
  • Loading branch information
jicheng1014 committed Mar 24, 2023
1 parent a5c9585 commit 1d6b6da
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ test.go
*.apk
*.ipa
.vscode/*
michael_jordan.png
michael_jordan.png
go-fir-cli-answer.json
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ go-fir-cli 只实现了 fir-cli 的部分功能, 并无计划实现全部功能,
由于作者不善 golang, 所以大部分代码皆来自于 Copilot 和 chatGPT 生成, 作者仅在此基础上做了一些修改与调试, 以便于使用. 如果您在使用中发现任何问题, 欢迎提 issue 或者 pr.

## 更新说明
- 0.0.8 增加了自定义图标参数 --icon_path
- 0.0.9 upload 增加了参数 --save-uploaded-info, 将结果存入当前目录下的 go-fir-cli-answer.json
- 0.0.8 upload 增加了自定义图标参数 --icon_path
- 0.0.7 支持了持久化登录
- 0.0.6 支持了windows平台
- 0.0.5 支持了上传进度条显示
- 0.0.4 支持了 arm64 的二进制文件, 上传时会有命令行的提示
- 0.0.3 支持了 企业微信、飞书和钉钉的通知机器人
- 0.0.2 支持了生成二维码文件, 支持精确到版本的下载地址
- 0.0.3 upload 支持了 企业微信、飞书和钉钉的通知机器人
- 0.0.2 upload 支持了生成二维码文件, 支持精确到版本的下载地址
- 0.0.1 支持了上传文件

## 安装
Expand Down
2 changes: 2 additions & 0 deletions api/rio_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type FirApi struct {
CustomIconPath string
QrCodePngNeed bool
QrCodeAsciiNeed bool
SaveUploadedInfo bool
ApiAppInfo *ApiAppInfo
uploadAppService *analysis.UploadAppService
appFileInfo *analysis.AppFileInfo
Expand All @@ -44,6 +45,7 @@ type ApiAppInfo struct {
BundleId string `json:"bundle_id"`
DownloadDomain string `json:"download_domain"`
MasterReleaseId string `json:"master_release_id"`
DownloadUrl string
}

type IconCallback struct {
Expand Down
2 changes: 1 addition & 1 deletion constants/constants.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package constants

const VERSION = "0.0.8"
const VERSION = "0.0.9"
const USER_AGENT = "go-fir-" + VERSION
21 changes: 16 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ func uploadFile() cli.Command {
Usage: "输出二维码文件 qrcode.png, 用于下载, 默认为 false",
},

cli.BoolFlag{
Name: "save-uploaded-info, sui",
Usage: "上传成功后, 保存上传信息到本地 go-fir-cli-answer.json, 用于用户的其他集成操作, 默认为 false",
},

cli.StringFlag{
Name: "dingtalkToken, dt",
Usage: "dingtalk 的机器人的 token, 用于发送通知",
Expand Down Expand Up @@ -231,23 +236,29 @@ func uploadFile() cli.Command {
}

api := api.FirApi{
ApiToken: token,
CustomIconPath: c.String("icon_path"),
AppChangelog: changelog,
QrCodePngNeed: c.Bool("qrcode"),
QrCodeAsciiNeed: c.Bool("qrcodeascii"),
ApiToken: token,
CustomIconPath: c.String("icon_path"),
AppChangelog: changelog,
QrCodePngNeed: c.Bool("qrcode"),
QrCodeAsciiNeed: c.Bool("qrcodeascii"),
SaveUploadedInfo: c.Bool("save-uploaded-info"),
}

api.Upload(file)
fmt.Println("上传成功")
url := buildDownloadUrl(api.ApiAppInfo, c.Bool("specific_release"))
api.ApiAppInfo.DownloadUrl = url
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.SaveUploadedInfo {
utils.SaveAnswer(api.ApiAppInfo)
}

if c.String("dingtalkToken") != "" {
notifier := &notifiers.DingTalkNotifier{
Key: c.String("dingtalkToken"),
Expand Down
29 changes: 29 additions & 0 deletions utils/save_file.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package utils

import (
"encoding/json"
"io/ioutil"
"time"

"github.com/PGYER/go-fir-cli/api"
)

func SaveAnswer(apiAppInfo *api.ApiAppInfo) error {
// fileName := "fir-cli-answer.json"

data := make(map[string]string)
now := time.Now()

data["short"] = apiAppInfo.Short
data["name"] = apiAppInfo.Name
data["download_url"] = apiAppInfo.DownloadUrl
data["app_id"] = apiAppInfo.Id
data["release_id"] = apiAppInfo.MasterReleaseId
data["time"] = now.Format("2006-01-02 15:03:04")

json, _ := json.Marshal(data)
// 将 data 转化为 json 后存储到本地answer.json 中
ioutil.WriteFile("go-fir-cli-answer.json", json, 0644)

return nil
}

0 comments on commit 1d6b6da

Please sign in to comment.