diff options
author | 2021-06-23 16:35:57 +0200 | |
---|---|---|
committer | 2021-06-23 16:35:57 +0200 | |
commit | 8c9a8533434ec6e159541896d5f43e39303d42e4 (patch) | |
tree | 3da3cbf9aa33a160cd076f2b9f8d56396ae3bdfa /internal/typeutils/internaltofrontend.go | |
parent | Opengraph meta tags (#55) (diff) | |
download | gotosocial-8c9a8533434ec6e159541896d5f43e39303d42e4.tar.xz |
Instance settings updates (#59)
Allow admins to set instance settings through a PATCH to /api/v1/instance
Update templates to reflect some of the new fields
Diffstat (limited to 'internal/typeutils/internaltofrontend.go')
-rw-r--r-- | internal/typeutils/internaltofrontend.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go index 90460ecdd..a5984e068 100644 --- a/internal/typeutils/internaltofrontend.go +++ b/internal/typeutils/internaltofrontend.go @@ -511,9 +511,31 @@ func (c *converter) InstanceToMasto(i *gtsmodel.Instance) (*model.Instance, erro ShortDescription: i.ShortDescription, Email: i.ContactEmail, Version: i.Version, + Stats: make(map[string]int), + ContactAccount: &model.Account{}, } + // if the requested instance is *this* instance, we can add some extra information if i.Domain == c.config.Host { + userCountKey := "user_count" + statusCountKey := "status_count" + domainCountKey := "domain_count" + + userCount, err := c.db.GetUserCountForInstance(c.config.Host) + if err == nil { + mi.Stats[userCountKey] = userCount + } + + statusCount, err := c.db.GetStatusCountForInstance(c.config.Host) + if err == nil { + mi.Stats[statusCountKey] = statusCount + } + + domainCount, err := c.db.GetDomainCountForInstance(c.config.Host) + if err == nil { + mi.Stats[domainCountKey] = domainCount + } + mi.Registrations = c.config.AccountsConfig.OpenRegistration mi.ApprovalRequired = c.config.AccountsConfig.RequireApproval mi.InvitesEnabled = false // TODO @@ -523,6 +545,17 @@ func (c *converter) InstanceToMasto(i *gtsmodel.Instance) (*model.Instance, erro } } + // get the instance account if it exists and just skip if it doesn't + ia := >smodel.Account{} + if err := c.db.GetWhere([]db.Where{{Key: "username", Value: i.Domain}}, ia); err == nil { + // instance account exists, get the header for the account if it exists + attachment := >smodel.MediaAttachment{} + if err := c.db.GetHeaderForAccountID(attachment, ia.ID); err == nil { + // header exists, set it on the api model + mi.Thumbnail = attachment.URL + } + } + // contact account is optional but let's try to get it if i.ContactAccountID != "" { ia := >smodel.Account{} |