From 7d54da638066dc27a8d4e39ddaa710e08eff6d95 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Thu, 13 Oct 2022 01:41:34 +0300 Subject: [PATCH] Add some information about instance --- mastodon/instance.go | 33 +++++++++++++++++++++++- renderer/model.go | 1 + service/service.go | 6 +++++ templates/aboutinstance.tmpl | 49 ++++++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 1 deletion(-) diff --git a/mastodon/instance.go b/mastodon/instance.go index 9152808..761a021 100644 --- a/mastodon/instance.go +++ b/mastodon/instance.go @@ -10,6 +10,7 @@ type Instance struct { URI string `json:"uri"` Title string `json:"title"` Description string `json:"description"` + ShortDescription *string `json:"short_description"` EMail string `json:"email"` Version string `json:"version,omitempty"` Thumbnail string `json:"thumbnail,omitempty"` @@ -17,7 +18,14 @@ type Instance struct { Stats *InstanceStats `json:"stats,omitempty"` Languages []string `json:"languages"` ContactAccount *Account `json:"account"` + PollLimits *PollLimit `json:"poll_limits"` MaxTootChars *int64 `json:"max_toot_chars"` + 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"` Pleroma *PleromaInstance `json:"pleroma"` } @@ -28,13 +36,36 @@ type InstanceStats struct { DomainCount int64 `json:"domain_count"` } +// 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"` +} + // For about instance if this Pleroma type PleromaInstance struct { MetaData MetaData `json:"metadata"` } type MetaData struct { - Features *[]string `json:"features"` + Features *[]string `json:"features"` + Federation FederationInfo `json:"federation"` +} + +type FederationInfo struct { + Enabled bool `json:enabled"` + MrfPolicies []string `json:mrf_policies"` } diff --git a/renderer/model.go b/renderer/model.go index c81e76d..ab1a88b 100644 --- a/renderer/model.go +++ b/renderer/model.go @@ -122,6 +122,7 @@ type AboutData struct { type AboutInstanceData struct { *CommonData Instance *mastodon.Instance + Peers []string } type EmojiData struct { diff --git a/service/service.go b/service/service.go index 8da1062..e73e873 100644 --- a/service/service.go +++ b/service/service.go @@ -743,9 +743,15 @@ func (s *service) AboutInstance(c *client) (err error) { if err != nil { return } + peers, err := c.GetInstancePeers(c.ctx) + if err != nil { + return + } + data := &renderer.AboutInstanceData{ CommonData: cdata, Instance: instance, + Peers: peers, } return s.renderer.Render(c.rctx, c.w, renderer.AboutInstance, data) } diff --git a/templates/aboutinstance.tmpl b/templates/aboutinstance.tmpl index 3fb6073..9302015 100644 --- a/templates/aboutinstance.tmpl +++ b/templates/aboutinstance.tmpl @@ -6,6 +6,19 @@

{{.Instance.Description}}

+

+ {{Raw .Instance.ShortDescription}} +

+ {{if .Instance.Rules}} +

+

+ Rules + {{range .Instance.Rules}} + {{.id}}. {{.text}}

+ {{end}} +
+

+ {{end}}

Logo instance @@ -15,6 +28,9 @@
Contact E-mail: {{.Instance.EMail}}
+{{if .Instance.ContactAccount}} +
Contact account: {{.Instance.ContactAccount.Acct}}
+{{end}} {{if .Instance.Stats}}
Statistics:
@@ -36,6 +52,39 @@ {{end}} +
Limits:
+ {{if .Instance.Configuration}} + Max status characters: {{.Instance.Configuration.Statuses.MaxCharacters}}
+ Max media attachments: {{.Instance.Configuration.Statuses.MaxMediaAttachments}}
+ {{else}} + Max status characters: {{.Instance.MaxTootChars}}
+ Max media attachments: {{.Instance.MaxMediaAttachments}}
+ Max size attachment: {{.Instance.UploadLimit}} bytes
+ {{end}} + {{if .Instance.PollLimits}} + Max poll options: {{.Instance.PollLimits.MaxOptions}}
+ {{end}} + + + +
Federation info:
+
+ {{if .Instance.Pleroma}} +
Federation enabled: {{.Instance.Pleroma.MetaData.Federation.Enabled}}
+
MRF Policies
+ {{range .Instance.Pleroma.MetaData.Federation.MrfPolicies}} + {{.}}
+ {{end}} + {{end}} +
+ Current peers ({{.Instance.Stats.DomainCount}}) + {{range .Peers}} + {{.}}
+ {{end}} +
+
+ +
Version: {{.Instance.Version}}