diff --git a/backend/app/service/app.go b/backend/app/service/app.go index ec91b7771..0b3b14b35 100644 --- a/backend/app/service/app.go +++ b/backend/app/service/app.go @@ -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 } diff --git a/backend/app/service/app_utils.go b/backend/app/service/app_utils.go index 1a548d54a..2b893f5dc 100644 --- a/backend/app/service/app_utils.go +++ b/backend/app/service/app_utils.go @@ -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 } diff --git a/backend/app/service/snapshot.go b/backend/app/service/snapshot.go index b82a23459..48ea41637 100644 --- a/backend/app/service/snapshot.go +++ b/backend/app/service/snapshot.go @@ -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) diff --git a/backend/app/service/upgrade.go b/backend/app/service/upgrade.go index 0644efd35..36f6e7fe3 100644 --- a/backend/app/service/upgrade.go +++ b/backend/app/service/upgrade.go @@ -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 diff --git a/backend/init/migration/migrations/init.go b/backend/init/migration/migrations/init.go index ca2f469b8..3af26a063 100644 --- a/backend/init/migration/migrations/init.go +++ b/backend/init/migration/migrations/init.go @@ -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 } diff --git a/backend/utils/http/request.go b/backend/utils/http/request.go index 0afe7e260..0f6850330 100644 --- a/backend/utils/http/request.go +++ b/backend/utils/http/request.go @@ -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) diff --git a/frontend/src/views/setting/panel/proxy/index.vue b/frontend/src/views/setting/panel/proxy/index.vue index 0f60d3049..eac65204b 100644 --- a/frontend/src/views/setting/panel/proxy/index.vue +++ b/frontend/src/views/setting/panel/proxy/index.vue @@ -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;