| 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 App struct { |
| 16 | DB *sql.DB |
| 17 | Log *slog.Logger |
| 18 | Templates *template.Template |
| 19 | Sessions *auth.Store |
| 20 | AdminPassword string |
| 21 | APIKey string |
| 22 | CookieSecure bool |
| 23 | BaseURL string |
| 24 | DefaultPollMinutes int |
| 25 | ItemCap int |
| 26 | } |
| 27 | |
| 28 | type templateItem struct { |
| 29 | Title string |
| 30 | Link string |
| 31 | Author string |
| 32 | FormattedDate string |
| 33 | } |
| 34 | |
| 35 | type adminSubRow struct { |
| 36 | ID int64 |
| 37 | Title string |
| 38 | FeedURL string |
| 39 | SiteURL string |
| 40 | CategoryName string |
| 41 | LastFetchedAt string |
| 42 | LastError string |
| 43 | } |
| 44 | |
| 45 | type indexPageData struct { |
| 46 | BaseURL string |
| 47 | Items []templateItem |
| 48 | FeedURLs []string |
| 49 | Error string |
| 50 | } |
| 51 | |
| 52 | type loginPageData struct { |
| 53 | Error string |
| 54 | } |
| 55 | |
| 56 | type adminPageData struct { |
| 57 | Success string |
| 58 | Error string |
| 59 | Subscriptions []adminSubRow |
| 60 | Categories []Category |
| 61 | PollIntervalMinutes int |
| 62 | ItemCap int |
| 63 | APIKeyConfigured bool |
| 64 | } |
| 65 | |
| 66 | type createSubscriptionBody struct { |
| 67 | FeedURL string `json:"feed_url"` |
| 68 | Title string `json:"title"` |
| 69 | CategoryID *int64 `json:"category_id"` |
| 70 | CategoryName string `json:"category_name"` |
| 71 | } |
| 72 | |
| 73 | type updateSubscriptionBody struct { |
| 74 | CategoryID *int64 `json:"category_id"` |
| 75 | CategoryName string `json:"category_name"` |
| 76 | ClearCategory bool `json:"clear_category"` |
| 77 | } |
| 78 | |
| 79 | type createCategoryBody struct { |
| 80 | Name string `json:"name"` |
| 81 | } |
| 82 | |
| 83 | type updateSettingsBody struct { |
| 84 | PollIntervalMinutes *int `json:"poll_interval_minutes"` |
| 85 | } |
| 86 | |
| 87 | type discoverBody struct { |
| 88 | BaseURL string `json:"base_url"` |
| 89 | } |
| 90 | |
| 91 | type importSummary struct { |
| 92 | Imported int `json:"imported"` |
| 93 | Skipped int `json:"skipped"` |
| 94 | Failed []string `json:"failed"` |
| 95 | } |
| 96 | |
| 97 | type subscriptionView struct { |
| 98 | ID int64 `json:"id"` |
| 99 | FeedURL string `json:"feed_url"` |
| 100 | Title string `json:"title"` |
| 101 | SiteURL *string `json:"site_url,omitempty"` |
| 102 | FaviconURL *string `json:"favicon_url,omitempty"` |
| 103 | CategoryID *int64 `json:"category_id,omitempty"` |
| 104 | ETag *string `json:"etag,omitempty"` |
| 105 | LastModified *string `json:"last_modified,omitempty"` |
| 106 | LastFetchedAt *string `json:"last_fetched_at,omitempty"` |
| 107 | LastError *string `json:"last_error,omitempty"` |
| 108 | AddedAt string `json:"added_at"` |
| 109 | } |