| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "database/sql" |
| 5 | "embed" |
| 6 | "html/template" |
| 7 | "log/slog" |
| 8 | |
| 9 | "github.com/stevedylandev/andromeda/pkg/auth" |
| 10 | ) |
| 11 | |
| 12 | //go:embed templates/*.html static/* |
| 13 | var appFS embed.FS |
| 14 | |
| 15 | type DisplayMode int |
| 16 | |
| 17 | const ( |
| 18 | DisplayModeInline DisplayMode = iota |
| 19 | DisplayModeNav |
| 20 | ) |
| 21 | |
| 22 | func parseDisplayMode(s string) DisplayMode { |
| 23 | if s == "nav" { |
| 24 | return DisplayModeNav |
| 25 | } |
| 26 | return DisplayModeInline |
| 27 | } |
| 28 | |
| 29 | type App struct { |
| 30 | DB *sql.DB |
| 31 | Log *slog.Logger |
| 32 | Templates *template.Template |
| 33 | Sessions *auth.Store |
| 34 | AdminPassword string |
| 35 | GoogleBooksKey string |
| 36 | CookieSecure bool |
| 37 | BaseURL string |
| 38 | DisplayMode DisplayMode |
| 39 | } |
| 40 | |
| 41 | type bookView struct { |
| 42 | Title string |
| 43 | Authors string |
| 44 | CoverURL string |
| 45 | Notes string |
| 46 | } |
| 47 | |
| 48 | type sectionView struct { |
| 49 | Label string |
| 50 | Books []bookView |
| 51 | } |
| 52 | |
| 53 | type navCategory struct { |
| 54 | Slug string |
| 55 | Label string |
| 56 | Active bool |
| 57 | } |
| 58 | |
| 59 | type indexPageData struct { |
| 60 | BaseURL string |
| 61 | Sections []sectionView |
| 62 | NavMode bool |
| 63 | NavCategories []navCategory |
| 64 | } |
| 65 | |
| 66 | type loginPageData struct { |
| 67 | Error string |
| 68 | } |
| 69 | |
| 70 | type adminBookRow struct { |
| 71 | ID int64 |
| 72 | Title string |
| 73 | Authors string |
| 74 | ISBN string |
| 75 | CoverURL string |
| 76 | Notes string |
| 77 | Status string |
| 78 | } |
| 79 | |
| 80 | type adminPageData struct { |
| 81 | Success string |
| 82 | Error string |
| 83 | Books []adminBookRow |
| 84 | Labels CategoryLabels |
| 85 | LibraryQuery string |
| 86 | LibraryResults []adminBookRow |
| 87 | LibrarySearched bool |
| 88 | } |