71 lines
2.7 KiB
Go
71 lines
2.7 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
type renderedCampaignInputs struct {
|
|
SpeakersFile string `yaml:"speakers_file,omitempty"`
|
|
AutocorrectFile string `yaml:"autocorrect_file,omitempty"`
|
|
GlossaryFile string `yaml:"glossary_file,omitempty"`
|
|
PartyFile string `yaml:"party_file,omitempty"`
|
|
SpellCatalogFile string `yaml:"spell_catalog_file,omitempty"`
|
|
}
|
|
|
|
// RenderCampaignDocument serializes the loaded effective campaign document.
|
|
func RenderCampaignDocument(cfg *Config) ([]byte, error) {
|
|
if cfg == nil {
|
|
return nil, fmt.Errorf("campaign document is required")
|
|
}
|
|
doc := cfg.CampaignDocument
|
|
if doc == nil {
|
|
doc = cfg.Campaign
|
|
}
|
|
if doc == nil {
|
|
return nil, fmt.Errorf("campaign document is required")
|
|
}
|
|
value := struct {
|
|
CampaignID string `yaml:"campaign_id"`
|
|
SessionTemplateFile string `yaml:"session_template_file,omitempty"`
|
|
Inputs renderedCampaignInputs `yaml:"inputs"`
|
|
}{doc.CampaignID, doc.SessionTemplateFile, renderedCampaignInputs{
|
|
doc.Inputs.SpeakersFile, doc.Inputs.AutocorrectFile, doc.Inputs.GlossaryFile, doc.Inputs.PartyFile, doc.Inputs.SpellCatalogFile,
|
|
}}
|
|
return yaml.Marshal(value)
|
|
}
|
|
|
|
// RenderSessionDocument serializes the session's own fields and actual identity.
|
|
func RenderSessionDocument(cfg *Config, sessionID string) ([]byte, error) {
|
|
if cfg == nil || cfg.Session == nil {
|
|
return nil, fmt.Errorf("session document is required")
|
|
}
|
|
doc := cfg.SessionDocument
|
|
if doc == nil {
|
|
doc = cfg.Session
|
|
}
|
|
id := cfg.Session.SessionID
|
|
if id == "" {
|
|
id = sessionID
|
|
}
|
|
inputs := struct {
|
|
AudioDir string `yaml:"audio_dir,omitempty"`
|
|
AudioFiles []string `yaml:"audio_files,omitempty"`
|
|
AudioS3 *SessionAudioS3Input `yaml:"audio_s3,omitempty"`
|
|
SpeakersFile string `yaml:"speakers_file,omitempty"`
|
|
AutocorrectFile string `yaml:"autocorrect_file,omitempty"`
|
|
GlossaryFile string `yaml:"glossary_file,omitempty"`
|
|
SpellCatalogFile string `yaml:"spell_catalog_file,omitempty"`
|
|
}{doc.Inputs.AudioDir, doc.Inputs.AudioFiles, doc.Inputs.AudioS3, doc.Inputs.SpeakersFile, doc.Inputs.AutocorrectFile, doc.Inputs.GlossaryFile, doc.Inputs.SpellCatalogFile}
|
|
value := struct {
|
|
SessionID string `yaml:"session_id"`
|
|
PreviousSessionID string `yaml:"previous_session_id,omitempty"`
|
|
Campaign string `yaml:"campaign,omitempty"`
|
|
Date string `yaml:"date,omitempty"`
|
|
Title string `yaml:"title,omitempty"`
|
|
Inputs any `yaml:"inputs"`
|
|
}{id, cfg.Session.PreviousSessionID, cfg.Session.Campaign, doc.Date, doc.Title, inputs}
|
|
return yaml.Marshal(value)
|
|
}
|