diff options
Diffstat (limited to 'internal/api')
-rw-r--r-- | internal/api/client/instance/instance.go | 38 | ||||
-rw-r--r-- | internal/api/client/instance/instanceget.go | 20 | ||||
-rw-r--r-- | internal/api/model/instance.go | 20 |
3 files changed, 68 insertions, 10 deletions
diff --git a/internal/api/client/instance/instance.go b/internal/api/client/instance/instance.go new file mode 100644 index 000000000..ed7c18718 --- /dev/null +++ b/internal/api/client/instance/instance.go @@ -0,0 +1,38 @@ +package instance + +import ( + "net/http" + + "github.com/sirupsen/logrus" + "github.com/superseriousbusiness/gotosocial/internal/api" + "github.com/superseriousbusiness/gotosocial/internal/config" + "github.com/superseriousbusiness/gotosocial/internal/message" + "github.com/superseriousbusiness/gotosocial/internal/router" +) + +const ( + // InstanceInformationPath + InstanceInformationPath = "api/v1/instance" +) + +// Module implements the ClientModule interface +type Module struct { + config *config.Config + processor message.Processor + log *logrus.Logger +} + +// New returns a new instance information module +func New(config *config.Config, processor message.Processor, log *logrus.Logger) api.ClientModule { + return &Module{ + config: config, + processor: processor, + log: log, + } +} + +// Route satisfies the ClientModule interface +func (m *Module) Route(s router.Router) error { + s.AttachHandler(http.MethodGet, InstanceInformationPath, m.InstanceInformationGETHandler) + return nil +} diff --git a/internal/api/client/instance/instanceget.go b/internal/api/client/instance/instanceget.go new file mode 100644 index 000000000..f8e82c096 --- /dev/null +++ b/internal/api/client/instance/instanceget.go @@ -0,0 +1,20 @@ +package instance + +import ( + "net/http" + + "github.com/gin-gonic/gin" +) + +func (m *Module) InstanceInformationGETHandler(c *gin.Context) { + l := m.log.WithField("func", "InstanceInformationGETHandler") + + instance, err := m.processor.InstanceGet(m.config.Host) + if err != nil { + l.Debugf("error getting instance from processor: %s", err) + c.JSON(http.StatusInternalServerError, gin.H{"error": "internal server error"}) + return + } + + c.JSON(http.StatusOK, instance) +} diff --git a/internal/api/model/instance.go b/internal/api/model/instance.go index 857a8acc5..75ef5392e 100644 --- a/internal/api/model/instance.go +++ b/internal/api/model/instance.go @@ -23,9 +23,9 @@ type Instance struct { // REQUIRED // The domain name of the instance. - URI string `json:"uri"` + URI string `json:"uri,omitempty"` // The title of the website. - Title string `json:"title"` + Title string `json:"title,omitempty"` // Admin-defined description of the Mastodon site. Description string `json:"description"` // A shorter description defined by the admin. @@ -33,9 +33,9 @@ type Instance struct { // An email that may be contacted for any inquiries. Email string `json:"email"` // The version of Mastodon installed on the instance. - Version string `json:"version"` + Version string `json:"version,omitempty"` // Primary langauges of the website and its staff. - Languages []string `json:"languages"` + Languages []string `json:"languages,omitempty"` // Whether registrations are enabled. Registrations bool `json:"registrations"` // Whether registrations require moderator approval. @@ -43,16 +43,16 @@ type Instance struct { // Whether invites are enabled. InvitesEnabled bool `json:"invites_enabled"` // URLs of interest for clients apps. - URLS *InstanceURLs `json:"urls"` + URLS *InstanceURLs `json:"urls,omitempty"` // Statistics about how much information the instance contains. - Stats *InstanceStats `json:"stats"` - - // OPTIONAL - + Stats *InstanceStats `json:"stats,omitempty"` // Banner image for the website. - Thumbnail string `json:"thumbnail,omitempty"` + Thumbnail string `json:"thumbnail"` // A user that can be contacted, as an alternative to email. ContactAccount *Account `json:"contact_account,omitempty"` + // What's the maximum allowed length of a post on this instance? + // This is provided for compatibility with Tusky. + MaxTootChars uint `json:"max_toot_chars"` } // InstanceURLs represents URLs necessary for successfully connecting to the instance as a user. See https://docs.joinmastodon.org/entities/instance/ |