statuspin.go (3045B)
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 // StatusPinPOSTHandler swagger:operation POST /api/v1/statuses/{id}/pin statusPin 31 // 32 // Pin a status to the top of your profile, and add it to your Featured ActivityPub collection. 33 // 34 // You can only pin original posts (not reblogs) that you authored yourself. 35 // 36 // Supported privacy levels for pinned posts are public, unlisted, and private/followers-only, 37 // but only public posts will appear on the web version of your profile. 38 // 39 // --- 40 // tags: 41 // - statuses 42 // 43 // produces: 44 // - application/json 45 // 46 // parameters: 47 // - 48 // name: id 49 // type: string 50 // description: Target status ID. 51 // in: path 52 // required: true 53 // 54 // security: 55 // - OAuth2 Bearer: 56 // - write:accounts 57 // 58 // responses: 59 // '200': 60 // name: status 61 // description: The status. 62 // schema: 63 // "$ref": "#/definitions/status" 64 // '400': 65 // description: bad request 66 // '401': 67 // description: unauthorized 68 // '403': 69 // description: forbidden 70 // '404': 71 // description: not found 72 // '406': 73 // description: not acceptable 74 // '500': 75 // description: internal server error 76 func (m *Module) StatusPinPOSTHandler(c *gin.Context) { 77 authed, err := oauth.Authed(c, true, true, true, true) 78 if err != nil { 79 apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1) 80 return 81 } 82 83 if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { 84 apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1) 85 return 86 } 87 88 targetStatusID := c.Param(IDKey) 89 if targetStatusID == "" { 90 err := errors.New("no status id specified") 91 apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1) 92 return 93 } 94 95 apiStatus, errWithCode := m.processor.Status().PinCreate(c.Request.Context(), authed.Account, targetStatusID) 96 if errWithCode != nil { 97 apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1) 98 return 99 } 100 101 c.JSON(http.StatusOK, apiStatus) 102 }