gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

inboxpost.go (2041B)


      1 // GoToSocial
      2 // Copyright (C) GoToSocial Authors admin@gotosocial.org
      3 // SPDX-License-Identifier: AGPL-3.0-or-later
      4 //
      5 // This program is free software: you can redistribute it and/or modify
      6 // it under the terms of the GNU Affero General Public License as published by
      7 // the Free Software Foundation, either version 3 of the License, or
      8 // (at your option) any later version.
      9 //
     10 // This program is distributed in the hope that it will be useful,
     11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 // GNU Affero General Public License for more details.
     14 //
     15 // You should have received a copy of the GNU Affero General Public License
     16 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 
     18 package users
     19 
     20 import (
     21 	"errors"
     22 	"net/http"
     23 
     24 	"github.com/gin-gonic/gin"
     25 	apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util"
     26 	"github.com/superseriousbusiness/gotosocial/internal/gtserror"
     27 	"github.com/superseriousbusiness/gotosocial/internal/log"
     28 )
     29 
     30 // InboxPOSTHandler deals with incoming POST requests to an actor's inbox.
     31 // Eg., POST to https://example.org/users/whatever/inbox.
     32 func (m *Module) InboxPOSTHandler(c *gin.Context) {
     33 	_, err := m.processor.Fedi().InboxPost(c.Request.Context(), c.Writer, c.Request)
     34 	if err != nil {
     35 		errWithCode := new(gtserror.WithCode)
     36 
     37 		if !errors.As(err, errWithCode) {
     38 			// Something else went wrong, and someone forgot to return
     39 			// an errWithCode! It's chill though. Log the error but don't
     40 			// return it as-is to the caller, to avoid leaking internals.
     41 			log.Errorf(c.Request.Context(), "returning Bad Request to caller, err was: %q", err)
     42 			*errWithCode = gtserror.NewErrorBadRequest(err)
     43 		}
     44 
     45 		// Pass along confirmed error with code to the main error handler
     46 		apiutil.ErrorHandler(c, *errWithCode, m.processor.InstanceGetV1)
     47 		return
     48 	}
     49 
     50 	// Inbox POST body was Accepted for processing.
     51 	c.JSON(http.StatusAccepted, gin.H{"status": http.StatusText(http.StatusAccepted)})
     52 }