| 1 | package memoria |
| 2 | |
| 3 | import ( |
| 4 | _ "embed" |
| 5 | "encoding/json" |
| 6 | "net/http" |
| 7 | |
| 8 | "amadan.net/oficina/estilo.git/credits" |
| 9 | ) |
| 10 | |
| 11 | //go:embed credits/notices.json |
| 12 | var creditNotices []byte |
| 13 | |
| 14 | type creditInventory struct { |
| 15 | Components []credits.Component `json:"components"` |
| 16 | MissingNotices []string `json:"missing_notices"` |
| 17 | } |
| 18 | |
| 19 | var embeddedCredits = func() creditInventory { |
| 20 | var inventory creditInventory |
| 21 | if err := json.Unmarshal(creditNotices, &inventory); err != nil { |
| 22 | panic(err) |
| 23 | } |
| 24 | return inventory |
| 25 | }() |
| 26 | |
| 27 | func (a *app) credits(w http.ResponseWriter, r *http.Request) { |
| 28 | w.Header().Set("Content-Type", "text/html; charset=utf-8") |
| 29 | w.Header().Set("Cache-Control", "no-store") |
| 30 | // strict-origin, not no-referrer (spec §9.5): this page shows the |
| 31 | // account menu, and with Home a Sign out from here is a POST chained |
| 32 | // to id.*, which admits it by Referer — no-referrer strips it and the |
| 33 | // sign-out lands on "Finish signing out". strict-origin still never |
| 34 | // sends a path, and the credit links carry their own no-referrer. |
| 35 | w.Header().Set("Referrer-Policy", "strict-origin") |
| 36 | render(w, "credits", creditsPage{ |
| 37 | page: a.pageFor(r, titled("Open source")), |
| 38 | Data: credits.PageData{Title: "Open source", MissingNoticeLabel: "No notice file is included in this release.", Components: embeddedCredits.Components}, |
| 39 | }) |
| 40 | } |
| 41 | |
| 42 | type creditsPage struct { |
| 43 | page |
| 44 | Data credits.PageData |
| 45 | } |
| 46 | |
| 47 | func serveCreditsCSS(w http.ResponseWriter, r *http.Request) { |
| 48 | w.Header().Set("Content-Type", "text/css; charset=utf-8") |
| 49 | w.Header().Set("Cache-Control", "no-cache") |
| 50 | w.Write(credits.CSS()) |
| 51 | } |
| 52 | |