summaryrefslogtreecommitdiff
path: root/internal/api/activitypub/users/inboxpost.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-05-28 21:05:15 +0200
committerLibravatar GitHub <noreply@github.com>2023-05-28 20:05:15 +0100
commit46d4ec0f05fd424321e40dc574e4707fc9be8297 (patch)
treeb3bda98ab5722efc85a9bea588cf27c37926a4b3 /internal/api/activitypub/users/inboxpost.go
parent[chore] tidy up media manager, add calling func to errors, build-script impro... (diff)
downloadgotosocial-46d4ec0f05fd424321e40dc574e4707fc9be8297.tar.xz
[bugfix/chore] Inbox post updates (#1821)
Co-authored-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/api/activitypub/users/inboxpost.go')
-rw-r--r--internal/api/activitypub/users/inboxpost.go36
1 files changed, 19 insertions, 17 deletions
diff --git a/internal/api/activitypub/users/inboxpost.go b/internal/api/activitypub/users/inboxpost.go
index 9f74d9c31..4f535f534 100644
--- a/internal/api/activitypub/users/inboxpost.go
+++ b/internal/api/activitypub/users/inboxpost.go
@@ -19,32 +19,34 @@ package users
import (
"errors"
- "strings"
+ "net/http"
"github.com/gin-gonic/gin"
apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util"
- "github.com/superseriousbusiness/gotosocial/internal/gtserror" //nolint:typecheck
+ "github.com/superseriousbusiness/gotosocial/internal/gtserror"
+ "github.com/superseriousbusiness/gotosocial/internal/log"
)
// InboxPOSTHandler deals with incoming POST requests to an actor's inbox.
// Eg., POST to https://example.org/users/whatever/inbox.
func (m *Module) InboxPOSTHandler(c *gin.Context) {
- // usernames on our instance are always lowercase
- requestedUsername := strings.ToLower(c.Param(UsernameKey))
- if requestedUsername == "" {
- err := errors.New("no username specified in request")
- apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
- return
- }
+ _, err := m.processor.Fedi().InboxPost(apiutil.TransferSignatureContext(c), c.Writer, c.Request)
+ if err != nil {
+ errWithCode := new(gtserror.WithCode)
- if posted, err := m.processor.Fedi().InboxPost(apiutil.TransferSignatureContext(c), c.Writer, c.Request); err != nil {
- if withCode, ok := err.(gtserror.WithCode); ok {
- apiutil.ErrorHandler(c, withCode, m.processor.InstanceGetV1)
- } else {
- apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
+ if !errors.As(err, errWithCode) {
+ // Something else went wrong, and someone forgot to return
+ // an errWithCode! It's chill though. Log the error but don't
+ // return it as-is to the caller, to avoid leaking internals.
+ log.Errorf(c.Request.Context(), "returning Bad Request to caller, err was: %q", err)
+ *errWithCode = gtserror.NewErrorBadRequest(err)
}
- } else if !posted {
- err := errors.New("unable to process request")
- apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
+
+ // Pass along confirmed error with code to the main error handler
+ apiutil.ErrorHandler(c, *errWithCode, m.processor.InstanceGetV1)
+ return
}
+
+ // Inbox POST body was Accepted for processing.
+ c.JSON(http.StatusAccepted, gin.H{"status": http.StatusText(http.StatusAccepted)})
}