Update: support configuration
This exposes settings for clients, so it's nice to be able to access it directly.master
parent
29bb16009b
commit
3203150fd3
16
instance.go
16
instance.go
|
@ -17,6 +17,17 @@ type Instance struct {
|
||||||
Stats *InstanceStats `json:"stats,omitempty"`
|
Stats *InstanceStats `json:"stats,omitempty"`
|
||||||
Languages []string `json:"languages"`
|
Languages []string `json:"languages"`
|
||||||
ContactAccount *Account `json:"contact_account"`
|
ContactAccount *Account `json:"contact_account"`
|
||||||
|
Configuration *InstanceConfig `json:"configuration"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type InstanceConfigMap map[string]int
|
||||||
|
|
||||||
|
// InstanceConfig holds configuration accessible for clients.
|
||||||
|
type InstanceConfig struct {
|
||||||
|
Accounts *InstanceConfigMap `json:"accounts"`
|
||||||
|
Statuses *InstanceConfigMap `json:"statuses"`
|
||||||
|
MediaAttachments map[string]interface{} `json:"media_attachments"`
|
||||||
|
Polls *InstanceConfigMap `json:"polls"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// InstanceStats holds information for mastodon instance stats.
|
// InstanceStats holds information for mastodon instance stats.
|
||||||
|
@ -36,6 +47,11 @@ func (c *Client) GetInstance(ctx context.Context) (*Instance, error) {
|
||||||
return &instance, nil
|
return &instance, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetConfig returns InstanceConfig.
|
||||||
|
func (c *Instance) GetConfig() *InstanceConfig {
|
||||||
|
return c.Configuration
|
||||||
|
}
|
||||||
|
|
||||||
// WeeklyActivity holds information for mastodon weekly activity.
|
// WeeklyActivity holds information for mastodon weekly activity.
|
||||||
type WeeklyActivity struct {
|
type WeeklyActivity struct {
|
||||||
Week Unixtime `json:"week"`
|
Week Unixtime `json:"week"`
|
||||||
|
|
|
@ -60,7 +60,7 @@ func TestGetInstanceMore(t *testing.T) {
|
||||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Fprintln(w, `{"title": "mastodon", "uri": "http://mstdn.example.com", "description": "test mastodon", "email": "mstdn@mstdn.example.com", "version": "0.0.1", "urls":{"foo":"http://stream1.example.com", "bar": "http://stream2.example.com"}, "thumbnail": "http://mstdn.example.com/logo.png", "stats":{"user_count":1, "status_count":2, "domain_count":3}}}`)
|
fmt.Fprintln(w, `{"title": "mastodon", "uri": "http://mstdn.example.com", "description": "test mastodon", "email": "mstdn@mstdn.example.com", "version": "0.0.1", "urls":{"foo":"http://stream1.example.com", "bar": "http://stream2.example.com"}, "thumbnail": "http://mstdn.example.com/logo.png", "configuration":{"accounts": {"max_featured_tags": 10}, "statuses": {"max_characters": 500}}, "stats":{"user_count":1, "status_count":2, "domain_count":3}}}`)
|
||||||
}))
|
}))
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ func TestGetInstanceMore(t *testing.T) {
|
||||||
t.Fatalf("want %q but %q", "http://mstdn.example.com/logo.png", ins.Thumbnail)
|
t.Fatalf("want %q but %q", "http://mstdn.example.com/logo.png", ins.Thumbnail)
|
||||||
}
|
}
|
||||||
if ins.Stats == nil {
|
if ins.Stats == nil {
|
||||||
t.Fatal("status should be nil")
|
t.Fatal("stats should not be nil")
|
||||||
}
|
}
|
||||||
if ins.Stats.UserCount != 1 {
|
if ins.Stats.UserCount != 1 {
|
||||||
t.Fatalf("want %v but %v", 1, ins.Stats.UserCount)
|
t.Fatalf("want %v but %v", 1, ins.Stats.UserCount)
|
||||||
|
@ -114,6 +114,15 @@ func TestGetInstanceMore(t *testing.T) {
|
||||||
if ins.Stats.DomainCount != 3 {
|
if ins.Stats.DomainCount != 3 {
|
||||||
t.Fatalf("want %v but %v", 3, ins.Stats.DomainCount)
|
t.Fatalf("want %v but %v", 3, ins.Stats.DomainCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg := ins.GetConfig()
|
||||||
|
if cfg.Accounts == nil {
|
||||||
|
t.Error("expected accounts to be non nil")
|
||||||
|
}
|
||||||
|
if cfg.Statuses == nil {
|
||||||
|
t.Error("expected statuses to be non nil")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetInstanceActivity(t *testing.T) {
|
func TestGetInstanceActivity(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue