user.go (3452B)
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 "net/http" 22 23 "github.com/gin-gonic/gin" 24 "github.com/superseriousbusiness/gotosocial/internal/processing" 25 "github.com/superseriousbusiness/gotosocial/internal/uris" 26 ) 27 28 const ( 29 // UsernameKey is for account usernames. 30 UsernameKey = "username" 31 // StatusIDKey is for status IDs 32 StatusIDKey = "status" 33 // OnlyOtherAccountsKey is for filtering status responses. 34 OnlyOtherAccountsKey = "only_other_accounts" 35 // MinIDKey is for filtering status responses. 36 MinIDKey = "min_id" 37 // MaxIDKey is for filtering status responses. 38 MaxIDKey = "max_id" 39 // PageKey is for filtering status responses. 40 PageKey = "page" 41 42 // BasePath is the base path for serving AP 'users' requests, minus the 'users' prefix. 43 BasePath = "/:" + UsernameKey 44 // InboxPath is for serving POST requests to a user's inbox with the given username key. 45 InboxPath = BasePath + "/" + uris.InboxPath 46 // OutboxPath is for serving GET requests to a user's outbox with the given username key. 47 OutboxPath = BasePath + "/" + uris.OutboxPath 48 // FollowersPath is for serving GET request's to a user's followers list, with the given username key. 49 FollowersPath = BasePath + "/" + uris.FollowersPath 50 // FollowingPath is for serving GET request's to a user's following list, with the given username key. 51 FollowingPath = BasePath + "/" + uris.FollowingPath 52 // FeaturedCollectionPath is for serving GET requests to a user's list of featured (pinned) statuses. 53 FeaturedCollectionPath = BasePath + "/" + uris.CollectionsPath + "/" + uris.FeaturedPath 54 // StatusPath is for serving GET requests to a particular status by a user, with the given username key and status ID 55 StatusPath = BasePath + "/" + uris.StatusesPath + "/:" + StatusIDKey 56 // StatusRepliesPath is for serving the replies collection of a status. 57 StatusRepliesPath = StatusPath + "/replies" 58 ) 59 60 type Module struct { 61 processor *processing.Processor 62 } 63 64 func New(processor *processing.Processor) *Module { 65 return &Module{ 66 processor: processor, 67 } 68 } 69 70 func (m *Module) Route(attachHandler func(method string, path string, f ...gin.HandlerFunc) gin.IRoutes) { 71 attachHandler(http.MethodGet, BasePath, m.UsersGETHandler) 72 attachHandler(http.MethodPost, InboxPath, m.InboxPOSTHandler) 73 attachHandler(http.MethodGet, FollowersPath, m.FollowersGETHandler) 74 attachHandler(http.MethodGet, FollowingPath, m.FollowingGETHandler) 75 attachHandler(http.MethodGet, FeaturedCollectionPath, m.FeaturedCollectionGETHandler) 76 attachHandler(http.MethodGet, StatusPath, m.StatusGETHandler) 77 attachHandler(http.MethodGet, StatusRepliesPath, m.StatusRepliesGETHandler) 78 attachHandler(http.MethodGet, OutboxPath, m.OutboxGETHandler) 79 }