use toml.DateTime; fix metadata.toml writing bug

This commit is contained in:
ari melody 2026-06-19 17:27:22 +01:00
parent dd54e8cc49
commit a3b9ec2cb6
Signed by: ari
GPG key ID: 60B5F0386E3DDB7E
2 changed files with 10 additions and 15 deletions

View file

@ -22,7 +22,7 @@ type (
Metadata struct {
Title string `toml:"title"`
Part int `toml:"part"`
Date string `toml:"date"`
Date toml.LocalDate `toml:"date"`
Tags []string `toml:"tags"`
FootageDir string `toml:"footage_dir"`
Uploaded bool `toml:"uploaded"`
@ -107,20 +107,20 @@ func ReadMetadata(directory string) (*Metadata, error) {
}
func WriteMetadata(directory string, metadata *Metadata) (error) {
file, err := os.OpenFile(
path.Join(directory, METADATA_FILENAME),
os.O_CREATE | os.O_RDWR, 0644,
)
data, err := toml.Marshal(metadata)
if err != nil { return err }
err = toml.NewEncoder(file).Encode(metadata)
err = os.WriteFile(path.Join(directory, METADATA_FILENAME), data, 0644)
return err
}
func DefaultMetadata() *Metadata {
return &Metadata{
Title: "Untitled Stream",
Date: time.Now().Format("2006-01-02"),
Date: toml.LocalDate{
Year: time.Now().Year(),
Month: int(time.Now().Month()),
Day: time.Now().Day(),
},
Part: 0,
Category: &Category{
Name: "Something",