Diffstat (limited to 'internal/storage/index.go')
| -rw-r--r-- | internal/storage/index.go | 92 |
1 files changed, 0 insertions, 92 deletions
diff --git a/internal/storage/index.go b/internal/storage/index.go deleted file mode 100644 index bfeafbe..0000000 --- a/internal/storage/index.go +++ /dev/null @@ -1,92 +0,0 @@ -package storage - -import ( - "encoding/json" - "fmt" - "time" -) - -const IndexFileName = "index.json" -const MedleysIndexFileName = "medleys.json" - -const IndexSchemaVersion = 2 - -type IndexEntry struct { - Link string `json:"link"` - ModifiedTime time.Time `json:"modifiedTime"` - Title string `json:"title"` - ShortDescription string `json:"shortDescription"` - ActionDate string `json:"actionDate"` - PublishedTime time.Time `json:"publishedTime"` - Thumbnail string `json:"thumbnail"` - Tags []string `json:"tags"` - Geolocation string `json:"geolocation"` - Medley string `json:"medley,omitempty"` - MedleyPart int `json:"medleyPart,omitempty"` -} - -type IndexV2Category struct { - GeneratedAt time.Time `json:"generatedAt"` - Pages map[string]IndexEntry `json:"pages"` -} - -type IndexV1Category struct { - GeneratedAt time.Time `json:"generatedAt"` - Pages []IndexEntry `json:"pages"` -} - -type Index struct { - SchemaVersion int `json:"schemaVersion"` - GeneratedAt time.Time `json:"generatedAt"` - Categories any `json:"categories"` -} - -func (idx *Index) UnmarshalJSON(data []byte) error { - var tmp struct { - SchemaVersion int `json:"schemaVersion"` - GeneratedAt time.Time `json:"generatedAt"` - Categories json.RawMessage `json:"categories"` - } - - if err := json.Unmarshal(data, &tmp); err != nil { - return err - } - - idx.SchemaVersion = tmp.SchemaVersion - idx.GeneratedAt = tmp.GeneratedAt - - switch tmp.SchemaVersion { - case 1: - var categories map[string]*IndexV1Category - if err := json.Unmarshal(tmp.Categories, &categories); err != nil { - return fmt.Errorf("unmarshal map[string]*IndexV1Category: %w", err) - } - idx.Categories = &categories - case 2: - var categories map[string]*IndexV2Category - if err := json.Unmarshal(tmp.Categories, &categories); err != nil { - return fmt.Errorf("unmarshal map[string]*IndexV2Category: %w", err) - } - idx.Categories = &categories - default: - return fmt.Errorf("unsupported index version: %d", tmp.SchemaVersion) - } - - return nil -} - -type IndexV1 struct { - SchemaVersion int `json:"schemaVersion"` - GeneratedAt time.Time `json:"generatedAt"` - Categories map[string]*IndexV1Category `json:"categories"` -} - -type MedleyEntry struct { - Codename string `json:"codename"` - Content []string `json:"content"` -} - -type MedleyPageEntry struct { - Codename string `json:"codename"` - Position int `json:"position"` -} |