2022-09-16 10:53:45 +00:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
2022-10-17 08:32:31 +00:00
|
|
|
"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/1Panel-dev/1Panel/backend/global"
|
2022-09-16 10:53:45 +00:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags Backup Account
|
|
|
|
// @Summary Create backup account
|
|
|
|
// @Description 创建备份账号
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.BackupOperate true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /backups [post]
|
|
|
|
// @x-panel-log {"bodyKeys":["type"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"创建备份账号 [type]","formatEN":"create backup account [type]"}
|
2022-09-16 10:53:45 +00:00
|
|
|
func (b *BaseApi) CreateBackup(c *gin.Context) {
|
|
|
|
var req dto.BackupOperate
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := backupService.Create(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags Backup Account
|
2023-01-05 03:57:03 +00:00
|
|
|
// @Summary List buckets
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Description 获取 bucket 列表
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.ForBuckets true "request"
|
|
|
|
// @Success 200 {anrry} string
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /backups/search [post]
|
2022-09-16 10:53:45 +00:00
|
|
|
func (b *BaseApi) ListBuckets(c *gin.Context) {
|
|
|
|
var req dto.ForBuckets
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
buckets, err := backupService.GetBuckets(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, buckets)
|
|
|
|
}
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags Backup Account
|
|
|
|
// @Summary Delete backup account
|
|
|
|
// @Description 删除备份账号
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.BatchDeleteReq true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /backups/del [post]
|
|
|
|
// @x-panel-log {"bodyKeys":["ids"],"paramKeys":[],"BeforeFuntions":[{"input_colume":"id","input_value":"ids","isList":true,"db":"backup_accounts","output_colume":"type","output_value":"types"}],"formatZH":"删除备份账号 [types]","formatEN":"delete backup account [types]"}
|
2022-09-16 10:53:45 +00:00
|
|
|
func (b *BaseApi) DeleteBackup(c *gin.Context) {
|
|
|
|
var req dto.BatchDeleteReq
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := backupService.BatchDelete(req.Ids); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags Backup Account
|
2023-01-05 03:57:03 +00:00
|
|
|
// @Summary Page backup records
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Description 获取备份记录列表分页
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.RecordSearch true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /backups/record/search [post]
|
2022-11-29 09:39:10 +00:00
|
|
|
func (b *BaseApi) SearchBackupRecords(c *gin.Context) {
|
|
|
|
var req dto.RecordSearch
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
total, list, err := backupService.SearchRecordsWithPage(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
helper.SuccessWithData(c, dto.PageResult{
|
|
|
|
Items: list,
|
|
|
|
Total: total,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags Backup Account
|
|
|
|
// @Summary Download backup record
|
|
|
|
// @Description 下载备份记录
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.DownloadRecord true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /backups/record/download [post]
|
|
|
|
// @x-panel-log {"bodyKeys":["source","fileName"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"下载备份记录 [source][fileName]","formatEN":"download backup records [source][fileName]"}
|
2022-10-28 03:02:47 +00:00
|
|
|
func (b *BaseApi) DownloadRecord(c *gin.Context) {
|
|
|
|
var req dto.DownloadRecord
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
filePath, err := backupService.DownloadRecord(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
c.File(filePath)
|
|
|
|
}
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags Backup Account
|
|
|
|
// @Summary Delete backup record
|
|
|
|
// @Description 删除备份记录
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.BatchDeleteReq true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /backups/record/del [post]
|
|
|
|
// @x-panel-log {"bodyKeys":["ids"],"paramKeys":[],"BeforeFuntions":[{"input_colume":"id","input_value":"ids","isList":true,"db":"backup_records","output_colume":"file_name","output_value":"files"}],"formatZH":"删除备份记录 [files]","formatEN":"delete backup records [files]"}
|
2022-10-27 15:09:39 +00:00
|
|
|
func (b *BaseApi) DeleteBackupRecord(c *gin.Context) {
|
|
|
|
var req dto.BatchDeleteReq
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := backupService.BatchDeleteRecord(req.Ids); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags Backup Account
|
|
|
|
// @Summary Update backup account
|
|
|
|
// @Description 更新备份账号信息
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.BackupOperate true "request"
|
|
|
|
// @Success 200
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /backups/update [post]
|
|
|
|
// @x-panel-log {"bodyKeys":["type"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"更新备份账号 [types]","formatEN":"update backup account [types]"}
|
2022-09-16 10:53:45 +00:00
|
|
|
func (b *BaseApi) UpdateBackup(c *gin.Context) {
|
|
|
|
var req dto.BackupOperate
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
2023-01-29 08:38:34 +00:00
|
|
|
if err := backupService.Update(req); err != nil {
|
2022-09-16 10:53:45 +00:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, nil)
|
|
|
|
}
|
|
|
|
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Tags Backup Account
|
2023-01-05 03:57:03 +00:00
|
|
|
// @Summary List backup accounts
|
2023-01-04 14:31:51 +00:00
|
|
|
// @Description 获取备份账号列表
|
|
|
|
// @Success 200 {anrry} dto.BackupInfo
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /backups/search [get]
|
2022-09-19 11:42:06 +00:00
|
|
|
func (b *BaseApi) ListBackup(c *gin.Context) {
|
|
|
|
data, err := backupService.List()
|
2022-09-16 10:53:45 +00:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-09-19 11:42:06 +00:00
|
|
|
helper.SuccessWithData(c, data)
|
2022-09-16 10:53:45 +00:00
|
|
|
}
|
2023-02-13 07:48:18 +00:00
|
|
|
|
|
|
|
// @Tags Backup Account
|
|
|
|
// @Summary List files from backup accounts
|
|
|
|
// @Description 获取备份账号内文件列表
|
|
|
|
// @Accept json
|
|
|
|
// @Param request body dto.BackupSearchFile true "request"
|
|
|
|
// @Success 200 {anrry} string
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Router /backups/search/files [post]
|
|
|
|
func (b *BaseApi) LoadFilesFromBackup(c *gin.Context) {
|
|
|
|
var req dto.BackupSearchFile
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := global.VALID.Struct(req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
data, err := backupService.ListFiles(req)
|
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
helper.SuccessWithData(c, data)
|
|
|
|
}
|