Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions agent/app/api/v2/ai.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (b *BaseApi) DeleteOllamaModel(c *gin.Context) {
return
}

helper.SuccessWithOutData(c)
helper.Success(c)
}

// @Tags AI
Expand Down Expand Up @@ -211,7 +211,7 @@ func (b *BaseApi) BindDomain(c *gin.Context) {
helper.BadRequest(c, err)
return
}
helper.SuccessWithOutData(c)
helper.Success(c)
}

// @Tags AI
Expand Down Expand Up @@ -252,5 +252,5 @@ func (b *BaseApi) UpdateBindDomain(c *gin.Context) {
helper.BadRequest(c, err)
return
}
helper.SuccessWithOutData(c)
helper.Success(c)
}
22 changes: 3 additions & 19 deletions agent/app/api/v2/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (b *BaseApi) SyncApp(c *gin.Context) {
helper.InternalServer(c, err)
return
}
helper.SuccessWithOutData(c)
helper.Success(c)
}

// @Tags App
Expand All @@ -74,7 +74,7 @@ func (b *BaseApi) SyncLocalApp(c *gin.Context) {
return
}
go appService.SyncAppListFromLocal(req.TaskID)
helper.SuccessWithOutData(c)
helper.Success(c)
}

// @Tags App
Expand Down Expand Up @@ -147,22 +147,6 @@ func (b *BaseApi) GetAppDetailByID(c *gin.Context) {
helper.SuccessWithData(c, appDetailDTO)
}

// @Tags App
// @Summary Get Ignore App
// @Accept json
// @Success 200 {array} response.IgnoredApp
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /apps/ignored [get]
func (b *BaseApi) GetIgnoredApp(c *gin.Context) {
res, err := appService.GetIgnoredApp()
if err != nil {
helper.InternalServer(c, err)
return
}
helper.SuccessWithData(c, res)
}

// @Tags App
// @Summary Install app
// @Accept json
Expand Down Expand Up @@ -227,7 +211,7 @@ func (b *BaseApi) UpdateAppstoreConfig(c *gin.Context) {
helper.InternalServer(c, err)
return
}
helper.SuccessWithOutData(c)
helper.Success(c)
}

// @Tags App
Expand Down
66 changes: 66 additions & 0 deletions agent/app/api/v2/app_ignore_upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package v2

import (
"github.com/1Panel-dev/1Panel/agent/app/api/v2/helper"
"github.com/1Panel-dev/1Panel/agent/app/dto/request"
"github.com/gin-gonic/gin"
)

// @Tags App
// @Summary List Upgrade Ignored App
// @Accept json
// @Success 200 {array} model.AppIgnoreUpgrade
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /apps/ignored/detail [get]
func (b *BaseApi) ListAppIgnored(c *gin.Context) {
res, err := appIgnoreUpgradeService.List()
if err != nil {
helper.InternalServer(c, err)
return
}
helper.SuccessWithData(c, res)
}

// @Tags App
// @Summary Ignore Upgrade App
// @Accept json
// @Param request body request.AppIgnoreUpgradeReq true "request"
// @Success 200
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /apps/installed/ignore [post]
// @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFunctions":[],"formatZH":"忽略应用升级","formatEN":"Ignore application upgrade"}
func (b *BaseApi) IgnoreAppUpgrade(c *gin.Context) {
var req request.AppIgnoreUpgradeReq
if err := helper.CheckBindAndValidate(&req, c); err != nil {
return
}
if err := appIgnoreUpgradeService.CreateAppIgnore(req); err != nil {
helper.InternalServer(c, err)
return
}
helper.Success(c)
}

// 写一个去掉忽略的接口
// @Tags App
// @Summary Cancel Ignore Upgrade App
// @Accept json
// @Param request body request.ReqWithID true "request"
// @Success 200
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /apps/ignored/cancel [post]
// @x-panel-log {"bodyKeys":[],"paramKeys":[],"BeforeFunctions":[],"formatZH":"取消忽略应用升级","formatEN":"Cancel ignore application upgrade"}
func (b *BaseApi) CancelIgnoreAppUpgrade(c *gin.Context) {
var req request.ReqWithID
if err := helper.CheckBindAndValidate(&req, c); err != nil {
return
}
if err := appIgnoreUpgradeService.Delete(req); err != nil {
helper.InternalServer(c, err)
return
}
helper.Success(c)
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code looks mostly correct with minor improvements. Here are some observations and suggestions:

Improvements

  1. Package Naming: The package name v2 is reasonable, but it's worth checking if this versioning system aligns with the rest of the project.

  2. Import Statements: All necessary imports seem to be correctly placed at the beginning (goimports) so that they don't have syntax errors.

  3. Endpoints:

    • /apps/ignored/detail: This endpoint lists all ignored apps without an ID filter.
    • /apps/installed/ignore: This endpoint ignores a specific app upgrade.
    • /apps/ignored/cancel: This endpoint cancels the ignore of a specific app upgrade.

    Ensure these endpoints meet intended functionality:

    • /apps/ignored/detail should not require an ID parameter unless there's a clear business requirement for such filtering.
    • Use meaningful names for parameters in both POST requests; e.g., req.ID instead of just request.
  4. Error Handling:

    • Both internal server error handling use helper.InternalServer(), which needs careful review for its implementation.
    • It might be cleaner to include more information about the error or implement custom error logging here before calling it.
  5. Comments: Comments like @Description could provide more context about what the endpoints do. For example, you can explain why certain fields or filters are used.

  6. API Logging:

    • While well-implemented, ensuring API logs have consistent keys can make them easier to parse. Consider using common format strings across applications.
  7. Security:

    • ApiKeyAuth and Timestamp security tags suggest that your authentication mechanism includes API keys or timestamps. Ensure proper validation occurs on client side too to prevent unauthorized access.

Optimization Suggestions

  1. Avoid Redundant Calls to Helper Functions:
    In many cases, helper functions can handle multiple types of inputs. If CheckBindAndValidate() works fine alone without needing to separate it out into different helpers based on parameter type, consider combining logic where feasible.

  2. Code Reusability:
    Review how various helper functions (e.g., binding validation) relate between individual controllers within the same base API class or structure.

  3. Performance Considerations:

    • Depending on database size and complexity, ensure queries used in services (ListAppIgnored, etc.) optimize query performance.
    • Profile critical sections of the codebase if needed, especially focusing on areas dealing with data retrieval or processing.

Overall, this code is well-structured and follows basic coding conventions. With additional testing specifically targeting scenarios involving ignoring / cancelling upgrades, further optimizations can be made tailored to the specifics of your application’s environment.

31 changes: 5 additions & 26 deletions agent/app/api/v2/app_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (b *BaseApi) SyncInstalled(c *gin.Context) {
helper.InternalServer(c, err)
return
}
helper.SuccessWithOutData(c)
helper.Success(c)
}

// @Tags App
Expand All @@ -179,7 +179,7 @@ func (b *BaseApi) OperateInstalled(c *gin.Context) {
helper.InternalServer(c, err)
return
}
helper.SuccessWithOutData(c)
helper.Success(c)
}

// @Tags App
Expand Down Expand Up @@ -239,7 +239,7 @@ func (b *BaseApi) ChangeAppPort(c *gin.Context) {
helper.InternalServer(c, err)
return
}
helper.SuccessWithOutData(c)
helper.Success(c)
}

// @Tags App
Expand Down Expand Up @@ -304,28 +304,7 @@ func (b *BaseApi) UpdateInstalled(c *gin.Context) {
helper.InternalServer(c, err)
return
}
helper.SuccessWithOutData(c)
}

// @Tags App
// @Summary ignore App Update
// @Accept json
// @Param request body request.AppInstalledIgnoreUpgrade true "request"
// @Success 200
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /apps/installed/ignore [post]
// @x-panel-log {"bodyKeys":["installId"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"忽略应用 [installId] 版本升级","formatEN":"Application param update [installId]"}
func (b *BaseApi) IgnoreUpgrade(c *gin.Context) {
var req request.AppInstalledIgnoreUpgrade
if err := helper.CheckBindAndValidate(&req, c); err != nil {
return
}
if err := appInstallService.IgnoreUpgrade(req); err != nil {
helper.InternalServer(c, err)
return
}
helper.SuccessWithOutData(c)
helper.Success(c)
}

// @Tags App
Expand All @@ -346,5 +325,5 @@ func (b *BaseApi) UpdateAppConfig(c *gin.Context) {
helper.InternalServer(c, err)
return
}
helper.SuccessWithOutData(c)
helper.Success(c)
}
22 changes: 11 additions & 11 deletions agent/app/api/v2/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (b *BaseApi) CheckBackupUsed(c *gin.Context) {
return
}

helper.SuccessWithOutData(c)
helper.Success(c)
}

func (b *BaseApi) SyncBackupAccount(c *gin.Context) {
Expand All @@ -36,7 +36,7 @@ func (b *BaseApi) SyncBackupAccount(c *gin.Context) {
return
}

helper.SuccessWithOutData(c)
helper.Success(c)
}

// @Tags Backup Account
Expand All @@ -58,7 +58,7 @@ func (b *BaseApi) CreateBackup(c *gin.Context) {
helper.InternalServer(c, err)
return
}
helper.SuccessWithOutData(c)
helper.Success(c)
}

// @Tags Backup Account
Expand All @@ -78,7 +78,7 @@ func (b *BaseApi) RefreshToken(c *gin.Context) {
helper.InternalServer(c, err)
return
}
helper.SuccessWithOutData(c)
helper.Success(c)
}

// @Tags Backup Account
Expand Down Expand Up @@ -122,7 +122,7 @@ func (b *BaseApi) DeleteBackup(c *gin.Context) {
helper.InternalServer(c, err)
return
}
helper.SuccessWithOutData(c)
helper.Success(c)
}

// @Tags Backup Account
Expand All @@ -144,7 +144,7 @@ func (b *BaseApi) UpdateBackup(c *gin.Context) {
helper.InternalServer(c, err)
return
}
helper.SuccessWithOutData(c)
helper.Success(c)
}

// @Tags Backup Account
Expand Down Expand Up @@ -321,7 +321,7 @@ func (b *BaseApi) UpdateRecordDescription(c *gin.Context) {
helper.InternalServer(c, err)
return
}
helper.SuccessWithOutData(c)
helper.Success(c)
}

// @Tags Backup Account
Expand All @@ -343,7 +343,7 @@ func (b *BaseApi) DeleteBackupRecord(c *gin.Context) {
helper.InternalServer(c, err)
return
}
helper.SuccessWithOutData(c)
helper.Success(c)
}

// @Tags Backup Account
Expand Down Expand Up @@ -406,7 +406,7 @@ func (b *BaseApi) Backup(c *gin.Context) {
return
}
}
helper.SuccessWithOutData(c)
helper.Success(c)
}

// @Tags Backup Account
Expand Down Expand Up @@ -461,7 +461,7 @@ func (b *BaseApi) Recover(c *gin.Context) {
return
}
}
helper.SuccessWithOutData(c)
helper.Success(c)
}

// @Tags Backup Account
Expand Down Expand Up @@ -501,5 +501,5 @@ func (b *BaseApi) RecoverByUpload(c *gin.Context) {
return
}
}
helper.SuccessWithOutData(c)
helper.Success(c)
}
16 changes: 8 additions & 8 deletions agent/app/api/v2/clam.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (b *BaseApi) CreateClam(c *gin.Context) {
helper.InternalServer(c, err)
return
}
helper.SuccessWithOutData(c)
helper.Success(c)
}

// @Tags Clam
Expand All @@ -47,7 +47,7 @@ func (b *BaseApi) UpdateClam(c *gin.Context) {
helper.InternalServer(c, err)
return
}
helper.SuccessWithOutData(c)
helper.Success(c)
}

// @Tags Clam
Expand All @@ -69,7 +69,7 @@ func (b *BaseApi) UpdateClamStatus(c *gin.Context) {
helper.InternalServer(c, err)
return
}
helper.SuccessWithOutData(c)
helper.Success(c)
}

// @Tags Clam
Expand Down Expand Up @@ -135,7 +135,7 @@ func (b *BaseApi) OperateClam(c *gin.Context) {
return
}

helper.SuccessWithOutData(c)
helper.Success(c)
}

// @Tags Clam
Expand All @@ -157,7 +157,7 @@ func (b *BaseApi) CleanClamRecord(c *gin.Context) {
return
}

helper.SuccessWithOutData(c)
helper.Success(c)
}

// @Tags Clam
Expand Down Expand Up @@ -249,7 +249,7 @@ func (b *BaseApi) UpdateFile(c *gin.Context) {
helper.InternalServer(c, err)
return
}
helper.SuccessWithOutData(c)
helper.Success(c)
}

// @Tags Clam
Expand All @@ -271,7 +271,7 @@ func (b *BaseApi) DeleteClam(c *gin.Context) {
helper.InternalServer(c, err)
return
}
helper.SuccessWithOutData(c)
helper.Success(c)
}

// @Tags Clam
Expand All @@ -293,5 +293,5 @@ func (b *BaseApi) HandleClamScan(c *gin.Context) {
helper.InternalServer(c, err)
return
}
helper.SuccessWithOutData(c)
helper.Success(c)
}
6 changes: 3 additions & 3 deletions agent/app/api/v2/compose_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (b *BaseApi) CreateComposeTemplate(c *gin.Context) {
helper.InternalServer(c, err)
return
}
helper.SuccessWithOutData(c)
helper.Success(c)
}

// @Tags Container Compose-template
Expand Down Expand Up @@ -91,7 +91,7 @@ func (b *BaseApi) DeleteComposeTemplate(c *gin.Context) {
helper.InternalServer(c, err)
return
}
helper.SuccessWithOutData(c)
helper.Success(c)
}

// @Tags Container Compose-template
Expand All @@ -116,5 +116,5 @@ func (b *BaseApi) UpdateComposeTemplate(c *gin.Context) {
helper.InternalServer(c, err)
return
}
helper.SuccessWithOutData(c)
helper.Success(c)
}
Loading
Loading