Files
go-fa-api/user.go
2026-05-26 20:21:55 +02:00

55 lines
1.7 KiB
Go

package fa
import (
"context"
"fmt"
"strings"
"time"
"github.com/PuerkitoBio/goquery"
"git.anthrove.art/public/go-fa-api/internal/urls"
)
// User is a user's full profile page, as seen on /user/{name}/.
type User struct {
UserRef
Title string // user-set "title" / artist headline
Joined time.Time // registration date
BioHTML string // raw profile HTML
BioText string // plaintext convenience
Stats UserStats // submission/view/journal/watcher counts
Contacts []UserContact // social/contact rows
Shouts []Shout // most recent shouts shown on the page
FeaturedSub *SubmissionRef // pinned/featured submission, if any
SiteBanner *SiteBanner // header banner; IsCustom=false when FA's default is shown
// Watched is true when the logged-in viewer currently watches this user
// i.e. the profile header renders an "Unwatch" button. It is false
// both when the viewer does not watch the user and when no watch button
// is present at all (anonymous session, or viewing your own page), so
// it is only meaningful on another user's page while logged in.
Watched bool
}
// GetUser fetches a user profile by URL-safe name (FA's lowercase login form).
func (c *Client) GetUser(ctx context.Context, name string, opts ...Option) (*User, error) {
name = strings.TrimSpace(name)
if name == "" {
return nil, fmt.Errorf("fa: GetUser: empty name")
}
var out *User
err := c.fetch(ctx, urls.User(name), func(doc *goquery.Document) error {
u, err := parseUser(name, doc)
if err != nil {
return err
}
out = u
return nil
}, opts...)
if err != nil {
return nil, err
}
return out, nil
}