package musicfs import ( "context" "fmt" "io" "github.com/rs/zerolog/log" pb "homelab.lan/music-agregator/gen/musicfs/v1" ) type SyncedFile struct { Path string FileID int64 VirtualPath string } type RescanResult struct { NewFiles []SyncedFile BytesSynced uint64 } func (c *Client) TriggerRescan(ctx context.Context, originID string, subdir string) (*RescanResult, error) { stream, err := c.MusicFS.RescanOrigin(ctx, &pb.OriginRequest{ OriginId: originID, Subdir: &subdir, }) if err != nil { return nil, fmt.Errorf("rescan origin: %w", err) } var result RescanResult for { progress, err := stream.Recv() if err == io.EOF { break } if err != nil { return nil, fmt.Errorf("rescan stream: %w", err) } log.Trace(). Str("phase", progress.GetPhase()). Uint32("current", progress.GetCurrent()). Uint32("total", progress.GetTotal()). Msg("rescan progress") if progress.GetPhase() == "complete" { for _, sf := range progress.GetNewFiles() { result.NewFiles = append(result.NewFiles, SyncedFile{ Path: sf.GetPath(), FileID: sf.GetFileId(), VirtualPath: sf.GetVirtualPath(), }) } result.BytesSynced = progress.GetBytesSynced() } } return &result, nil }