2024-08-08 15:38:37 +08:00
|
|
|
package v2
|
|
|
|
|
|
|
|
|
|
import (
|
2024-11-12 13:35:12 +08:00
|
|
|
"fmt"
|
|
|
|
|
|
2024-08-08 15:38:37 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/core/app/api/v2/helper"
|
|
|
|
|
"github.com/1Panel-dev/1Panel/core/app/dto"
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// @Tags Backup Account
|
|
|
|
|
// @Summary Create backup account
|
|
|
|
|
// @Accept json
|
|
|
|
|
// @Param request body dto.BackupOperate true "request"
|
|
|
|
|
// @Success 200
|
|
|
|
|
// @Security ApiKeyAuth
|
2025-01-21 18:32:14 +08:00
|
|
|
// @Security Timestamp
|
2025-01-14 14:27:51 +08:00
|
|
|
// @Router /core/backups [post]
|
2024-08-08 15:38:37 +08:00
|
|
|
// @x-panel-log {"bodyKeys":["type"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"创建备份账号 [type]","formatEN":"create backup account [type]"}
|
|
|
|
|
func (b *BaseApi) CreateBackup(c *gin.Context) {
|
|
|
|
|
var req dto.BackupOperate
|
|
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := backupService.Create(req); err != nil {
|
2024-10-29 18:42:12 +08:00
|
|
|
helper.InternalServer(c, err)
|
2024-08-08 15:38:37 +08:00
|
|
|
return
|
|
|
|
|
}
|
2025-04-18 15:44:28 +08:00
|
|
|
helper.Success(c)
|
2024-08-08 15:38:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Tags Backup Account
|
2024-12-26 14:13:41 +08:00
|
|
|
// @Summary Refresh token
|
2025-01-14 14:27:51 +08:00
|
|
|
// @Accept json
|
2025-02-08 14:25:26 +08:00
|
|
|
// @Param request body dto.OperateByName true "request"
|
2024-08-08 15:38:37 +08:00
|
|
|
// @Success 200
|
|
|
|
|
// @Security ApiKeyAuth
|
2025-01-21 18:32:14 +08:00
|
|
|
// @Security Timestamp
|
2025-01-14 14:27:51 +08:00
|
|
|
// @Router /core/backups/refresh/token [post]
|
2024-12-26 14:13:41 +08:00
|
|
|
func (b *BaseApi) RefreshToken(c *gin.Context) {
|
2025-02-08 14:25:26 +08:00
|
|
|
var req dto.OperateByName
|
2025-01-14 14:27:51 +08:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if err := backupService.RefreshToken(req); err != nil {
|
|
|
|
|
helper.InternalServer(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
2025-04-18 16:52:27 +08:00
|
|
|
helper.Success(c)
|
2024-08-08 15:38:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Tags Backup Account
|
2024-12-26 14:13:41 +08:00
|
|
|
// @Summary Load backup account base info
|
2024-08-08 15:38:37 +08:00
|
|
|
// @Accept json
|
2025-02-08 22:57:08 +08:00
|
|
|
// @Success 200 {object} dto.BackupClientInfo
|
2024-08-08 15:38:37 +08:00
|
|
|
// @Security ApiKeyAuth
|
2025-01-21 18:32:14 +08:00
|
|
|
// @Security Timestamp
|
2026-06-02 15:11:43 +08:00
|
|
|
// @Param clientType path string true "clientType"
|
2025-01-14 14:27:51 +08:00
|
|
|
// @Router /core/backups/client/:clientType [get]
|
2024-12-26 14:13:41 +08:00
|
|
|
func (b *BaseApi) LoadBackupClientInfo(c *gin.Context) {
|
2024-11-12 13:35:12 +08:00
|
|
|
clientType, ok := c.Params.Get("clientType")
|
|
|
|
|
if !ok {
|
|
|
|
|
helper.BadRequest(c, fmt.Errorf("error %s in path", "clientType"))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
data, err := backupService.LoadBackupClientInfo(clientType)
|
2024-08-08 15:38:37 +08:00
|
|
|
if err != nil {
|
2024-10-29 18:42:12 +08:00
|
|
|
helper.InternalServer(c, err)
|
2024-08-08 15:38:37 +08:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
helper.SuccessWithData(c, data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Tags Backup Account
|
|
|
|
|
// @Summary Delete backup account
|
|
|
|
|
// @Accept json
|
2025-02-08 14:25:26 +08:00
|
|
|
// @Param request body dto.OperateByName true "request"
|
2024-08-08 15:38:37 +08:00
|
|
|
// @Success 200
|
|
|
|
|
// @Security ApiKeyAuth
|
2025-01-21 18:32:14 +08:00
|
|
|
// @Security Timestamp
|
2025-01-14 14:27:51 +08:00
|
|
|
// @Router /core/backups/del [post]
|
2025-02-08 14:25:26 +08:00
|
|
|
// @x-panel-log {"bodyKeys":["name"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"删除备份账号 [name]","formatEN":"delete backup account [name]"}
|
2024-08-08 15:38:37 +08:00
|
|
|
func (b *BaseApi) DeleteBackup(c *gin.Context) {
|
2025-02-08 14:25:26 +08:00
|
|
|
var req dto.OperateByName
|
2024-08-08 15:38:37 +08:00
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-08 14:25:26 +08:00
|
|
|
if err := backupService.Delete(req.Name); err != nil {
|
2024-10-29 18:42:12 +08:00
|
|
|
helper.InternalServer(c, err)
|
2024-08-08 15:38:37 +08:00
|
|
|
return
|
|
|
|
|
}
|
2025-04-18 16:52:27 +08:00
|
|
|
helper.Success(c)
|
2024-08-08 15:38:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Tags Backup Account
|
|
|
|
|
// @Summary Update backup account
|
|
|
|
|
// @Accept json
|
|
|
|
|
// @Param request body dto.BackupOperate true "request"
|
|
|
|
|
// @Success 200
|
|
|
|
|
// @Security ApiKeyAuth
|
2025-01-21 18:32:14 +08:00
|
|
|
// @Security Timestamp
|
2025-01-14 14:27:51 +08:00
|
|
|
// @Router /core/backups/update [post]
|
2026-06-02 15:11:43 +08:00
|
|
|
// @x-panel-log {"bodyKeys":["type"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"更新备份账号 [type]","formatEN":"update backup account [type]"}
|
2024-08-08 15:38:37 +08:00
|
|
|
func (b *BaseApi) UpdateBackup(c *gin.Context) {
|
|
|
|
|
var req dto.BackupOperate
|
|
|
|
|
if err := helper.CheckBindAndValidate(&req, c); err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := backupService.Update(req); err != nil {
|
2024-10-29 18:42:12 +08:00
|
|
|
helper.InternalServer(c, err)
|
2024-08-08 15:38:37 +08:00
|
|
|
return
|
|
|
|
|
}
|
2025-04-18 16:52:27 +08:00
|
|
|
helper.Success(c)
|
2025-01-21 18:32:14 +08:00
|
|
|
}
|