emojiget.go (2850B)
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 admin 19 20 import ( 21 "errors" 22 "fmt" 23 "net/http" 24 25 "github.com/gin-gonic/gin" 26 apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util" 27 "github.com/superseriousbusiness/gotosocial/internal/gtserror" 28 "github.com/superseriousbusiness/gotosocial/internal/oauth" 29 ) 30 31 // EmojiGETHandler swagger:operation GET /api/v1/admin/custom_emojis/{id} emojiGet 32 // 33 // Get the admin view of a single emoji. 34 // 35 // --- 36 // tags: 37 // - admin 38 // 39 // produces: 40 // - application/json 41 // 42 // parameters: 43 // - 44 // name: id 45 // type: string 46 // description: The id of the emoji. 47 // in: path 48 // required: true 49 // 50 // responses: 51 // '200': 52 // description: A single emoji. 53 // schema: 54 // "$ref": "#/definitions/adminEmoji" 55 // '400': 56 // description: bad request 57 // '401': 58 // description: unauthorized 59 // '403': 60 // description: forbidden 61 // '404': 62 // description: not found 63 // '406': 64 // description: not acceptable 65 // '500': 66 // description: internal server error 67 func (m *Module) EmojiGETHandler(c *gin.Context) { 68 authed, err := oauth.Authed(c, true, true, true, true) 69 if err != nil { 70 apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1) 71 return 72 } 73 74 if !*authed.User.Admin { 75 err := fmt.Errorf("user %s not an admin", authed.User.ID) 76 apiutil.ErrorHandler(c, gtserror.NewErrorForbidden(err, err.Error()), m.processor.InstanceGetV1) 77 return 78 } 79 80 if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { 81 apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1) 82 return 83 } 84 85 emojiID := c.Param(IDKey) 86 if emojiID == "" { 87 err := errors.New("no emoji id specified") 88 apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1) 89 return 90 } 91 92 emoji, errWithCode := m.processor.Admin().EmojiGet(c.Request.Context(), authed.Account, authed.User, emojiID) 93 if errWithCode != nil { 94 apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1) 95 return 96 } 97 98 c.JSON(http.StatusOK, emoji) 99 }