feat: snapshot upload async allows restore

This commit is contained in:
Harivansh Rathi 2026-04-10 22:48:45 +00:00
parent 30282928f5
commit 1e7829a974
3 changed files with 108 additions and 0 deletions

View file

@ -14,6 +14,7 @@ import (
"golang.org/x/sync/errgroup"
"github.com/getcompanion-ai/computer-host/internal/firecracker"
"github.com/getcompanion-ai/computer-host/internal/httpapi"
"github.com/getcompanion-ai/computer-host/internal/model"
"github.com/getcompanion-ai/computer-host/internal/store"
contracthost "github.com/getcompanion-ai/computer-host/contract"
@ -441,6 +442,37 @@ func (d *Daemon) GetSnapshot(ctx context.Context, snapshotID contracthost.Snapsh
return &contracthost.GetSnapshotResponse{Snapshot: snapshotToContract(*snap)}, nil
}
func (d *Daemon) GetSnapshotArtifact(ctx context.Context, snapshotID contracthost.SnapshotID, artifactID string) (*httpapi.SnapshotArtifactContent, error) {
snapshot, err := d.store.GetSnapshot(ctx, snapshotID)
if err != nil {
return nil, err
}
artifactID = strings.TrimSpace(artifactID)
if artifactID == "" {
return nil, fmt.Errorf("snapshot artifact id is required")
}
for _, artifact := range snapshot.Artifacts {
if artifact.ID != artifactID {
continue
}
path := strings.TrimSpace(artifact.LocalPath)
if path == "" {
return nil, fmt.Errorf("snapshot %q artifact %q not found", snapshotID, artifactID)
}
if _, err := os.Stat(path); err != nil {
if os.IsNotExist(err) {
return nil, fmt.Errorf("snapshot %q artifact %q not found", snapshotID, artifactID)
}
return nil, fmt.Errorf("stat snapshot %q artifact %q: %w", snapshotID, artifactID, err)
}
return &httpapi.SnapshotArtifactContent{
Name: artifact.Name,
Path: path,
}, nil
}
return nil, fmt.Errorf("snapshot %q artifact %q not found", snapshotID, artifactID)
}
func (d *Daemon) ListSnapshots(ctx context.Context, machineID contracthost.MachineID) (*contracthost.ListSnapshotsResponse, error) {
records, err := d.store.ListSnapshotsByMachine(ctx, machineID)
if err != nil {