bloat/mastodon/instance.go

127 lines
4 KiB
Go
Raw Normal View History

2019-12-13 18:08:26 +00:00
package mastodon
import (
"context"
"net/http"
)
// Instance hold information for mastodon instance.
type Instance struct {
URI string `json:"uri"`
Title string `json:"title"`
Description string `json:"description"`
2022-10-12 22:41:34 +00:00
ShortDescription *string `json:"short_description"`
2019-12-13 18:08:26 +00:00
EMail string `json:"email"`
Version string `json:"version,omitempty"`
Thumbnail string `json:"thumbnail,omitempty"`
URLs map[string]string `json:"urls,omitempty"`
Stats *InstanceStats `json:"stats,omitempty"`
Languages []string `json:"languages"`
ContactAccount *Account `json:"account"`
2022-10-12 22:41:34 +00:00
PollLimits *PollLimit `json:"poll_limits"`
2022-10-12 10:34:41 +00:00
MaxTootChars *int64 `json:"max_toot_chars"`
2022-10-12 22:41:34 +00:00
MaxMediaAttachments *int64 `json:"max_media_attachments"`
UploadLimit *int64 `json:"upload_limit"`
BackgroundUploadLimit *int64 `json:"background_upload_limit"`
AvatarUploadLimit *int64 `json:"avatar_upload_limit"`
Configuration *InstanceConf `json:"configuration"`
Rules *[]map[string]string `json:"rules"`
2022-10-12 10:34:41 +00:00
Pleroma *PleromaInstance `json:"pleroma"`
2019-12-13 18:08:26 +00:00
}
// InstanceStats hold information for mastodon instance stats.
type InstanceStats struct {
UserCount int64 `json:"user_count"`
StatusCount int64 `json:"status_count"`
DomainCount int64 `json:"domain_count"`
}
2022-10-12 22:41:34 +00:00
// InstanceConf hold information for mastodon instances
type InstanceConf struct {
Statuses StatusesConf `json:"statuses"`
}
type StatusesConf struct {
MaxCharacters int64 `json:"max_characters"`
MaxMediaAttachments int64 `json:"max_media_attachments"`
}
type PollLimit struct {
MaxExpiration int64 `json:"max_expiration"`
MaxOptionChars int64 `json:"max_option_chars"`
MaxOptions int64 `json:"max_options"`
MinExpiration int64 `json:"min_expiration"`
}
2022-10-12 10:34:41 +00:00
// For about instance if this Pleroma
type PleromaInstance struct {
MetaData MetaData `json:"metadata"`
}
type MetaData struct {
2022-10-12 22:41:34 +00:00
Features *[]string `json:"features"`
Federation FederationInfo `json:"federation"`
}
type FederationInfo struct {
2023-11-10 23:59:32 +00:00
Enabled bool `json:"enabled"`
MrfPolicies []string `json:"mrf_policies"`
MrfSimple MRFSimple `json:"mrf_simple"`
}
type MRFSimple struct {
Reject []string `json:"reject"`
MediaNsfw []string `json:"media_nsfw"`
FederatedTimelineRemoval []string `json:"federated_timeline_removal"`
RejectDeletes []string `json:"reject_deletes"`
2022-10-12 10:34:41 +00:00
}
2019-12-13 18:08:26 +00:00
// GetInstance return Instance.
func (c *Client) GetInstance(ctx context.Context) (*Instance, error) {
var instance Instance
err := c.doAPI(ctx, http.MethodGet, "/api/v1/instance", nil, &instance, nil)
if err != nil {
return nil, err
}
return &instance, nil
}
// WeeklyActivity hold information for mastodon weekly activity.
type WeeklyActivity struct {
Week Unixtime `json:"week"`
Statuses int64 `json:"statuses,string"`
Logins int64 `json:"logins,string"`
Registrations int64 `json:"registrations,string"`
}
// GetInstanceActivity return instance activity.
func (c *Client) GetInstanceActivity(ctx context.Context) ([]*WeeklyActivity, error) {
var activity []*WeeklyActivity
err := c.doAPI(ctx, http.MethodGet, "/api/v1/instance/activity", nil, &activity, nil)
if err != nil {
return nil, err
}
return activity, nil
}
// GetInstancePeers return instance peers.
func (c *Client) GetInstancePeers(ctx context.Context) ([]string, error) {
var peers []string
err := c.doAPI(ctx, http.MethodGet, "/api/v1/instance/peers", nil, &peers, nil)
if err != nil {
return nil, err
}
return peers, nil
}
2019-12-22 18:10:42 +00:00
// GetInstanceEmojis return instance emojis.
func (c *Client) GetInstanceEmojis(ctx context.Context) ([]*Emoji, error) {
var emojis []*Emoji
err := c.doAPI(ctx, http.MethodGet, "/api/v1/custom_emojis", nil, &emojis, nil)
if err != nil {
return nil, err
}
return emojis, nil
}