2023-01-06 10:53:25 +00:00
package v1
import (
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/backend/constant"
"github.com/gin-gonic/gin"
)
// @Tags System Setting
2023-02-13 07:48:18 +00:00
// @Summary Create system snapshot
2023-01-06 10:53:25 +00:00
// @Description 创建系统快照
// @Accept json
// @Param request body dto.SnapshotCreate true "request"
// @Success 200
// @Security ApiKeyAuth
// @Router /settings/snapshot [post]
2023-10-07 07:46:44 +00:00
// @x-panel-log {"bodyKeys":["from", "description"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"创建系统快照 [description] 到 [from]","formatEN":"Create system backup [description] to [from]"}
2023-01-06 10:53:25 +00:00
func ( b * BaseApi ) CreateSnapshot ( c * gin . Context ) {
var req dto . SnapshotCreate
2023-10-27 06:19:26 +00:00
if err := helper . CheckBindAndValidate ( & req , c ) ; err != nil {
2023-01-06 10:53:25 +00:00
return
}
2023-10-27 06:19:26 +00:00
2023-01-09 14:55:10 +00:00
if err := snapshotService . SnapshotCreate ( req ) ; err != nil {
2023-01-06 10:53:25 +00:00
helper . ErrorWithDetail ( c , constant . CodeErrInternalServer , constant . ErrTypeInternalServer , err )
return
}
helper . SuccessWithData ( c , nil )
}
2023-02-13 07:48:18 +00:00
// @Tags System Setting
// @Summary Import system snapshot
// @Description 导入已有快照
// @Accept json
// @Param request body dto.SnapshotImport true "request"
// @Success 200
// @Security ApiKeyAuth
// @Router /settings/snapshot/import [post]
2023-10-07 07:46:44 +00:00
// @x-panel-log {"bodyKeys":["from", "names"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"从 [from] 同步系统快照 [names]","formatEN":"Sync system snapshots [names] from [from]"}
2023-02-13 07:48:18 +00:00
func ( b * BaseApi ) ImportSnapshot ( c * gin . Context ) {
var req dto . SnapshotImport
2023-10-27 06:19:26 +00:00
if err := helper . CheckBindAndValidate ( & req , c ) ; err != nil {
2023-02-13 07:48:18 +00:00
return
}
2023-10-27 06:19:26 +00:00
2023-02-13 07:48:18 +00:00
if err := snapshotService . SnapshotImport ( req ) ; err != nil {
helper . ErrorWithDetail ( c , constant . CodeErrInternalServer , constant . ErrTypeInternalServer , err )
return
}
helper . SuccessWithData ( c , nil )
}
2023-08-23 09:16:18 +00:00
// @Tags System Setting
// @Summary Load Snapshot status
// @Description 获取快照状态
// @Accept json
// @Param request body dto.OperateByID true "request"
// @Success 200
// @Security ApiKeyAuth
// @Router /settings/snapshot/status [post]
func ( b * BaseApi ) LoadSnapShotStatus ( c * gin . Context ) {
var req dto . OperateByID
2023-10-27 06:19:26 +00:00
if err := helper . CheckBindAndValidate ( & req , c ) ; err != nil {
2023-08-23 09:16:18 +00:00
return
}
2023-10-27 06:19:26 +00:00
2023-08-23 09:16:18 +00:00
data , err := snapshotService . LoadSnapShotStatus ( req . ID )
if err != nil {
helper . ErrorWithDetail ( c , constant . CodeErrInternalServer , constant . ErrTypeInternalServer , err )
return
}
helper . SuccessWithData ( c , data )
}
2023-02-13 07:48:18 +00:00
// @Tags System Setting
// @Summary Update snapshot description
// @Description 更新快照描述信息
// @Accept json
// @Param request body dto.UpdateDescription true "request"
// @Success 200
// @Security ApiKeyAuth
// @Router /settings/snapshot/description/update [post]
2023-10-07 07:46:44 +00:00
// @x-panel-log {"bodyKeys":["id","description"],"paramKeys":[],"BeforeFunctions":[{"input_column":"id","input_value":"id","isList":false,"db":"snapshots","output_column":"name","output_value":"name"}],"formatZH":"快照 [name] 描述信息修改 [description]","formatEN":"The description of the snapshot [name] is modified => [description]"}
2023-02-13 07:48:18 +00:00
func ( b * BaseApi ) UpdateSnapDescription ( c * gin . Context ) {
var req dto . UpdateDescription
2023-10-27 06:19:26 +00:00
if err := helper . CheckBindAndValidate ( & req , c ) ; err != nil {
2023-02-13 07:48:18 +00:00
return
}
2023-10-27 06:19:26 +00:00
2023-02-13 07:48:18 +00:00
if err := snapshotService . UpdateDescription ( req ) ; err != nil {
helper . ErrorWithDetail ( c , constant . CodeErrInternalServer , constant . ErrTypeInternalServer , err )
return
}
helper . SuccessWithData ( c , nil )
}
2023-01-06 10:53:25 +00:00
// @Tags System Setting
// @Summary Page system snapshot
// @Description 获取系统快照列表分页
// @Accept json
2024-08-28 05:45:22 +00:00
// @Param request body dto.PageSnapshot true "request"
2023-01-06 10:53:25 +00:00
// @Success 200 {object} dto.PageResult
// @Security ApiKeyAuth
2023-01-09 14:55:10 +00:00
// @Router /settings/snapshot/search [post]
2023-01-06 10:53:25 +00:00
func ( b * BaseApi ) SearchSnapshot ( c * gin . Context ) {
2024-08-28 05:45:22 +00:00
var req dto . PageSnapshot
2023-10-27 06:19:26 +00:00
if err := helper . CheckBindAndValidate ( & req , c ) ; err != nil {
2023-01-06 10:53:25 +00:00
return
}
2023-10-27 06:19:26 +00:00
2023-01-06 10:53:25 +00:00
total , accounts , err := snapshotService . SearchWithPage ( req )
if err != nil {
helper . ErrorWithDetail ( c , constant . CodeErrInternalServer , constant . ErrTypeInternalServer , err )
return
}
helper . SuccessWithData ( c , dto . PageResult {
Total : total ,
Items : accounts ,
} )
}
2023-01-09 14:55:10 +00:00
2024-10-10 03:05:00 +00:00
// @Tags System Setting
// @Summary Load system snapshot size
// @Description 获取系统快照大小
// @Accept json
// @Param request body dto.PageSnapshot true "request"
// @Success 200
// @Security ApiKeyAuth
// @Router /settings/snapshot/size [post]
func ( b * BaseApi ) LoadSnapshotSize ( c * gin . Context ) {
var req dto . PageSnapshot
if err := helper . CheckBindAndValidate ( & req , c ) ; err != nil {
return
}
data , err := snapshotService . LoadSize ( req )
if err != nil {
helper . ErrorWithDetail ( c , constant . CodeErrInternalServer , constant . ErrTypeInternalServer , err )
return
}
helper . SuccessWithData ( c , data )
}
2023-01-09 14:55:10 +00:00
// @Tags System Setting
// @Summary Recover system backup
// @Description 从系统快照恢复
// @Accept json
// @Param request body dto.SnapshotRecover true "request"
// @Success 200
// @Security ApiKeyAuth
// @Router /settings/snapshot/recover [post]
2023-10-07 07:46:44 +00:00
// @x-panel-log {"bodyKeys":["id"],"paramKeys":[],"BeforeFunctions":[{"input_column":"id","input_value":"id","isList":false,"db":"snapshots","output_column":"name","output_value":"name"}],"formatZH":"从系统快照 [name] 恢复","formatEN":"Recover from system backup [name]"}
2023-01-09 14:55:10 +00:00
func ( b * BaseApi ) RecoverSnapshot ( c * gin . Context ) {
var req dto . SnapshotRecover
2023-10-27 06:19:26 +00:00
if err := helper . CheckBindAndValidate ( & req , c ) ; err != nil {
2023-01-09 14:55:10 +00:00
return
}
if err := snapshotService . SnapshotRecover ( req ) ; err != nil {
helper . ErrorWithDetail ( c , constant . CodeErrInternalServer , constant . ErrTypeInternalServer , err )
return
}
helper . SuccessWithData ( c , nil )
}
// @Tags System Setting
// @Summary Rollback system backup
// @Description 从系统快照回滚
// @Accept json
// @Param request body dto.SnapshotRecover true "request"
// @Success 200
// @Security ApiKeyAuth
// @Router /settings/snapshot/rollback [post]
2023-10-07 07:46:44 +00:00
// @x-panel-log {"bodyKeys":["id"],"paramKeys":[],"BeforeFunctions":[{"input_column":"id","input_value":"id","isList":false,"db":"snapshots","output_column":"name","output_value":"name"}],"formatZH":"从系统快照 [name] 回滚","formatEN":"Rollback from system backup [name]"}
2023-01-09 14:55:10 +00:00
func ( b * BaseApi ) RollbackSnapshot ( c * gin . Context ) {
var req dto . SnapshotRecover
2023-10-27 06:19:26 +00:00
if err := helper . CheckBindAndValidate ( & req , c ) ; err != nil {
2023-01-09 14:55:10 +00:00
return
}
if err := snapshotService . SnapshotRollback ( req ) ; err != nil {
helper . ErrorWithDetail ( c , constant . CodeErrInternalServer , constant . ErrTypeInternalServer , err )
return
}
helper . SuccessWithData ( c , nil )
}
// @Tags System Setting
// @Summary Delete system backup
// @Description 删除系统快照
// @Accept json
2024-05-31 09:31:19 +00:00
// @Param request body dto.SnapshotBatchDelete true "request"
2023-01-09 14:55:10 +00:00
// @Success 200
// @Security ApiKeyAuth
// @Router /settings/snapshot/del [post]
2023-10-07 07:46:44 +00:00
// @x-panel-log {"bodyKeys":["ids"],"paramKeys":[],"BeforeFunctions":[{"input_column":"id","input_value":"ids","isList":true,"db":"snapshots","output_column":"name","output_value":"name"}],"formatZH":"删除系统快照 [name]","formatEN":"Delete system backup [name]"}
2023-01-09 14:55:10 +00:00
func ( b * BaseApi ) DeleteSnapshot ( c * gin . Context ) {
2024-05-31 09:31:19 +00:00
var req dto . SnapshotBatchDelete
2023-10-27 06:19:26 +00:00
if err := helper . CheckBindAndValidate ( & req , c ) ; err != nil {
2023-01-09 14:55:10 +00:00
return
}
if err := snapshotService . Delete ( req ) ; err != nil {
helper . ErrorWithDetail ( c , constant . CodeErrInternalServer , constant . ErrTypeInternalServer , err )
return
}
helper . SuccessWithData ( c , nil )
}