From 8c9a8533434ec6e159541896d5f43e39303d42e4 Mon Sep 17 00:00:00 2001 From: Tobi Smethurst <31960611+tsmethurst@users.noreply.github.com> Date: Wed, 23 Jun 2021 16:35:57 +0200 Subject: 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 --- internal/typeutils/internaltofrontend.go | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'internal/typeutils/internaltofrontend.go') 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{} -- cgit v1.2.3