4006dca9f5
CI / test (push) Successful in 12s
Campaign content and listmonk credentials now live in separate per-domain repos that install this tool at a pinned version, so a client with access to one domain's content repo has no path to another domain's secrets. Renames the module to the actual Gitea host path so `go install` works without vanity-import redirects, drops the four workflows that assumed campaigns/ content lived here, adds real go-test CI, and rewrites the README for the tool's new audience. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package campaign
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"gitea.reground.org/will/eec-campaigns/internal/listmonk"
|
|
)
|
|
|
|
// SyncTemplate pushes a template file's content into listmonk under name,
|
|
// creating it (as the default campaign template) if missing or overwriting
|
|
// its body if it already exists. Unlike campaign sync, a template has no
|
|
// send-lifecycle status to protect — there's no "draft vs. live" distinction
|
|
// to guard, so this is always a safe create-or-update, no rejection path.
|
|
func SyncTemplate(lm *listmonk.Client, name, path string) (*listmonk.Template, error) {
|
|
body, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
existing, err := lm.FindTemplateByName(name)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if existing == nil {
|
|
created, err := lm.CreateTemplate(name, string(body), true)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("creating template %q: %w", name, err)
|
|
}
|
|
return created, nil
|
|
}
|
|
if err := lm.UpdateTemplate(existing.ID, name, string(body), true); err != nil {
|
|
return nil, fmt.Errorf("updating template %q: %w", name, err)
|
|
}
|
|
existing.Body = string(body)
|
|
existing.IsDefault = true
|
|
return existing, nil
|
|
}
|