Report audio, speaker, and artifact work progress
This commit is contained in:
@@ -11,10 +11,12 @@ import (
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/fileops"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/logging"
|
||||
)
|
||||
|
||||
// S3MaterializeRequest describes one S3-backed audio materialization.
|
||||
type S3MaterializeRequest struct {
|
||||
Reporter logging.Reporter
|
||||
Store storage.ObjectStore
|
||||
Object storage.ObjectInfo
|
||||
Bucket string
|
||||
@@ -50,6 +52,9 @@ func MaterializeS3Audio(ctx context.Context, req S3MaterializeRequest) (S3Materi
|
||||
return S3MaterializeResult{}, fmt.Errorf("destination path is required")
|
||||
}
|
||||
|
||||
if req.Reporter != nil {
|
||||
req.Reporter.Info("selected audio source", "bucket", req.Bucket, "key", key, "destination", req.DestPath)
|
||||
}
|
||||
result := S3MaterializeResult{}
|
||||
if req.CacheEnabled && cacheIdentityEligible(req) {
|
||||
cachePath, err := artifacts.S3AudioCachePath(req.CacheRoot, req.Bucket, key)
|
||||
@@ -62,6 +67,9 @@ func MaterializeS3Audio(ctx context.Context, req S3MaterializeRequest) (S3Materi
|
||||
} else if ok {
|
||||
result.Checksum = checksum
|
||||
result.CacheHit = true
|
||||
if req.Reporter != nil {
|
||||
req.Reporter.Progress("reusing cached audio", "audio", filepath.Base(req.DestPath))
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
}
|
||||
@@ -70,7 +78,7 @@ func MaterializeS3Audio(ctx context.Context, req S3MaterializeRequest) (S3Materi
|
||||
if spoolPath == "" {
|
||||
return S3MaterializeResult{}, fmt.Errorf("spool path is required for s3 audio download")
|
||||
}
|
||||
if err := downloadObjectAtomic(ctx, req.Store, key, spoolPath, req.Object.Size); err != nil {
|
||||
if err := downloadObjectAtomic(ctx, req.Store, key, spoolPath, req.Object.Size, req.Reporter); err != nil {
|
||||
return S3MaterializeResult{}, fmt.Errorf("download s3 audio object %q: %w", key, err)
|
||||
}
|
||||
|
||||
@@ -115,8 +123,11 @@ func validateLocalAudio(path string, expectedSize int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func downloadObjectAtomic(ctx context.Context, store storage.ObjectStore, key, destPath string, expectedSize int64) error {
|
||||
func downloadObjectAtomic(ctx context.Context, store storage.ObjectStore, key, destPath string, expectedSize int64, reporter logging.Reporter) error {
|
||||
temporaryPath, err := writeAudioTemp(destPath, func(destination io.Writer) error {
|
||||
if reporter != nil {
|
||||
reporter.Progress("downloading audio", "audio", filepath.Base(destPath))
|
||||
}
|
||||
return storage.DownloadTo(ctx, store, key, destination)
|
||||
})
|
||||
if err != nil {
|
||||
@@ -129,6 +140,9 @@ func downloadObjectAtomic(ctx context.Context, store storage.ObjectStore, key, d
|
||||
if err := fileops.InstallSiblingTempFile(temporaryPath, destPath, fileops.WorkspaceFileMode); err != nil {
|
||||
return err
|
||||
}
|
||||
if reporter != nil {
|
||||
reporter.Progress("audio downloaded", "audio", filepath.Base(destPath))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user