From e986f97874f0e4dd12974bae58dd08b5b466b16d Mon Sep 17 00:00:00 2001
From: shenwc <spd260@126.com>
Date: 星期二, 26 十一月 2024 17:48:06 +0800
Subject: [PATCH] add qiniu

---
 stores/qiniu/qiniu.go |   79 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 79 insertions(+), 0 deletions(-)

diff --git a/stores/qiniu/qiniu.go b/stores/qiniu/qiniu.go
new file mode 100644
index 0000000..e64a8ce
--- /dev/null
+++ b/stores/qiniu/qiniu.go
@@ -0,0 +1,79 @@
+package qiniu
+
+import (
+	"fmt"
+	"runtime"
+	"strings"
+
+	"github.com/zan8in/goupdate/progress"
+)
+
+type Store struct {
+	Owner   string
+	Repo    string
+	Version string
+}
+
+type QiniuResult struct {
+	Status        int // update success = 1; have latest version = 2;
+	LatestVersion string
+}
+
+func init() {
+	fmt.Printf("qiniu store %s", "init!")
+}
+
+// 更新最新版本
+// owner = zan8in
+// repo = afrog
+// version = 2.8.8 当前版本
+func Update(owner, repo, version string) (*QiniuResult, error) {
+	var (
+		result = &QiniuResult{}
+		err    error
+	)
+
+	var command string
+	switch runtime.GOOS {
+	case "windows":
+		command = repo + ".exe"
+	default:
+		command = repo
+	}
+
+	s := &Store{
+		Owner:   owner,
+		Repo:    repo,
+		Version: version,
+	}
+
+	m := update.Manager{
+		Command: command,
+	}
+
+	asset, err := s.LatestGitReleases()
+	if err != nil {
+		if strings.Contains(err.Error(), update.LatestVersionTips) {
+			result.LatestVersion = asset.LatestVersion
+			result.Status = 2
+			return result, nil
+		}
+		return nil, err
+	}
+
+	// download tarball to a tmp dir
+	tarball, err := asset.DownloadProxy(progress.Reader)
+	if err != nil {
+		return nil, fmt.Errorf("error downloading: %s", err)
+	}
+
+	// install it
+	if err := m.Install(tarball); err != nil {
+		return nil, fmt.Errorf("error installing: %s", err)
+	}
+
+	// gologger.Info().Msgf("Successfully updated to %s %s\n", command, s.Version)
+	result.LatestVersion = asset.LatestVersion
+	result.Status = 1
+	return result, nil
+}

--
Gitblit v1.8.0