mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 10:25:52 +02:00
feat(ota): add dev channel
This commit is contained in:
parent
6a832937e3
commit
38f4b55fcf
4 changed files with 105 additions and 3 deletions
77
internal/version/dev_build.go
Normal file
77
internal/version/dev_build.go
Normal file
|
@ -0,0 +1,77 @@
|
|||
package version
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
GithubDevCommitAPI = "https://api.github.com/repos/0xJacky/nginx-ui/commits/dev?per_page=1"
|
||||
CloudflareWorkerAPI = "https://nginx-ui-proxy.langgood.com"
|
||||
)
|
||||
|
||||
type TCommit struct {
|
||||
SHA string `json:"sha"`
|
||||
Commit struct {
|
||||
Message string `json:"message"`
|
||||
Committer struct {
|
||||
Date time.Time `json:"date"`
|
||||
} `json:"committer"`
|
||||
} `json:"commit"`
|
||||
}
|
||||
|
||||
func getDevBuild() (data TRelease, err error) {
|
||||
resp, err := http.Get(GithubDevCommitAPI)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
commit := TCommit{}
|
||||
err = json.Unmarshal(body, &commit)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if len(commit.SHA) < 7 {
|
||||
err = errors.New("invalid commit SHA")
|
||||
return
|
||||
}
|
||||
shortSHA := commit.SHA[:7]
|
||||
|
||||
resp, err = http.Get(fmt.Sprintf("%s/dev-builds/%s", CloudflareWorkerAPI, shortSHA))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
body, err = io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
assets := []TReleaseAsset{}
|
||||
err = json.Unmarshal(body, &assets)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
data = TRelease{
|
||||
TagName: "sha-" + shortSHA,
|
||||
Name: shortSHA,
|
||||
Body: commit.Commit.Message,
|
||||
Type: ReleaseTypeDev,
|
||||
PublishedAt: commit.Commit.Committer.Date,
|
||||
Assets: assets,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue