A tool for archiving & converting scans of postcards, and information about them.

fix: Prevent empty fields from appearing in YAML

Some Metadata fields were implemented with non-nilable types, meaning they always appeared in YAML, even when not needed. This was confusing, so this allows them to be absent.

+17 -15
+1 -1
formats/xmp/decode.go
··· 111 111 json.Unmarshal([]byte(js.Models.Postcard.TranscriptionBack), &meta.Back.Transcription) 112 112 113 113 if date, err := time.Parse(`2006-01-02`, js.Models.EXIF.Date); err == nil { 114 - meta.SentOn = types.Date{Time: date} 114 + meta.SentOn = &types.Date{Time: date} 115 115 } 116 116 meta.Location.Name = js.Models.EXIF.LocationName 117 117 meta.Location.Latitude = scanDegrees(js.Models.EXIF.Latitude)
+9 -7
formats/xmp/exif.go
··· 23 23 return sections 24 24 } 25 25 26 - yy, mm, dd := meta.SentOn.Date() 27 - 28 26 exif := xmpExif{ 29 - Namespace: "http://ns.adobe.com/exif/1.0/", 30 - OriginalDateTime: fmt.Sprintf("%d-%02d-%02d", yy, mm, dd), 31 - Placename: meta.Location.Name, 32 - Latitude: fmtEXIFDegrees(meta.Location.Latitude, true), 33 - Longitude: fmtEXIFDegrees(meta.Location.Longitude, false), 27 + Namespace: "http://ns.adobe.com/exif/1.0/", 28 + Placename: meta.Location.Name, 29 + Latitude: fmtEXIFDegrees(meta.Location.Latitude, true), 30 + Longitude: fmtEXIFDegrees(meta.Location.Longitude, false), 31 + } 32 + 33 + if meta.SentOn != nil { 34 + yy, mm, dd := meta.SentOn.Date() 35 + exif.OriginalDateTime = fmt.Sprintf("%d-%02d-%02d", yy, mm, dd) 34 36 } 35 37 36 38 return append(sections, exif)
+1 -1
internal/testhelpers/fixtures.go
··· 49 49 Longitude: &([]float64{7.66}[0]), 50 50 }, 51 51 Flip: types.FlipBook, 52 - SentOn: types.Date{ 52 + SentOn: &types.Date{ 53 53 Time: time.Date(2006, time.January, 2, 0, 0, 0, 0, time.UTC), 54 54 }, 55 55 Sender: types.Person{
+1 -1
pkg/postoffice/http.go
··· 103 103 ) 104 104 105 105 if t, err := time.Parse(`2006-01-02`, r.FormValue("sent-on")); err == nil { 106 - meta.SentOn = types.Date{Time: t} 106 + meta.SentOn = &types.Date{Time: t} 107 107 } 108 108 109 109 meta.Sender.Scan(r.FormValue("sender"))
+1 -1
types/person.go
··· 7 7 ) 8 8 9 9 type Person struct { 10 - Name string `json:"name"` 10 + Name string `json:"name,omitempty"` 11 11 Uri string `json:"uri,omitempty" yaml:"link,omitempty"` 12 12 } 13 13
+4 -4
types/postcard.go
··· 94 94 Name string `json:"-" yaml:"-"` 95 95 HasTransparency bool `json:"-" yaml:"-"` 96 96 97 - Locale string `json:"locale,omitempty"` 97 + Locale string `json:"locale,omitempty" yaml:"locale,omitempty"` 98 98 Location Location `json:"location,omitempty" yaml:"location,omitempty"` 99 - Flip Flip `json:"flip" yaml:"flip"` 100 - SentOn Date `json:"sentOn,omitempty" yaml:"sent_on,omitempty"` 99 + Flip Flip `json:"flip,omitempty" yaml:"flip,omitempty"` 100 + SentOn *Date `json:"sentOn,omitempty" yaml:"sent_on,omitempty"` 101 101 Sender Person `json:"sender,omitempty" yaml:"sender,omitempty"` 102 102 Recipient Person `json:"recipient,omitempty" yaml:"recipient,omitempty"` 103 103 Front Side `json:"front,omitempty" yaml:"front,omitempty"` ··· 107 107 } 108 108 109 109 type Physical struct { 110 - FrontDimensions Size `json:"frontSize" yaml:"front_size,omitempty"` 110 + FrontDimensions Size `json:"frontSize,omitempty" yaml:"front_size,omitempty"` 111 111 ThicknessMM float64 `json:"thicknessMM,omitempty" yaml:"thickness_mm,omitempty"` 112 112 } 113 113