mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-14 00:57:29 -06:00
add api/v1/instance info handler + instance model
This commit is contained in:
parent
0cbab627c7
commit
5b41a00e81
11 changed files with 222 additions and 22 deletions
|
|
@ -74,6 +74,9 @@ type TypeConverter interface {
|
|||
// VisToMasto converts a gts visibility into its mastodon equivalent
|
||||
VisToMasto(m gtsmodel.Visibility) model.Visibility
|
||||
|
||||
// InstanceToMasto converts a gts instance into its mastodon equivalent for serving at /api/v1/instance
|
||||
InstanceToMasto(i *gtsmodel.Instance) (*model.Instance, error)
|
||||
|
||||
/*
|
||||
FRONTEND (mastodon) MODEL TO INTERNAL (gts) MODEL
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -551,3 +551,33 @@ func (c *converter) VisToMasto(m gtsmodel.Visibility) model.Visibility {
|
|||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (c *converter) InstanceToMasto(i *gtsmodel.Instance) (*model.Instance, error) {
|
||||
mi := &model.Instance{
|
||||
URI: i.URI,
|
||||
Title: i.Title,
|
||||
Description: i.Description,
|
||||
ShortDescription: i.ShortDescription,
|
||||
Email: i.ContactEmail,
|
||||
}
|
||||
|
||||
if i.Domain == c.config.Host {
|
||||
mi.Registrations = c.config.AccountsConfig.OpenRegistration
|
||||
mi.ApprovalRequired = c.config.AccountsConfig.RequireApproval
|
||||
mi.InvitesEnabled = false // TODO
|
||||
mi.MaxTootChars = uint(c.config.StatusesConfig.MaxChars)
|
||||
}
|
||||
|
||||
// contact account is optional but let's try to get it
|
||||
if i.ContactAccountID != "" {
|
||||
ia := >smodel.Account{}
|
||||
if err := c.db.GetByID(i.ContactAccountID, ia); err == nil {
|
||||
ma, err := c.AccountToMastoPublic(ia)
|
||||
if err == nil {
|
||||
mi.ContactAccount = ma
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mi, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue