58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
package handlers
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/noderunners/nip05api/internal/nostr"
|
|
"github.com/noderunners/nip05api/internal/user"
|
|
)
|
|
|
|
func userResponse(u *user.User) map[string]any {
|
|
resp := map[string]any{
|
|
"pubkey": u.Pubkey,
|
|
"npub": nostr.HexToNpub(u.Pubkey),
|
|
"username": u.Username,
|
|
"subscription_type": string(u.SubscriptionType),
|
|
"is_active": u.IsActive,
|
|
"manual_username": u.ManualUsername,
|
|
"created_at": u.CreatedAt.UTC().Format(time.RFC3339),
|
|
}
|
|
if u.ExpiresAt != nil {
|
|
resp["expires_at"] = u.ExpiresAt.UTC().Format(time.RFC3339)
|
|
}
|
|
if u.DeactivatedAt != nil {
|
|
resp["deactivated_at"] = u.DeactivatedAt.UTC().Format(time.RFC3339)
|
|
}
|
|
return resp
|
|
}
|
|
|
|
func dmVars(u *user.User, domain, frontend string) map[string]string {
|
|
expires := "lifetime"
|
|
if u.ExpiresAt != nil {
|
|
expires = u.ExpiresAt.Format("2006-01-02")
|
|
}
|
|
return map[string]string{
|
|
"username": u.Username,
|
|
"npub": nostr.HexToNpub(u.Pubkey),
|
|
"pubkey": u.Pubkey,
|
|
"domain": domain,
|
|
"expires_at": expires,
|
|
"days_remaining": "",
|
|
"frontend_url": frontend,
|
|
"subscription_type": string(u.SubscriptionType),
|
|
}
|
|
}
|
|
|
|
func hookData(u *user.User, domain string) map[string]any {
|
|
d := map[string]any{
|
|
"pubkey": u.Pubkey,
|
|
"npub": nostr.HexToNpub(u.Pubkey),
|
|
"username": u.Username,
|
|
"subscription_type": string(u.SubscriptionType),
|
|
}
|
|
if u.ExpiresAt != nil {
|
|
d["expires_at"] = u.ExpiresAt.UTC().Format(time.RFC3339)
|
|
}
|
|
return d
|
|
}
|