mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-31 22:18:07 +08:00
feat: optimize the invocation of proxy servers (#7755)
This commit is contained in:
parent
0d15a28f93
commit
fcc3f8e216
@ -26,8 +26,7 @@ import (
|
|||||||
"github.com/1Panel-dev/1Panel/agent/utils/common"
|
"github.com/1Panel-dev/1Panel/agent/utils/common"
|
||||||
"github.com/1Panel-dev/1Panel/agent/utils/docker"
|
"github.com/1Panel-dev/1Panel/agent/utils/docker"
|
||||||
"github.com/1Panel-dev/1Panel/agent/utils/files"
|
"github.com/1Panel-dev/1Panel/agent/utils/files"
|
||||||
http2 "github.com/1Panel-dev/1Panel/agent/utils/http"
|
"github.com/1Panel-dev/1Panel/agent/utils/req_helper"
|
||||||
httpUtil "github.com/1Panel-dev/1Panel/agent/utils/http"
|
|
||||||
"github.com/1Panel-dev/1Panel/agent/utils/xpack"
|
"github.com/1Panel-dev/1Panel/agent/utils/xpack"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
@ -260,7 +259,7 @@ func (a AppService) GetAppDetail(appID uint, version, appType string) (response.
|
|||||||
if appDetailDTO.DockerCompose == "" {
|
if appDetailDTO.DockerCompose == "" {
|
||||||
filename := filepath.Base(appDetailDTO.DownloadUrl)
|
filename := filepath.Base(appDetailDTO.DownloadUrl)
|
||||||
dockerComposeUrl := fmt.Sprintf("%s%s", strings.TrimSuffix(appDetailDTO.DownloadUrl, filename), "docker-compose.yml")
|
dockerComposeUrl := fmt.Sprintf("%s%s", strings.TrimSuffix(appDetailDTO.DownloadUrl, filename), "docker-compose.yml")
|
||||||
statusCode, composeRes, err := httpUtil.HandleGet(dockerComposeUrl, http.MethodGet, constant.TimeOut20s)
|
statusCode, composeRes, err := req_helper.HandleRequest(dockerComposeUrl, http.MethodGet, constant.TimeOut20s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return appDetailDTO, buserr.WithDetail("ErrGetCompose", err.Error(), err)
|
return appDetailDTO, buserr.WithDetail("ErrGetCompose", err.Error(), err)
|
||||||
}
|
}
|
||||||
@ -773,7 +772,7 @@ func (a AppService) GetAppUpdate() (*response.AppUpdateRes, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
versionUrl := fmt.Sprintf("%s/%s/1panel.json.version.txt", global.CONF.System.AppRepo, global.CONF.System.Mode)
|
versionUrl := fmt.Sprintf("%s/%s/1panel.json.version.txt", global.CONF.System.AppRepo, global.CONF.System.Mode)
|
||||||
_, versionRes, err := http2.HandleGet(versionUrl, http.MethodGet, constant.TimeOut20s)
|
_, versionRes, err := req_helper.HandleRequest(versionUrl, http.MethodGet, constant.TimeOut20s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -936,7 +935,6 @@ func (a AppService) SyncAppListFromRemote(taskID string) (err error) {
|
|||||||
oldAppIds = append(oldAppIds, old.ID)
|
oldAppIds = append(oldAppIds, old.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
transport := xpack.LoadRequestTransport()
|
|
||||||
baseRemoteUrl := fmt.Sprintf("%s/%s/1panel", global.CONF.System.AppRepo, global.CONF.System.Mode)
|
baseRemoteUrl := fmt.Sprintf("%s/%s/1panel", global.CONF.System.AppRepo, global.CONF.System.Mode)
|
||||||
|
|
||||||
appsMap := getApps(oldApps, list.Apps, setting.SystemVersion, t)
|
appsMap := getApps(oldApps, list.Apps, setting.SystemVersion, t)
|
||||||
@ -944,7 +942,7 @@ func (a AppService) SyncAppListFromRemote(taskID string) (err error) {
|
|||||||
t.LogStart(i18n.GetMsgByKey("SyncAppDetail"))
|
t.LogStart(i18n.GetMsgByKey("SyncAppDetail"))
|
||||||
for _, l := range list.Apps {
|
for _, l := range list.Apps {
|
||||||
app := appsMap[l.AppProperty.Key]
|
app := appsMap[l.AppProperty.Key]
|
||||||
_, iconRes, err := httpUtil.HandleGetWithTransport(l.Icon, http.MethodGet, transport, constant.TimeOut20s)
|
_, iconRes, err := req_helper.HandleRequest(l.Icon, http.MethodGet, constant.TimeOut20s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -977,7 +975,7 @@ func (a AppService) SyncAppListFromRemote(taskID string) (err error) {
|
|||||||
}
|
}
|
||||||
if _, ok := InitTypes[app.Type]; ok {
|
if _, ok := InitTypes[app.Type]; ok {
|
||||||
dockerComposeUrl := fmt.Sprintf("%s/%s", versionUrl, "docker-compose.yml")
|
dockerComposeUrl := fmt.Sprintf("%s/%s", versionUrl, "docker-compose.yml")
|
||||||
_, composeRes, err := httpUtil.HandleGetWithTransport(dockerComposeUrl, http.MethodGet, transport, constant.TimeOut20s)
|
_, composeRes, err := req_helper.HandleRequest(dockerComposeUrl, http.MethodGet, constant.TimeOut20s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/agent/utils/files"
|
"github.com/1Panel-dev/1Panel/agent/utils/files"
|
||||||
httpUtil "github.com/1Panel-dev/1Panel/agent/utils/http"
|
"github.com/1Panel-dev/1Panel/agent/utils/req_helper"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
@ -553,7 +553,7 @@ func (a *AppInstallService) GetUpdateVersions(req request.AppUpdateVersion) ([]d
|
|||||||
if req.UpdateVersion != "" && req.UpdateVersion == detail.Version && detail.DockerCompose == "" && !app.IsLocalApp() {
|
if req.UpdateVersion != "" && req.UpdateVersion == detail.Version && detail.DockerCompose == "" && !app.IsLocalApp() {
|
||||||
filename := filepath.Base(detail.DownloadUrl)
|
filename := filepath.Base(detail.DownloadUrl)
|
||||||
dockerComposeUrl := fmt.Sprintf("%s%s", strings.TrimSuffix(detail.DownloadUrl, filename), "docker-compose.yml")
|
dockerComposeUrl := fmt.Sprintf("%s%s", strings.TrimSuffix(detail.DownloadUrl, filename), "docker-compose.yml")
|
||||||
statusCode, composeRes, err := httpUtil.HandleGet(dockerComposeUrl, http.MethodGet, constant.TimeOut20s)
|
statusCode, composeRes, err := req_helper.HandleRequest(dockerComposeUrl, http.MethodGet, constant.TimeOut20s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return versions, err
|
return versions, err
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ import (
|
|||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
|
|
||||||
httpUtil "github.com/1Panel-dev/1Panel/agent/utils/http"
|
"github.com/1Panel-dev/1Panel/agent/utils/req_helper"
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/agent/utils/cmd"
|
"github.com/1Panel-dev/1Panel/agent/utils/cmd"
|
||||||
@ -1758,5 +1758,5 @@ func RequestDownloadCallBack(downloadCallBackUrl string) {
|
|||||||
if downloadCallBackUrl == "" {
|
if downloadCallBackUrl == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, _, _ = httpUtil.HandleGet(downloadCallBackUrl, http.MethodGet, constant.TimeOut5s)
|
_, _, _ = req_helper.HandleRequest(downloadCallBackUrl, http.MethodGet, constant.TimeOut5s)
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"fmt"
|
"fmt"
|
||||||
http2 "github.com/1Panel-dev/1Panel/agent/utils/http"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@ -25,6 +24,7 @@ import (
|
|||||||
"github.com/1Panel-dev/1Panel/agent/utils/cmd"
|
"github.com/1Panel-dev/1Panel/agent/utils/cmd"
|
||||||
"github.com/1Panel-dev/1Panel/agent/utils/common"
|
"github.com/1Panel-dev/1Panel/agent/utils/common"
|
||||||
"github.com/1Panel-dev/1Panel/agent/utils/files"
|
"github.com/1Panel-dev/1Panel/agent/utils/files"
|
||||||
|
"github.com/1Panel-dev/1Panel/agent/utils/req_helper"
|
||||||
"github.com/1Panel-dev/1Panel/agent/utils/ssl"
|
"github.com/1Panel-dev/1Panel/agent/utils/ssl"
|
||||||
"github.com/go-acme/lego/v4/certcrypto"
|
"github.com/go-acme/lego/v4/certcrypto"
|
||||||
legoLogger "github.com/go-acme/lego/v4/log"
|
legoLogger "github.com/go-acme/lego/v4/log"
|
||||||
@ -205,7 +205,7 @@ func reloadSystemSSL(websiteSSL *model.WebsiteSSL, logger *log.Logger) {
|
|||||||
logger.Printf("Failed to update the SSL certificate for 1Panel System domain [%s] , err:%s", websiteSSL.PrimaryDomain, err.Error())
|
logger.Printf("Failed to update the SSL certificate for 1Panel System domain [%s] , err:%s", websiteSSL.PrimaryDomain, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := http2.PostLocalCore("/core/settings/ssl/reload"); err != nil {
|
if err := req_helper.PostLocalCore("/core/settings/ssl/reload"); err != nil {
|
||||||
logger.Printf("Failed to update the SSL certificate for 1Panel System domain [%s] , err:%s", websiteSSL.PrimaryDomain, err.Error())
|
logger.Printf("Failed to update the SSL certificate for 1Panel System domain [%s] , err:%s", websiteSSL.PrimaryDomain, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/agent/constant"
|
"github.com/1Panel-dev/1Panel/agent/constant"
|
||||||
"github.com/1Panel-dev/1Panel/agent/utils/cmd"
|
"github.com/1Panel-dev/1Panel/agent/utils/cmd"
|
||||||
http2 "github.com/1Panel-dev/1Panel/agent/utils/http"
|
"github.com/1Panel-dev/1Panel/agent/utils/req_helper"
|
||||||
cZip "github.com/klauspost/compress/zip"
|
cZip "github.com/klauspost/compress/zip"
|
||||||
"golang.org/x/text/encoding/simplifiedchinese"
|
"golang.org/x/text/encoding/simplifiedchinese"
|
||||||
"golang.org/x/text/transform"
|
"golang.org/x/text/transform"
|
||||||
@ -315,7 +315,7 @@ func (f FileOp) DownloadFileWithProcess(url, dst, key string, ignoreCertificate
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f FileOp) DownloadFile(url, dst string) error {
|
func (f FileOp) DownloadFile(url, dst string) error {
|
||||||
resp, err := http2.GetHttpRes(url)
|
resp, err := req_helper.HandleGet(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -334,7 +334,7 @@ func (f FileOp) DownloadFile(url, dst string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f FileOp) DownloadFileWithProxy(url, dst string) error {
|
func (f FileOp) DownloadFileWithProxy(url, dst string) error {
|
||||||
_, resp, err := http2.HandleGet(url, http.MethodGet, constant.TimeOut5m)
|
_, resp, err := req_helper.HandleRequest(url, http.MethodGet, constant.TimeOut5m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1,42 +0,0 @@
|
|||||||
package http
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/agent/buserr"
|
|
||||||
"github.com/1Panel-dev/1Panel/agent/utils/xpack"
|
|
||||||
)
|
|
||||||
|
|
||||||
func GetHttpRes(url string) (*http.Response, error) {
|
|
||||||
client := &http.Client{
|
|
||||||
Timeout: time.Second * 300,
|
|
||||||
}
|
|
||||||
transport := xpack.LoadRequestTransport()
|
|
||||||
client.Transport = transport
|
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(context.Background(), "GET", url, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, buserr.WithMap("ErrCreateHttpClient", map[string]interface{}{"err": err.Error()}, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, context.DeadlineExceeded) {
|
|
||||||
return nil, buserr.WithMap("ErrHttpReqTimeOut", map[string]interface{}{"err": err.Error()}, err)
|
|
||||||
} else {
|
|
||||||
if strings.Contains(err.Error(), "no such host") {
|
|
||||||
return nil, buserr.New("ErrNoSuchHost")
|
|
||||||
}
|
|
||||||
return nil, buserr.WithMap("ErrHttpReqFailed", map[string]interface{}{"err": err.Error()}, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if resp.StatusCode == 404 {
|
|
||||||
return nil, buserr.New("ErrHttpReqNotFound")
|
|
||||||
}
|
|
||||||
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
package http
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/agent/global"
|
|
||||||
"github.com/1Panel-dev/1Panel/agent/utils/xpack"
|
|
||||||
)
|
|
||||||
|
|
||||||
func HandleGet(url, method string, timeout int) (int, []byte, error) {
|
|
||||||
transport := xpack.LoadRequestTransport()
|
|
||||||
return HandleGetWithTransport(url, method, transport, timeout)
|
|
||||||
}
|
|
||||||
|
|
||||||
func HandleGetWithTransport(url, method string, transport *http.Transport, timeout int) (int, []byte, error) {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
global.LOG.Errorf("handle request failed, error message: %v", r)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
client := http.Client{Timeout: time.Duration(timeout) * time.Second, Transport: transport}
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second)
|
|
||||||
defer cancel()
|
|
||||||
request, err := http.NewRequestWithContext(ctx, method, url, nil)
|
|
||||||
if err != nil {
|
|
||||||
return 0, nil, err
|
|
||||||
}
|
|
||||||
request.Header.Set("Content-Type", "application/json")
|
|
||||||
resp, err := client.Do(request)
|
|
||||||
if err != nil {
|
|
||||||
return 0, nil, err
|
|
||||||
}
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
return 0, nil, errors.New(resp.Status)
|
|
||||||
}
|
|
||||||
body, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return 0, nil, err
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
return resp.StatusCode, body, nil
|
|
||||||
}
|
|
@ -1,10 +1,11 @@
|
|||||||
package http
|
package req_helper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/1Panel-dev/1Panel/agent/app/repo"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/1Panel-dev/1Panel/agent/app/repo"
|
||||||
)
|
)
|
||||||
|
|
||||||
func PostLocalCore(url string) error {
|
func PostLocalCore(url string) error {
|
90
agent/utils/req_helper/request.go
Normal file
90
agent/utils/req_helper/request.go
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
package req_helper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/tls"
|
||||||
|
"errors"
|
||||||
|
"io"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/1Panel-dev/1Panel/agent/buserr"
|
||||||
|
"github.com/1Panel-dev/1Panel/agent/global"
|
||||||
|
)
|
||||||
|
|
||||||
|
func HandleGet(url string) (*http.Response, error) {
|
||||||
|
client := &http.Client{
|
||||||
|
Timeout: time.Second * 300,
|
||||||
|
}
|
||||||
|
client.Transport = loadRequestTransport()
|
||||||
|
|
||||||
|
req, err := http.NewRequestWithContext(context.Background(), "GET", url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, buserr.WithMap("ErrCreateHttpClient", map[string]interface{}{"err": err.Error()}, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, context.DeadlineExceeded) {
|
||||||
|
return nil, buserr.WithMap("ErrHttpReqTimeOut", map[string]interface{}{"err": err.Error()}, err)
|
||||||
|
} else {
|
||||||
|
if strings.Contains(err.Error(), "no such host") {
|
||||||
|
return nil, buserr.New("ErrNoSuchHost")
|
||||||
|
}
|
||||||
|
return nil, buserr.WithMap("ErrHttpReqFailed", map[string]interface{}{"err": err.Error()}, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if resp.StatusCode == 404 {
|
||||||
|
return nil, buserr.New("ErrHttpReqNotFound")
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func HandleRequest(url, method string, timeout int) (int, []byte, error) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
global.LOG.Errorf("handle request failed, error message: %v", r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
transport := loadRequestTransport()
|
||||||
|
client := http.Client{Timeout: time.Duration(timeout) * time.Second, Transport: transport}
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
request, err := http.NewRequestWithContext(ctx, method, url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return 0, nil, err
|
||||||
|
}
|
||||||
|
request.Header.Set("Content-Type", "application/json")
|
||||||
|
resp, err := client.Do(request)
|
||||||
|
if err != nil {
|
||||||
|
return 0, nil, err
|
||||||
|
}
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return 0, nil, errors.New(resp.Status)
|
||||||
|
}
|
||||||
|
body, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return 0, nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
return resp.StatusCode, body, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadRequestTransport() *http.Transport {
|
||||||
|
return &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||||
|
DialContext: (&net.Dialer{
|
||||||
|
Timeout: 60 * time.Second,
|
||||||
|
KeepAlive: 60 * time.Second,
|
||||||
|
}).DialContext,
|
||||||
|
TLSHandshakeTimeout: 5 * time.Second,
|
||||||
|
ResponseHeaderTimeout: 10 * time.Second,
|
||||||
|
IdleConnTimeout: 15 * time.Second,
|
||||||
|
}
|
||||||
|
}
|
@ -3,12 +3,8 @@
|
|||||||
package xpack
|
package xpack
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/agent/app/dto"
|
"github.com/1Panel-dev/1Panel/agent/app/dto"
|
||||||
"github.com/1Panel-dev/1Panel/agent/app/model"
|
"github.com/1Panel-dev/1Panel/agent/app/model"
|
||||||
@ -19,19 +15,6 @@ import (
|
|||||||
|
|
||||||
func RemoveTamper(website string) {}
|
func RemoveTamper(website string) {}
|
||||||
|
|
||||||
func LoadRequestTransport() *http.Transport {
|
|
||||||
return &http.Transport{
|
|
||||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
|
||||||
DialContext: (&net.Dialer{
|
|
||||||
Timeout: 60 * time.Second,
|
|
||||||
KeepAlive: 60 * time.Second,
|
|
||||||
}).DialContext,
|
|
||||||
TLSHandshakeTimeout: 5 * time.Second,
|
|
||||||
ResponseHeaderTimeout: 10 * time.Second,
|
|
||||||
IdleConnTimeout: 15 * time.Second,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func LoadGpuInfo() []interface{} {
|
func LoadGpuInfo() []interface{} {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
"github.com/1Panel-dev/1Panel/core/utils/cloud_storage"
|
"github.com/1Panel-dev/1Panel/core/utils/cloud_storage"
|
||||||
"github.com/1Panel-dev/1Panel/core/utils/cloud_storage/client"
|
"github.com/1Panel-dev/1Panel/core/utils/cloud_storage/client"
|
||||||
"github.com/1Panel-dev/1Panel/core/utils/encrypt"
|
"github.com/1Panel-dev/1Panel/core/utils/encrypt"
|
||||||
httpUtils "github.com/1Panel-dev/1Panel/core/utils/http"
|
"github.com/1Panel-dev/1Panel/core/utils/req_helper"
|
||||||
"github.com/1Panel-dev/1Panel/core/utils/xpack"
|
"github.com/1Panel-dev/1Panel/core/utils/xpack"
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -168,7 +168,7 @@ func (u *BackupService) Delete(id uint) error {
|
|||||||
if backup.Type == constant.Local {
|
if backup.Type == constant.Local {
|
||||||
return buserr.New(constant.ErrBackupLocal)
|
return buserr.New(constant.ErrBackupLocal)
|
||||||
}
|
}
|
||||||
if _, err := httpUtils.NewLocalClient(fmt.Sprintf("/api/v2/backups/check/%v", id), http.MethodGet, nil); err != nil {
|
if _, err := req_helper.NewLocalClient(fmt.Sprintf("/api/v2/backups/check/%v", id), http.MethodGet, nil); err != nil {
|
||||||
global.LOG.Errorf("check used of local cronjob failed, err: %v", err)
|
global.LOG.Errorf("check used of local cronjob failed, err: %v", err)
|
||||||
return buserr.New(constant.ErrBackupInUsed)
|
return buserr.New(constant.ErrBackupInUsed)
|
||||||
}
|
}
|
||||||
@ -370,5 +370,5 @@ func syncAccountToAgent(backup model.BackupAccount, operation string) {
|
|||||||
itemJson := dto.SyncToAgent{Name: backup.Name, Operation: operation, Data: string(itemData)}
|
itemJson := dto.SyncToAgent{Name: backup.Name, Operation: operation, Data: string(itemData)}
|
||||||
bodyItem, _ := json.Marshal(itemJson)
|
bodyItem, _ := json.Marshal(itemJson)
|
||||||
_ = xpack.RequestToAllAgent("/api/v2/backups/sync", http.MethodPost, bytes.NewReader((bodyItem)))
|
_ = xpack.RequestToAllAgent("/api/v2/backups/sync", http.MethodPost, bytes.NewReader((bodyItem)))
|
||||||
_, _ = httpUtils.NewLocalClient("/api/v2/backups/sync", http.MethodPost, bytes.NewReader((bodyItem)))
|
_, _ = req_helper.NewLocalClient("/api/v2/backups/sync", http.MethodPost, bytes.NewReader((bodyItem)))
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
"github.com/1Panel-dev/1Panel/core/buserr"
|
"github.com/1Panel-dev/1Panel/core/buserr"
|
||||||
"github.com/1Panel-dev/1Panel/core/constant"
|
"github.com/1Panel-dev/1Panel/core/constant"
|
||||||
"github.com/1Panel-dev/1Panel/core/global"
|
"github.com/1Panel-dev/1Panel/core/global"
|
||||||
httpUtils "github.com/1Panel-dev/1Panel/core/utils/http"
|
"github.com/1Panel-dev/1Panel/core/utils/req_helper"
|
||||||
"github.com/1Panel-dev/1Panel/core/utils/xpack"
|
"github.com/1Panel-dev/1Panel/core/utils/xpack"
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -92,7 +92,7 @@ func (u *GroupService) Delete(id uint) error {
|
|||||||
err = xpack.UpdateGroup("node", id, defaultGroup.ID)
|
err = xpack.UpdateGroup("node", id, defaultGroup.ID)
|
||||||
case "website":
|
case "website":
|
||||||
bodyItem := []byte(fmt.Sprintf(`{"Group":%v, "NewGroup":%v}`, id, defaultGroup.ID))
|
bodyItem := []byte(fmt.Sprintf(`{"Group":%v, "NewGroup":%v}`, id, defaultGroup.ID))
|
||||||
if _, err := httpUtils.NewLocalClient("/api/v2/websites/group/change", http.MethodPost, bytes.NewReader(bodyItem)); err != nil {
|
if _, err := req_helper.NewLocalClient("/api/v2/websites/group/change", http.MethodPost, bytes.NewReader(bodyItem)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := xpack.UpdateGroup("node", id, defaultGroup.ID); err != nil {
|
if err := xpack.UpdateGroup("node", id, defaultGroup.ID); err != nil {
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
"github.com/1Panel-dev/1Panel/core/utils/cmd"
|
"github.com/1Panel-dev/1Panel/core/utils/cmd"
|
||||||
"github.com/1Panel-dev/1Panel/core/utils/common"
|
"github.com/1Panel-dev/1Panel/core/utils/common"
|
||||||
"github.com/1Panel-dev/1Panel/core/utils/files"
|
"github.com/1Panel-dev/1Panel/core/utils/files"
|
||||||
httpUtil "github.com/1Panel-dev/1Panel/core/utils/http"
|
"github.com/1Panel-dev/1Panel/core/utils/req_helper"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UpgradeService struct{}
|
type UpgradeService struct{}
|
||||||
@ -264,7 +264,7 @@ func (u *UpgradeService) loadVersion(isLatest bool, currentVersion, mode string)
|
|||||||
if !isLatest {
|
if !isLatest {
|
||||||
path = fmt.Sprintf("%s/%s/latest.current", global.CONF.System.RepoUrl, mode)
|
path = fmt.Sprintf("%s/%s/latest.current", global.CONF.System.RepoUrl, mode)
|
||||||
}
|
}
|
||||||
_, latestVersionRes, err := httpUtil.HandleGet(path, http.MethodGet, constant.TimeOut20s)
|
_, latestVersionRes, err := req_helper.HandleRequestWithProxy(path, http.MethodGet, constant.TimeOut20s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
global.LOG.Errorf("load latest version from oss failed, err: %v", err)
|
global.LOG.Errorf("load latest version from oss failed, err: %v", err)
|
||||||
return ""
|
return ""
|
||||||
@ -325,7 +325,7 @@ func (u *UpgradeService) checkVersion(v2, v1 string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *UpgradeService) loadReleaseNotes(path string) (string, error) {
|
func (u *UpgradeService) loadReleaseNotes(path string) (string, error) {
|
||||||
_, releaseNotes, err := httpUtil.HandleGet(path, http.MethodGet, constant.TimeOut20s)
|
_, releaseNotes, err := req_helper.HandleRequestWithProxy(path, http.MethodGet, constant.TimeOut20s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ system:
|
|||||||
repo_url: https://resource.fit2cloud.com/1panel/package
|
repo_url: https://resource.fit2cloud.com/1panel/package
|
||||||
app_repo: https://apps-assets.fit2cloud.com
|
app_repo: https://apps-assets.fit2cloud.com
|
||||||
is_demo: false
|
is_demo: false
|
||||||
is_intl: true
|
is_intl: false
|
||||||
port: 9999
|
port: 9999
|
||||||
username: admin
|
username: admin
|
||||||
password: admin123
|
password: admin123
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
"github.com/1Panel-dev/1Panel/core/constant"
|
"github.com/1Panel-dev/1Panel/core/constant"
|
||||||
"github.com/1Panel-dev/1Panel/core/global"
|
"github.com/1Panel-dev/1Panel/core/global"
|
||||||
"github.com/1Panel-dev/1Panel/core/utils/cmd"
|
"github.com/1Panel-dev/1Panel/core/utils/cmd"
|
||||||
httpUtil "github.com/1Panel-dev/1Panel/core/utils/http"
|
"github.com/1Panel-dev/1Panel/core/utils/req_helper"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CopyFile(src, dst string, withName bool) error {
|
func CopyFile(src, dst string, withName bool) error {
|
||||||
@ -146,7 +146,7 @@ func HandleUnTar(sourceFile, targetDir string, secret string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func DownloadFile(url, dst string) error {
|
func DownloadFile(url, dst string) error {
|
||||||
resp, err := httpUtil.GetHttpRes(url)
|
resp, err := req_helper.HandleGet(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -165,7 +165,7 @@ func DownloadFile(url, dst string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func DownloadFileWithProxy(url, dst string) error {
|
func DownloadFileWithProxy(url, dst string) error {
|
||||||
_, resp, err := httpUtil.HandleGet(url, http.MethodGet, constant.TimeOut5m)
|
_, resp, err := req_helper.HandleRequestWithProxy(url, http.MethodGet, constant.TimeOut5m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package http
|
package req_helper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -12,9 +12,10 @@ import (
|
|||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/core/buserr"
|
"github.com/1Panel-dev/1Panel/core/buserr"
|
||||||
"github.com/1Panel-dev/1Panel/core/global"
|
"github.com/1Panel-dev/1Panel/core/global"
|
||||||
|
"github.com/1Panel-dev/1Panel/core/utils/xpack"
|
||||||
)
|
)
|
||||||
|
|
||||||
func HandleGet(url, method string, timeout int) (int, []byte, error) {
|
func HandleRequest(url, method string, timeout int) (int, []byte, error) {
|
||||||
transport := &http.Transport{
|
transport := &http.Transport{
|
||||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||||
DialContext: (&net.Dialer{
|
DialContext: (&net.Dialer{
|
||||||
@ -25,10 +26,15 @@ func HandleGet(url, method string, timeout int) (int, []byte, error) {
|
|||||||
ResponseHeaderTimeout: 10 * time.Second,
|
ResponseHeaderTimeout: 10 * time.Second,
|
||||||
IdleConnTimeout: 15 * time.Second,
|
IdleConnTimeout: 15 * time.Second,
|
||||||
}
|
}
|
||||||
return HandleGetWithTransport(url, method, transport, timeout)
|
return handleRequestWithTransport(url, method, transport, timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleGetWithTransport(url, method string, transport *http.Transport, timeout int) (int, []byte, error) {
|
func HandleRequestWithProxy(url, method string, timeout int) (int, []byte, error) {
|
||||||
|
transport := xpack.LoadRequestTransport()
|
||||||
|
return handleRequestWithTransport(url, method, transport, timeout)
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleRequestWithTransport(url, method string, transport *http.Transport, timeout int) (int, []byte, error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
global.LOG.Errorf("handle request failed, error message: %v", r)
|
global.LOG.Errorf("handle request failed, error message: %v", r)
|
||||||
@ -57,10 +63,7 @@ func HandleGetWithTransport(url, method string, transport *http.Transport, timeo
|
|||||||
return resp.StatusCode, body, nil
|
return resp.StatusCode, body, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetHttpRes(url string) (*http.Response, error) {
|
func HandleGet(url string) (*http.Response, error) {
|
||||||
client := &http.Client{
|
|
||||||
Timeout: time.Second * 300,
|
|
||||||
}
|
|
||||||
transport := &http.Transport{
|
transport := &http.Transport{
|
||||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||||
DialContext: (&net.Dialer{
|
DialContext: (&net.Dialer{
|
||||||
@ -71,6 +74,18 @@ func GetHttpRes(url string) (*http.Response, error) {
|
|||||||
ResponseHeaderTimeout: 10 * time.Second,
|
ResponseHeaderTimeout: 10 * time.Second,
|
||||||
IdleConnTimeout: 15 * time.Second,
|
IdleConnTimeout: 15 * time.Second,
|
||||||
}
|
}
|
||||||
|
return handleGetWithTransport(url, transport)
|
||||||
|
}
|
||||||
|
|
||||||
|
func HandleGetWithProxy(url string) (*http.Response, error) {
|
||||||
|
transport := xpack.LoadRequestTransport()
|
||||||
|
return handleGetWithTransport(url, transport)
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleGetWithTransport(url string, transport *http.Transport) (*http.Response, error) {
|
||||||
|
client := &http.Client{
|
||||||
|
Timeout: time.Second * 300,
|
||||||
|
}
|
||||||
client.Transport = transport
|
client.Transport = transport
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(context.Background(), "GET", url, nil)
|
req, err := http.NewRequestWithContext(context.Background(), "GET", url, nil)
|
@ -1,4 +1,4 @@
|
|||||||
package http
|
package req_helper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
@ -3,7 +3,11 @@
|
|||||||
package xpack
|
package xpack
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/tls"
|
||||||
"io"
|
"io"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
@ -15,3 +19,16 @@ func UpdateGroup(name string, group, newGroup uint) error { return nil }
|
|||||||
func CheckBackupUsed(id uint) error { return nil }
|
func CheckBackupUsed(id uint) error { return nil }
|
||||||
|
|
||||||
func RequestToAllAgent(reqUrl, reqMethod string, reqBody io.Reader) error { return nil }
|
func RequestToAllAgent(reqUrl, reqMethod string, reqBody io.Reader) error { return nil }
|
||||||
|
|
||||||
|
func LoadRequestTransport() *http.Transport {
|
||||||
|
return &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||||
|
DialContext: (&net.Dialer{
|
||||||
|
Timeout: 60 * time.Second,
|
||||||
|
KeepAlive: 60 * time.Second,
|
||||||
|
}).DialContext,
|
||||||
|
TLSHandshakeTimeout: 5 * time.Second,
|
||||||
|
ResponseHeaderTimeout: 10 * time.Second,
|
||||||
|
IdleConnTimeout: 15 * time.Second,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@codemirror/lang-json": "^6.0.1",
|
"@codemirror/lang-json": "^6.0.1",
|
||||||
|
"@codemirror/lang-html": "^6.4.9",
|
||||||
|
"@codemirror/lang-php": "^6.0.1",
|
||||||
"@codemirror/language": "^6.10.2",
|
"@codemirror/language": "^6.10.2",
|
||||||
"@codemirror/legacy-modes": "^6.4.0",
|
"@codemirror/legacy-modes": "^6.4.0",
|
||||||
"@codemirror/theme-one-dark": "^6.1.2",
|
"@codemirror/theme-one-dark": "^6.1.2",
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
<PrimaryMenu />
|
<PrimaryMenu />
|
||||||
</div>
|
</div>
|
||||||
<Logo :isCollapse="isCollapse" />
|
<Logo :isCollapse="isCollapse" />
|
||||||
<div class="el-dropdown-link flex justify-between items-center">
|
<div class="el-dropdown-link flex justify-between items-center background">
|
||||||
<el-button link class="ml-4" @click="openChangeNode" @mouseenter="openChangeNode">
|
<el-button link class="ml-4" @click="openChangeNode" @mouseenter="openChangeNode">
|
||||||
{{ loadCurrentName() }}
|
{{ loadCurrentName() }}
|
||||||
</el-button>
|
</el-button>
|
||||||
@ -226,6 +226,7 @@ const search = async () => {
|
|||||||
await checkIsSystemIntl();
|
await checkIsSystemIntl();
|
||||||
let checkedLabels: any[] = [];
|
let checkedLabels: any[] = [];
|
||||||
const res = await getSettingInfo();
|
const res = await getSettingInfo();
|
||||||
|
version.value = res.data.systemVersion;
|
||||||
const json: Node = JSON.parse(res.data.xpackHideMenu);
|
const json: Node = JSON.parse(res.data.xpackHideMenu);
|
||||||
checkedLabels = getCheckedLabels(json);
|
checkedLabels = getCheckedLabels(json);
|
||||||
|
|
||||||
@ -300,6 +301,10 @@ onMounted(() => {
|
|||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
@use 'index';
|
@use 'index';
|
||||||
|
|
||||||
|
.background {
|
||||||
|
z-index: 20;
|
||||||
|
}
|
||||||
|
|
||||||
.custom-menu .el-menu-item {
|
.custom-menu .el-menu-item {
|
||||||
white-space: normal !important;
|
white-space: normal !important;
|
||||||
word-break: break-word;
|
word-break: break-word;
|
||||||
|
@ -475,6 +475,7 @@ const onSave = async (key: string, val: any) => {
|
|||||||
}
|
}
|
||||||
MsgSuccess(i18n.t('commons.msg.operationSuccess'));
|
MsgSuccess(i18n.t('commons.msg.operationSuccess'));
|
||||||
search();
|
search();
|
||||||
|
loading.value = false;
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
|
@ -217,7 +217,6 @@ const onSubmit = async () => {
|
|||||||
proxyUrl = '';
|
proxyUrl = '';
|
||||||
}
|
}
|
||||||
await updateXpackSettingByKey('ProxyDocker', proxyUrl);
|
await updateXpackSettingByKey('ProxyDocker', proxyUrl);
|
||||||
await updateDaemonJson(`${form.proxyType}-proxy`, proxyUrl);
|
|
||||||
emit('search');
|
emit('search');
|
||||||
handleClose();
|
handleClose();
|
||||||
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
|
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user