mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-18 22:22:59 +08:00
fix: 解决 HTTP 类型代理失败的问题 (#5306)
This commit is contained in:
parent
97e800ee15
commit
d83402b819
@ -5,7 +5,6 @@ import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -27,6 +26,7 @@ import (
|
||||
"github.com/1Panel-dev/1Panel/backend/utils/files"
|
||||
http2 "github.com/1Panel-dev/1Panel/backend/utils/http"
|
||||
httpUtil "github.com/1Panel-dev/1Panel/backend/utils/http"
|
||||
"github.com/1Panel-dev/1Panel/backend/utils/xpack"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
@ -710,16 +710,11 @@ func (a AppService) GetAppUpdate() (*response.AppUpdateRes, error) {
|
||||
}
|
||||
|
||||
versionUrl := fmt.Sprintf("%s/%s/1panel.json.version.txt", global.CONF.System.AppRepo, global.CONF.System.Mode)
|
||||
versionRes, err := http2.GetHttpRes(versionUrl)
|
||||
_, versionRes, err := http2.HandleGet(versionUrl, http.MethodGet)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer versionRes.Body.Close()
|
||||
body, err := io.ReadAll(versionRes.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
lastModifiedStr := string(body)
|
||||
lastModifiedStr := string(versionRes)
|
||||
lastModified, err := strconv.Atoi(lastModifiedStr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -845,13 +840,18 @@ func (a AppService) SyncAppListFromRemote() (err error) {
|
||||
oldAppIds = append(oldAppIds, old.ID)
|
||||
}
|
||||
|
||||
var transport *http.Transport
|
||||
ok, transportItem := xpack.LoadRequestTransport()
|
||||
if ok {
|
||||
transport = transportItem
|
||||
}
|
||||
baseRemoteUrl := fmt.Sprintf("%s/%s/1panel", global.CONF.System.AppRepo, global.CONF.System.Mode)
|
||||
appsMap := getApps(oldApps, list.Apps)
|
||||
|
||||
global.LOG.Infof("Starting synchronization of application details...")
|
||||
for _, l := range list.Apps {
|
||||
app := appsMap[l.AppProperty.Key]
|
||||
_, iconRes, err := httpUtil.HandleGet(l.Icon, http.MethodGet)
|
||||
_, iconRes, err := httpUtil.HandleGetWithTransport(l.Icon, http.MethodGet, transport)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -878,7 +878,7 @@ func (a AppService) SyncAppListFromRemote() (err error) {
|
||||
|
||||
if _, ok := InitTypes[app.Type]; ok {
|
||||
dockerComposeUrl := fmt.Sprintf("%s/%s", versionUrl, "docker-compose.yml")
|
||||
_, composeRes, err := httpUtil.HandleGet(dockerComposeUrl, http.MethodGet)
|
||||
_, composeRes, err := httpUtil.HandleGetWithTransport(dockerComposeUrl, http.MethodGet, transport)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/docker/docker/api/types"
|
||||
"math"
|
||||
"net/http"
|
||||
"os"
|
||||
@ -16,6 +15,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
|
||||
httpUtil "github.com/1Panel-dev/1Panel/backend/utils/http"
|
||||
"github.com/1Panel-dev/1Panel/backend/utils/xpack"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
@ -778,7 +779,7 @@ func downloadApp(app model.App, appDetail model.AppDetail, appInstall *model.App
|
||||
}
|
||||
}()
|
||||
|
||||
if err = fileOp.DownloadFile(appDetail.DownloadUrl, filePath); err != nil {
|
||||
if err = fileOp.DownloadFileWithProxy(appDetail.DownloadUrl, filePath); err != nil {
|
||||
global.LOG.Errorf("download app[%s] error %v", app.Name, err)
|
||||
return
|
||||
}
|
||||
|
@ -326,13 +326,15 @@ func (u *SnapshotService) HandleSnapshot(isCronjob bool, logPath string, req dto
|
||||
func (u *SnapshotService) Delete(req dto.SnapshotBatchDelete) error {
|
||||
snaps, _ := snapshotRepo.GetList(commonRepo.WithIdsIn(req.Ids))
|
||||
for _, snap := range snaps {
|
||||
targetAccounts, err := loadClientMap(snap.From)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, item := range targetAccounts {
|
||||
global.LOG.Debugf("remove snapshot file %s.tar.gz from %s", snap.Name, item.backType)
|
||||
_, _ = item.client.Delete(path.Join(item.backupPath, "system_snapshot", snap.Name+".tar.gz"))
|
||||
if req.DeleteWithFile {
|
||||
targetAccounts, err := loadClientMap(snap.From)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, item := range targetAccounts {
|
||||
global.LOG.Debugf("remove snapshot file %s.tar.gz from %s", snap.Name, item.backType)
|
||||
_, _ = item.client.Delete(path.Join(item.backupPath, "system_snapshot", snap.Name+".tar.gz"))
|
||||
}
|
||||
}
|
||||
|
||||
_ = snapshotRepo.DeleteStatus(snap.ID)
|
||||
|
@ -108,7 +108,7 @@ func (u *UpgradeService) Upgrade(req dto.Upgrade) error {
|
||||
defer func() {
|
||||
global.Cron.Start()
|
||||
}()
|
||||
if err := fileOp.DownloadFile(downloadPath+"/"+fileName, rootDir+"/"+fileName); err != nil {
|
||||
if err := fileOp.DownloadFileWithProxy(downloadPath+"/"+fileName, rootDir+"/"+fileName); err != nil {
|
||||
global.LOG.Errorf("download service file failed, err: %v", err)
|
||||
_ = settingRepo.Update("SystemStatus", "Free")
|
||||
return
|
||||
|
@ -85,7 +85,7 @@ var AddTableSetting = &gormigrate.Migration{
|
||||
if err := tx.Create(&model.Setting{Key: "Language", Value: "zh"}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&model.Setting{Key: "Theme", Value: "auto"}).Error; err != nil {
|
||||
if err := tx.Create(&model.Setting{Key: "Theme", Value: "light"}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,15 @@ import (
|
||||
)
|
||||
|
||||
func HandleGet(url, method string) (int, []byte, error) {
|
||||
var transport *http.Transport
|
||||
ok, transportItem := xpack.LoadRequestTransport()
|
||||
if ok {
|
||||
transport = transportItem
|
||||
}
|
||||
return HandleGetWithTransport(url, method, transport)
|
||||
}
|
||||
|
||||
func HandleGetWithTransport(url, method string, transport *http.Transport) (int, []byte, error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
global.LOG.Errorf(" A panic occurred during handle request, error message: %v", r)
|
||||
@ -18,11 +27,7 @@ func HandleGet(url, method string) (int, []byte, error) {
|
||||
}
|
||||
}()
|
||||
|
||||
client := http.Client{Timeout: 10 * time.Second}
|
||||
ok, transport := xpack.LoadRequestTransport()
|
||||
if ok {
|
||||
client.Transport = transport
|
||||
}
|
||||
client := http.Client{Timeout: 10 * time.Second, Transport: transport}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
request, err := http.NewRequestWithContext(ctx, method, url, nil)
|
||||
|
@ -116,7 +116,13 @@ interface DialogProps {
|
||||
passwdKeep: string;
|
||||
}
|
||||
const acceptParams = (params: DialogProps): void => {
|
||||
form.proxyUrl = params.url || '127.0.0.1';
|
||||
if (params.url) {
|
||||
if (params.type === 'http' || params.type === 'https') {
|
||||
form.proxyUrl = params.url.replaceAll(params.type + '://', '');
|
||||
}
|
||||
} else {
|
||||
form.proxyUrl = '127.0.0.1';
|
||||
}
|
||||
form.proxyType = params.type || 'close';
|
||||
form.proxyPortItem = params.port ? Number(params.port) : 7890;
|
||||
form.proxyUser = params.user;
|
||||
|
Loading…
Reference in New Issue
Block a user