statusboost.go (2938B)
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 statuses 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/oauth" 28 ) 29 30 // StatusBoostPOSTHandler swagger:operation POST /api/v1/statuses/{id}/reblog statusReblog 31 // 32 // Reblog/boost status with the given ID. 33 // 34 // If the target status is rebloggable/boostable, it will be shared with your followers. 35 // This is equivalent to an ActivityPub 'Announce' activity. 36 // 37 // --- 38 // tags: 39 // - statuses 40 // 41 // produces: 42 // - application/json 43 // 44 // parameters: 45 // - 46 // name: id 47 // type: string 48 // description: Target status ID. 49 // in: path 50 // required: true 51 // 52 // security: 53 // - OAuth2 Bearer: 54 // - write:statuses 55 // 56 // responses: 57 // '200': 58 // name: status 59 // description: The boost of the status. 60 // schema: 61 // "$ref": "#/definitions/status" 62 // '400': 63 // description: bad request 64 // '401': 65 // description: unauthorized 66 // '403': 67 // description: forbidden 68 // '404': 69 // description: not found 70 // '406': 71 // description: not acceptable 72 // '500': 73 // description: internal server error 74 func (m *Module) StatusBoostPOSTHandler(c *gin.Context) { 75 authed, err := oauth.Authed(c, true, true, true, true) 76 if err != nil { 77 apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1) 78 return 79 } 80 81 if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { 82 apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1) 83 return 84 } 85 86 targetStatusID := c.Param(IDKey) 87 if targetStatusID == "" { 88 err := errors.New("no status id specified") 89 apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1) 90 return 91 } 92 93 apiStatus, errWithCode := m.processor.Status().BoostCreate(c.Request.Context(), authed.Account, authed.Application, targetStatusID) 94 if errWithCode != nil { 95 apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1) 96 return 97 } 98 99 c.JSON(http.StatusOK, apiStatus) 100 }