Support data coming from the panel better
This commit is contained in:
parent
151b00de23
commit
1e2da95d26
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -46,3 +46,4 @@ test_*/
|
||||||
!.gitkeep
|
!.gitkeep
|
||||||
debug
|
debug
|
||||||
data/.states.json
|
data/.states.json
|
||||||
|
.DS_Store
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package router
|
package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/pterodactyl/wings/server"
|
"github.com/pterodactyl/wings/server"
|
||||||
"github.com/pterodactyl/wings/server/backup"
|
"github.com/pterodactyl/wings/server/backup"
|
||||||
|
@ -12,14 +14,27 @@ import (
|
||||||
func postServerBackup(c *gin.Context) {
|
func postServerBackup(c *gin.Context) {
|
||||||
s := GetServer(c.Param("server"))
|
s := GetServer(c.Param("server"))
|
||||||
|
|
||||||
data := &backup.LocalBackup{}
|
data := &backup.Request{}
|
||||||
c.BindJSON(&data)
|
c.BindJSON(&data)
|
||||||
|
|
||||||
|
switch data.Adapter {
|
||||||
|
case backup.LocalBackupAdapter:
|
||||||
|
adapter, err := data.NewLocalBackup()
|
||||||
|
if err != nil {
|
||||||
|
TrackedServerError(err, s).AbortWithServerError(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
go func(b *backup.LocalBackup, serv *server.Server) {
|
go func(b *backup.LocalBackup, serv *server.Server) {
|
||||||
if err := serv.BackupLocal(b); err != nil {
|
if err := serv.BackupLocal(b); err != nil {
|
||||||
zap.S().Errorw("failed to generate backup for server", zap.Error(err))
|
zap.S().Errorw("failed to generate backup for server", zap.Error(err))
|
||||||
}
|
}
|
||||||
}(data, s)
|
}(adapter, s)
|
||||||
|
case backup.S3BackupAdapter:
|
||||||
|
TrackedServerError(errors.New(fmt.Sprintf("unsupported backup adapter [%s] provided", data.Adapter)), s).AbortWithServerError(c)
|
||||||
|
default:
|
||||||
|
TrackedServerError(errors.New(fmt.Sprintf("unknown backup adapter [%s] provided", data.Adapter)), s).AbortWithServerError(c)
|
||||||
|
}
|
||||||
|
|
||||||
c.Status(http.StatusAccepted)
|
c.Status(http.StatusAccepted)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,35 @@
|
||||||
package backup
|
package backup
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
"github.com/pterodactyl/wings/api"
|
"github.com/pterodactyl/wings/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
LocalBackupAdapter = "local"
|
||||||
|
S3BackupAdapter = "s3"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Request struct {
|
||||||
|
Adapter string `json:"adapter"`
|
||||||
|
Uuid string `json:"uuid"`
|
||||||
|
IgnoredFiles []string `json:"ignored_files"`
|
||||||
|
PresignedUrl string `json:"presigned_url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generates a new local backup struct.
|
||||||
|
func (r *Request) NewLocalBackup() (*LocalBackup, error) {
|
||||||
|
if r.Adapter != LocalBackupAdapter {
|
||||||
|
return nil, errors.New(fmt.Sprintf("cannot create local backup using [%s] adapter", r.Adapter))
|
||||||
|
}
|
||||||
|
|
||||||
|
return &LocalBackup{
|
||||||
|
Uuid: r.Uuid,
|
||||||
|
IgnoredFiles: r.IgnoredFiles,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
type Backup interface {
|
type Backup interface {
|
||||||
// Returns the UUID of this backup as tracked by the panel instance.
|
// Returns the UUID of this backup as tracked by the panel instance.
|
||||||
Identifier() string
|
Identifier() string
|
||||||
|
|
Loading…
Reference in New Issue
Block a user