release / go (push) Successful in 2m7s
release / web (push) Successful in 1m25s
release / govulncheck (push) Successful in 21s
release / integration (push) Successful in 4m30s
release / android (push) Successful in 4m39s
release / Build signed APK (push) Successful in 5m10s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 29s
release / Verify release artifacts (tag releases only) (push) Skipped
- Module path: github.com/Fabled-Sword/minstrel, in go.mod, every import and the Dockerfile's version ldflags. - buildinfo.ProjectURL, the contact outside services see in Minstrel's User-Agent: https://github.com/Fabled-Sword/minstrel. - README's compose example pulls ghcr.io/fabled-sword/minstrel:latest. - docs/security.md sends problem reports to the GitHub issues. - The demo-library stack builds Minstrel from the checkout, since :dev is not published to GHCR. - hygiene.go's same-site example uses example.com names. The workbench CI (.gitea/, ci/, export-ignored) still builds and publishes :dev to the private registry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
114 lines
3.0 KiB
Go
114 lines
3.0 KiB
Go
package notifications
|
|
|
|
import (
|
|
"embed"
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/Fabled-Sword/minstrel/internal/mailer"
|
|
)
|
|
|
|
//go:embed templates/digest.txt templates/digest.html
|
|
var digestFS embed.FS
|
|
|
|
// digestEmail is one rendered email.
|
|
type digestEmail struct {
|
|
Subject string
|
|
Text string
|
|
HTML string
|
|
}
|
|
|
|
type digestLine struct {
|
|
Title string
|
|
Body string
|
|
URL string
|
|
}
|
|
|
|
type digestArtist struct {
|
|
Name string
|
|
URL string
|
|
Titles []digestLine
|
|
}
|
|
|
|
type digestVars struct {
|
|
Name string
|
|
Intro string
|
|
Items []digestLine
|
|
Artists []digestArtist
|
|
}
|
|
|
|
// renderDigest renders one group's email. base is the public address; with
|
|
// none set, the email still goes out, without links.
|
|
func renderDigest(group EmailGroup, name string, items []pendingItem, base string) (digestEmail, error) {
|
|
vars := digestVars{Name: name}
|
|
frame := mailer.Frame{Server: base, NotificationSettings: true}
|
|
var subject string
|
|
if group == EmailSummary {
|
|
vars.Artists = summaryArtists(items, base)
|
|
vars.Intro = "New in your library since the last summary:"
|
|
subject = "Minstrel: new music in your library"
|
|
frame.Heading = "New music in your library"
|
|
frame.Reason = "you chose to get new-music summaries by email"
|
|
} else {
|
|
for _, it := range items {
|
|
r := Render(it.Kind, it.Payload)
|
|
vars.Items = append(vars.Items, digestLine{Title: r.Title, Body: r.Body, URL: joinURL(base, r.Link)})
|
|
}
|
|
vars.Intro = "Here's what happened on Minstrel:"
|
|
subject = fmt.Sprintf("Minstrel: %d updates", len(items))
|
|
frame.Heading = fmt.Sprintf("%d updates", len(items))
|
|
if len(items) == 1 {
|
|
subject = "Minstrel: " + vars.Items[0].Title
|
|
frame.Heading = vars.Items[0].Title
|
|
}
|
|
frame.Reason = "you chose to get these notifications by email"
|
|
}
|
|
|
|
text, html, err := mailer.Render(digestFS, "templates/digest.txt", "templates/digest.html", vars, frame)
|
|
if err != nil {
|
|
return digestEmail{}, fmt.Errorf("render digest: %w", err)
|
|
}
|
|
return digestEmail{Subject: subject, Text: text, HTML: html}, nil
|
|
}
|
|
|
|
// summaryArtists groups new-music arrivals by artist, in the order each
|
|
// artist first arrived, with each artist's albums under them.
|
|
func summaryArtists(items []pendingItem, base string) []digestArtist {
|
|
var out []digestArtist
|
|
index := map[string]int{}
|
|
for _, it := range items {
|
|
var p Payload
|
|
_ = json.Unmarshal(it.Payload, &p)
|
|
for _, a := range p.Albums {
|
|
artist := a.Artist
|
|
if artist == "" {
|
|
artist = "Unknown artist"
|
|
}
|
|
i, ok := index[artist]
|
|
if !ok {
|
|
i = len(out)
|
|
index[artist] = i
|
|
out = append(out, digestArtist{Name: artist})
|
|
if a.ArtistID != "" {
|
|
out[i].URL = joinURL(base, "/artists/"+a.ArtistID)
|
|
}
|
|
}
|
|
link := "/"
|
|
if a.AlbumID != "" {
|
|
link = "/albums/" + a.AlbumID
|
|
}
|
|
out[i].Titles = append(out[i].Titles, digestLine{Title: a.Title, URL: joinURL(base, link)})
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
// joinURL is base followed by path, or "" when no public address is set.
|
|
func joinURL(base, path string) string {
|
|
if base == "" || path == "" {
|
|
return ""
|
|
}
|
|
return strings.TrimRight(base, "/") + path
|
|
}
|