Allow server to make backups
This commit is contained in:
parent
aeceae11d5
commit
b3a827e042
27 changed files with 891 additions and 418 deletions
73
internal/component/info/socket.go
Normal file
73
internal/component/info/socket.go
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
package info
|
||||
|
||||
import (
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/component/snapshots"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/httpx"
|
||||
"github.com/tkw1536/goprogram/status"
|
||||
"github.com/tkw1536/goprogram/stream"
|
||||
)
|
||||
|
||||
func (info *Info) serveSocket(conn httpx.WebSocketConnection) {
|
||||
// read the next message to act on
|
||||
message, ok := <-conn.Read()
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
switch string(message.Bytes) {
|
||||
case "snapshot":
|
||||
slug, ok := <-conn.Read()
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
info.serverSocketSnapshot(string(slug.Bytes), info.socketWriter(conn))
|
||||
}
|
||||
}
|
||||
|
||||
func (*Info) socketWriter(conn httpx.WebSocketConnection) *status.LineBuffer {
|
||||
return &status.LineBuffer{
|
||||
Line: func(line string) {
|
||||
<-conn.WriteText(line)
|
||||
},
|
||||
FlushLineOnClose: true,
|
||||
}
|
||||
}
|
||||
|
||||
func (info *Info) serverSocketSnapshot(slug string, writer *status.LineBuffer) {
|
||||
stream := stream.NewIOStream(writer, writer, nil, 0)
|
||||
|
||||
// get the wisski
|
||||
wissKI, err := info.Instances.WissKI(slug)
|
||||
if err != nil {
|
||||
stream.EPrintln(err)
|
||||
return
|
||||
}
|
||||
|
||||
{
|
||||
err := info.SnapshotManager.HandleSnapshotLike(
|
||||
stream,
|
||||
snapshots.SnapshotFlags{
|
||||
Dest: "",
|
||||
Slug: slug,
|
||||
Title: "Snapshot",
|
||||
StagingOnly: false,
|
||||
Do: func(dest string) snapshots.SnapshotLike {
|
||||
snapshot := info.SnapshotManager.NewSnapshot(
|
||||
wissKI,
|
||||
stream,
|
||||
snapshots.SnapshotDescription{
|
||||
Dest: dest,
|
||||
},
|
||||
)
|
||||
return &snapshot
|
||||
},
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
stream.EPrintln(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
stream.Println("Done")
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue