Share transcript envelope validation
This commit is contained in:
@@ -3,6 +3,7 @@ package seriatim
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -10,6 +11,7 @@ import (
|
||||
"unicode/utf8"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/subprocess"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/contracts"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/fileops"
|
||||
)
|
||||
|
||||
@@ -659,19 +661,12 @@ func validateJSONFileWithSegments(path string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
var payload map[string]any
|
||||
if err := json.Unmarshal(data, &payload); err != nil {
|
||||
return fmt.Errorf("parse json: %w", err)
|
||||
err = contracts.ValidateTranscriptEnvelope(data)
|
||||
var decode *contracts.TranscriptDecodeError
|
||||
if errors.As(err, &decode) {
|
||||
return fmt.Errorf("parse json: %w", decode.Err)
|
||||
}
|
||||
|
||||
segments, ok := payload["segments"]
|
||||
if !ok {
|
||||
return fmt.Errorf("top-level segments is required")
|
||||
}
|
||||
if _, ok := segments.([]any); !ok {
|
||||
return fmt.Errorf("top-level segments must be an array")
|
||||
}
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
func validateNonEmptyTextFile(path string) error {
|
||||
|
||||
Reference in New Issue
Block a user