summaryrefslogtreecommitdiff
path: root/internal/processing
diff options
context:
space:
mode:
Diffstat (limited to 'internal/processing')
-rw-r--r--internal/processing/instance.go34
-rw-r--r--internal/processing/processor.go8
2 files changed, 33 insertions, 9 deletions
diff --git a/internal/processing/instance.go b/internal/processing/instance.go
index afa60ad1e..f05d83052 100644
--- a/internal/processing/instance.go
+++ b/internal/processing/instance.go
@@ -33,13 +33,35 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/validate"
)
-func (p *processor) InstanceGet(ctx context.Context, domain string) (*apimodel.Instance, gtserror.WithCode) {
+func (p *processor) getThisInstance(ctx context.Context) (*gtsmodel.Instance, error) {
i := &gtsmodel.Instance{}
- if err := p.db.GetWhere(ctx, []db.Where{{Key: "domain", Value: domain}}, i); err != nil {
- return nil, gtserror.NewErrorInternalError(fmt.Errorf("db error fetching instance %s: %s", domain, err))
+ if err := p.db.GetWhere(ctx, []db.Where{{Key: "domain", Value: config.GetHost()}}, i); err != nil {
+ return nil, err
+ }
+ return i, nil
+}
+
+func (p *processor) InstanceGetV1(ctx context.Context) (*apimodel.InstanceV1, gtserror.WithCode) {
+ i, err := p.getThisInstance(ctx)
+ if err != nil {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("db error fetching instance: %s", err))
+ }
+
+ ai, err := p.tc.InstanceToAPIV1Instance(ctx, i)
+ if err != nil {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting instance to api representation: %s", err))
+ }
+
+ return ai, nil
+}
+
+func (p *processor) InstanceGetV2(ctx context.Context) (*apimodel.InstanceV2, gtserror.WithCode) {
+ i, err := p.getThisInstance(ctx)
+ if err != nil {
+ return nil, gtserror.NewErrorInternalError(fmt.Errorf("db error fetching instance: %s", err))
}
- ai, err := p.tc.InstanceToAPIInstance(ctx, i)
+ ai, err := p.tc.InstanceToAPIV2Instance(ctx, i)
if err != nil {
return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting instance to api representation: %s", err))
}
@@ -98,7 +120,7 @@ func (p *processor) InstancePeersGet(ctx context.Context, includeSuspended bool,
return domains, nil
}
-func (p *processor) InstancePatch(ctx context.Context, form *apimodel.InstanceSettingsUpdateRequest) (*apimodel.Instance, gtserror.WithCode) {
+func (p *processor) InstancePatch(ctx context.Context, form *apimodel.InstanceSettingsUpdateRequest) (*apimodel.InstanceV1, gtserror.WithCode) {
// fetch the instance entry from the db for processing
i := &gtsmodel.Instance{}
host := config.GetHost()
@@ -235,7 +257,7 @@ func (p *processor) InstancePatch(ctx context.Context, form *apimodel.InstanceSe
}
}
- ai, err := p.tc.InstanceToAPIInstance(ctx, i)
+ ai, err := p.tc.InstanceToAPIV1Instance(ctx, i)
if err != nil {
return nil, gtserror.NewErrorInternalError(fmt.Errorf("error converting instance to api representation: %s", err))
}
diff --git a/internal/processing/processor.go b/internal/processing/processor.go
index 68a4c5fa4..6ea860c78 100644
--- a/internal/processing/processor.go
+++ b/internal/processing/processor.go
@@ -170,13 +170,15 @@ type Processor interface {
// FollowRequestReject handles the rejection of a follow request from the given account ID.
FollowRequestReject(ctx context.Context, auth *oauth.Auth, accountID string) (*apimodel.Relationship, gtserror.WithCode)
- // InstanceGet retrieves instance information for serving at api/v1/instance
- InstanceGet(ctx context.Context, domain string) (*apimodel.Instance, gtserror.WithCode)
+ // InstanceGetV1 retrieves instance information for serving at api/v1/instance
+ InstanceGetV1(ctx context.Context) (*apimodel.InstanceV1, gtserror.WithCode)
+ // InstanceGetV1 retrieves instance information for serving at api/v2/instance
+ InstanceGetV2(ctx context.Context) (*apimodel.InstanceV2, gtserror.WithCode)
InstancePeersGet(ctx context.Context, includeSuspended bool, includeOpen bool, flat bool) (interface{}, gtserror.WithCode)
// InstancePatch updates this instance according to the given form.
//
// It should already be ascertained that the requesting account is authenticated and an admin.
- InstancePatch(ctx context.Context, form *apimodel.InstanceSettingsUpdateRequest) (*apimodel.Instance, gtserror.WithCode)
+ InstancePatch(ctx context.Context, form *apimodel.InstanceSettingsUpdateRequest) (*apimodel.InstanceV1, gtserror.WithCode)
// MediaCreate handles the creation of a media attachment, using the given form.
MediaCreate(ctx context.Context, authed *oauth.Auth, form *apimodel.AttachmentRequest) (*apimodel.Attachment, gtserror.WithCode)