mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-10-07 10:16:38 +08:00
Merge pull request #85 from Sagit-chu/opencode/lucky-otter
fix: use direct GitHub API for release queries instead of proxy
This commit is contained in:
@@ -413,7 +413,7 @@ func (h *Handler) nodeInstall(w http.ResponseWriter, r *http.Request) {
|
|||||||
response.WriteJSON(w, response.Err(-2, err.Error()))
|
response.WriteJSON(w, response.Err(-2, err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cmd := fmt.Sprintf("curl -L https://gcode.hostcentral.cc/https://github.com/Sagit-chu/flux-panel/releases/latest/download/install.sh -o ./install.sh && chmod +x ./install.sh && ./install.sh -a %s -s %s", processServerAddress(panelAddr), secret)
|
cmd := fmt.Sprintf("curl -L https://gcode.hostcentral.cc/https://github.com/Sagit-chu/flvx/releases/latest/download/install.sh -o ./install.sh && chmod +x ./install.sh && ./install.sh -a %s -s %s", processServerAddress(panelAddr), secret)
|
||||||
response.WriteJSON(w, response.OK(cmd))
|
response.WriteJSON(w, response.OK(cmd))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package handler
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -10,6 +11,13 @@ import (
|
|||||||
"go-backend/internal/http/response"
|
"go-backend/internal/http/response"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
githubRepo = "Sagit-chu/flvx"
|
||||||
|
githubProxy = "https://gcode.hostcentral.cc"
|
||||||
|
githubAPIBase = "https://api.github.com"
|
||||||
|
githubHTMLBase = "https://github.com"
|
||||||
|
)
|
||||||
|
|
||||||
func (h *Handler) nodeUpgrade(w http.ResponseWriter, r *http.Request) {
|
func (h *Handler) nodeUpgrade(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method != http.MethodPost {
|
if r.Method != http.MethodPost {
|
||||||
response.WriteJSON(w, response.ErrDefault("请求失败"))
|
response.WriteJSON(w, response.ErrDefault("请求失败"))
|
||||||
@@ -40,12 +48,12 @@ func (h *Handler) nodeUpgrade(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
downloadURL := fmt.Sprintf(
|
downloadURL := fmt.Sprintf(
|
||||||
"https://gcode.hostcentral.cc/https://github.com/Sagit-chu/flux-panel/releases/download/%s/gost-{ARCH}",
|
githubProxy+"/%s/%s/releases/download/%s/gost-{ARCH}",
|
||||||
version,
|
githubHTMLBase, githubRepo, version,
|
||||||
)
|
)
|
||||||
checksumURL := fmt.Sprintf(
|
checksumURL := fmt.Sprintf(
|
||||||
"https://gcode.hostcentral.cc/https://github.com/Sagit-chu/flux-panel/releases/download/%s/gost-{ARCH}.sha256",
|
githubProxy+"/%s/%s/releases/download/%s/gost-{ARCH}.sha256",
|
||||||
version,
|
githubHTMLBase, githubRepo, version,
|
||||||
)
|
)
|
||||||
|
|
||||||
result, err := h.wsServer.SendCommand(req.ID, "UpgradeAgent", map[string]interface{}{
|
result, err := h.wsServer.SendCommand(req.ID, "UpgradeAgent", map[string]interface{}{
|
||||||
@@ -71,7 +79,7 @@ func resolveLatestRelease() (string, error) {
|
|||||||
Timeout: 10 * time.Second,
|
Timeout: 10 * time.Second,
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := client.Get("https://gcode.hostcentral.cc/https://github.com/Sagit-chu/flux-panel/releases/latest")
|
resp, err := client.Get(githubProxy + "/" + githubHTMLBase + "/" + githubRepo + "/releases/latest")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("请求GitHub失败: %v", err)
|
return "", fmt.Errorf("请求GitHub失败: %v", err)
|
||||||
}
|
}
|
||||||
@@ -97,12 +105,17 @@ func resolveLatestRelease() (string, error) {
|
|||||||
|
|
||||||
func resolveLatestReleaseAPI() (string, error) {
|
func resolveLatestReleaseAPI() (string, error) {
|
||||||
client := &http.Client{Timeout: 10 * time.Second}
|
client := &http.Client{Timeout: 10 * time.Second}
|
||||||
resp, err := client.Get("https://gcode.hostcentral.cc/https://api.github.com/repos/Sagit-chu/flux-panel/releases/latest")
|
resp, err := client.Get(githubAPIBase + "/repos/" + githubRepo + "/releases/latest")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("请求GitHub API失败: %v", err)
|
return "", fmt.Errorf("请求GitHub API失败: %v", err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
body, _ := io.ReadAll(io.LimitReader(resp.Body, 512))
|
||||||
|
return "", fmt.Errorf("GitHub API返回 %d: %s", resp.StatusCode, string(body))
|
||||||
|
}
|
||||||
|
|
||||||
var release struct {
|
var release struct {
|
||||||
TagName string `json:"tag_name"`
|
TagName string `json:"tag_name"`
|
||||||
}
|
}
|
||||||
@@ -146,12 +159,12 @@ func (h *Handler) nodeBatchUpgrade(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
downloadURL := fmt.Sprintf(
|
downloadURL := fmt.Sprintf(
|
||||||
"https://gcode.hostcentral.cc/https://github.com/Sagit-chu/flux-panel/releases/download/%s/gost-{ARCH}",
|
githubProxy+"/%s/%s/releases/download/%s/gost-{ARCH}",
|
||||||
version,
|
githubHTMLBase, githubRepo, version,
|
||||||
)
|
)
|
||||||
checksumURL := fmt.Sprintf(
|
checksumURL := fmt.Sprintf(
|
||||||
"https://gcode.hostcentral.cc/https://github.com/Sagit-chu/flux-panel/releases/download/%s/gost-{ARCH}.sha256",
|
githubProxy+"/%s/%s/releases/download/%s/gost-{ARCH}.sha256",
|
||||||
version,
|
githubHTMLBase, githubRepo, version,
|
||||||
)
|
)
|
||||||
|
|
||||||
type upgradeResult struct {
|
type upgradeResult struct {
|
||||||
@@ -186,13 +199,19 @@ func (h *Handler) listReleases(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
client := &http.Client{Timeout: 15 * time.Second}
|
client := &http.Client{Timeout: 15 * time.Second}
|
||||||
resp, err := client.Get("https://gcode.hostcentral.cc/https://api.github.com/repos/Sagit-chu/flux-panel/releases?per_page=20")
|
resp, err := client.Get(githubAPIBase + "/repos/" + githubRepo + "/releases?per_page=20")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.WriteJSON(w, response.Err(-2, fmt.Sprintf("获取版本列表失败: %v", err)))
|
response.WriteJSON(w, response.Err(-2, fmt.Sprintf("获取版本列表失败: %v", err)))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
body, _ := io.ReadAll(io.LimitReader(resp.Body, 512))
|
||||||
|
response.WriteJSON(w, response.Err(-2, fmt.Sprintf("获取版本列表失败: GitHub API返回 %d: %s", resp.StatusCode, string(body))))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var releases []struct {
|
var releases []struct {
|
||||||
TagName string `json:"tag_name"`
|
TagName string `json:"tag_name"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|||||||
Reference in New Issue
Block a user