-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix: Modify the recommended application synchronization mode #8050
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ import ( | |
| "github.com/docker/docker/api/types/filters" | ||
|
|
||
| "github.com/1Panel-dev/1Panel/agent/app/dto" | ||
| "github.com/1Panel-dev/1Panel/agent/app/repo" | ||
| "github.com/1Panel-dev/1Panel/agent/app/task" | ||
| "github.com/1Panel-dev/1Panel/agent/global" | ||
| "github.com/1Panel-dev/1Panel/agent/utils/cmd" | ||
|
|
@@ -37,7 +38,6 @@ const ( | |
| uploadPath = "1panel/uploads" | ||
| downloadPath = "1panel/download" | ||
| logPath = "1panel/log" | ||
| taskPath = "1panel/task" | ||
| ) | ||
|
|
||
| func (u *DeviceService) Scan() dto.CleanData { | ||
|
|
@@ -254,18 +254,10 @@ func (u *DeviceService) Clean(req []dto.Clean) { | |
| dropFileOrDir(path.Join(global.Dir.BaseDir, logPath, item.Name)) | ||
| } | ||
| case "task_log": | ||
| pathItem := path.Join(global.Dir.BaseDir, taskPath, item.Name) | ||
| dropFileOrDir(path.Join(global.Dir.BaseDir, taskPath, item.Name)) | ||
| pathItem := path.Join(global.Dir.BaseDir, logPath, item.Name) | ||
| dropFileOrDir(pathItem) | ||
| if len(item.Name) == 0 { | ||
| files, _ := os.ReadDir(pathItem) | ||
| if len(files) == 0 { | ||
| continue | ||
| } | ||
| for _, file := range files { | ||
| _ = cronjobRepo.DeleteRecord(cronjobRepo.WithByRecordFile(path.Join(pathItem, file.Name()))) | ||
| } | ||
| } else { | ||
| _ = cronjobRepo.DeleteRecord(cronjobRepo.WithByRecordFile(pathItem)) | ||
| _ = taskRepo.Delete(repo.WithByType(item.Name)) | ||
| } | ||
| case "images": | ||
| dropImages() | ||
|
|
@@ -506,8 +498,8 @@ func loadLogTree(fileOp fileUtils.FileOp) []dto.CleanTree { | |
| } | ||
| treeData = append(treeData, dto.CleanTree{ID: uuid.NewString(), Label: "system_log", Size: uint64(size), Children: list1, Type: "system_log", IsRecommend: true}) | ||
|
|
||
| path2 := path.Join(global.Dir.BaseDir, taskPath) | ||
| list2 := loadTreeWithAllFile(false, path2, "task_log", path2, fileOp) | ||
| path2 := path.Join(global.Dir.BaseDir, logPath) | ||
| list2 := loadTreeWithDir(false, "task_log", path2, fileOp) | ||
| size2, _ := fileOp.GetDirSize(path2) | ||
| treeData = append(treeData, dto.CleanTree{ID: uuid.NewString(), Label: "task_log", Size: uint64(size2), Children: list2, Type: "task_log"}) | ||
| return treeData | ||
|
|
@@ -570,6 +562,9 @@ func loadTreeWithDir(isCheck bool, treeType, pathItem string, fileOp fileUtils.F | |
| if (treeType == "old_upgrade" || treeType == "upgrade") && !strings.HasPrefix(file.Name(), "upgrade_2023") { | ||
| continue | ||
| } | ||
| if treeType == "task_log" && file.Name() == "ssl" { | ||
| continue | ||
| } | ||
| if file.IsDir() { | ||
| size, err := fileOp.GetDirSize(path.Join(pathItem, file.Name())) | ||
| if err != nil { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code appears to be well written but not extensive enough for detailed analysis of regularity, potential issues, or optimization. The main difference seems to relate to whether the directory "uploadPath" should include an extra slash after "/uploads". It might be helpful if more context is provided for proper review. No significant problems were detected according to the checks performed. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import ( | |
| "github.com/1Panel-dev/1Panel/core/app/model" | ||
| "github.com/1Panel-dev/1Panel/core/app/repo" | ||
| "github.com/1Panel-dev/1Panel/core/constant" | ||
| "github.com/1Panel-dev/1Panel/core/utils/req_helper" | ||
| "github.com/1Panel-dev/1Panel/core/utils/xpack" | ||
| ) | ||
|
|
||
|
|
@@ -37,32 +38,23 @@ func (u *LauncherService) Search() ([]string, error) { | |
|
|
||
| func (u *LauncherService) ChangeShow(req dto.SettingUpdate) error { | ||
| launcher, _ := launcherRepo.Get(repo.WithByKey(req.Key)) | ||
| if req.Value == constant.StatusEnable { | ||
| if launcher.ID != 0 { | ||
| go syncLauncherToAgent(launcher, "create") | ||
| return nil | ||
| } | ||
| launcher.Key = req.Key | ||
| if err := launcherRepo.Create(&launcher); err != nil { | ||
| if req.Value == constant.StatusEnable && launcher.ID == 0 { | ||
| if err := launcherRepo.Create(&model.AppLauncher{Key: req.Key}); err != nil { | ||
| return err | ||
| } | ||
| go syncLauncherToAgent(launcher, "create") | ||
| return nil | ||
| } | ||
| if launcher.ID == 0 { | ||
| go syncLauncherToAgent(launcher, "delete") | ||
| return nil | ||
| } | ||
| if err := launcherRepo.Delete(repo.WithByKey(req.Key)); err != nil { | ||
| return err | ||
| if req.Value == constant.StatusDisable && launcher.ID != 0 { | ||
| if err := launcherRepo.Delete(repo.WithByKey(req.Key)); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| go syncLauncherToAgent(launcher, "delete") | ||
| go syncLauncherToAgent() | ||
| return nil | ||
| } | ||
|
|
||
| func syncLauncherToAgent(launcher model.AppLauncher, operation string) { | ||
| itemData, _ := json.Marshal(launcher) | ||
| itemJson := dto.SyncToAgent{Name: launcher.Key, Operation: operation, Data: string(itemData)} | ||
| bodyItem, _ := json.Marshal(itemJson) | ||
| _ = xpack.RequestToAllAgent("/api/v2/backups/sync", http.MethodPost, bytes.NewReader((bodyItem))) | ||
| func syncLauncherToAgent() { | ||
| launchers, _ := launcherRepo.List() | ||
| itemData, _ := json.Marshal(launchers) | ||
| _, _ = req_helper.NewLocalClient("/api/v2/dashboard/app/launcher/sync", http.MethodPost, bytes.NewReader((itemData))) | ||
| _ = xpack.RequestToAllAgent("/api/v2/dashboard/app/launcher/sync", http.MethodPost, bytes.NewReader((itemData))) | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The key difference between the two codes is that one uses This can cause issues with agents responding to requests incorrectly depending on what they actually support since different enums may correspond to differing statuses like 'create' vs 'delete'. Optimization suggestion:
For example: |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provided code snippet is from a C# library for managing panels on an open-source software platform called 1Panel. There are a few points to note:
syncfunctions do not take arguments, which is not consistent with their current implementation.Here are some suggestions:
a. Refactor:
loadOsInfo()function by extracting common functionality (e.g., loading settings) instead of duplicating code every time it needs to load a particular section or option in the OS information payload.b. Functionality Improvements:
c. Testing and Quality Assurance:
d. Documentation:
Sync()method) and private helper functions. This will help other developers understand expected behavior and requirements, particularly when they implement these methods outside the original base package.It is good practice to maintain consistency and efficiency throughout the development process but also adapt and grow over time. Good luck!