| 
									
										
										
										
											2023-03-12 16:00:57 +01:00
										 |  |  | // GoToSocial | 
					
						
							|  |  |  | // Copyright (C) GoToSocial Authors admin@gotosocial.org | 
					
						
							|  |  |  | // SPDX-License-Identifier: AGPL-3.0-or-later | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // This program is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  | // it under the terms of the GNU Affero General Public License as published by | 
					
						
							|  |  |  | // the Free Software Foundation, either version 3 of the License, or | 
					
						
							|  |  |  | // (at your option) any later version. | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  | // GNU Affero General Public License for more details. | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // You should have received a copy of the GNU Affero General Public License | 
					
						
							|  |  |  | // along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
					
						
							| 
									
										
										
										
											2021-04-01 20:46:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | package accounts | 
					
						
							| 
									
										
										
										
											2021-04-01 20:46:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"net/http" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/gin-gonic/gin" | 
					
						
							| 
									
										
										
										
											2021-05-30 13:12:00 +02:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/processing" | 
					
						
							| 
									
										
										
										
											2021-04-01 20:46:45 +02:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const ( | 
					
						
							| 
									
										
										
										
											2022-04-15 14:33:01 +02:00
										 |  |  | 	ExcludeReblogsKey = "exclude_reblogs" | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	ExcludeRepliesKey = "exclude_replies" | 
					
						
							|  |  |  | 	LimitKey          = "limit" | 
					
						
							|  |  |  | 	MaxIDKey          = "max_id" | 
					
						
							|  |  |  | 	MinIDKey          = "min_id" | 
					
						
							|  |  |  | 	OnlyMediaKey      = "only_media" | 
					
						
							|  |  |  | 	OnlyPublicKey     = "only_public" | 
					
						
							|  |  |  | 	PinnedKey         = "pinned" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BasePath       = "/v1/accounts" | 
					
						
							|  |  |  | 	IDKey          = "id" | 
					
						
							| 
									
										
										
										
											2021-04-20 18:14:23 +02:00
										 |  |  | 	BasePathWithID = BasePath + "/:" + IDKey | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	BlockPath         = BasePathWithID + "/block" | 
					
						
							|  |  |  | 	DeletePath        = BasePath + "/delete" | 
					
						
							|  |  |  | 	FollowersPath     = BasePathWithID + "/followers" | 
					
						
							|  |  |  | 	FollowingPath     = BasePathWithID + "/following" | 
					
						
							|  |  |  | 	FollowPath        = BasePathWithID + "/follow" | 
					
						
							|  |  |  | 	ListsPath         = BasePathWithID + "/lists" | 
					
						
							|  |  |  | 	LookupPath        = BasePath + "/lookup" | 
					
						
							| 
									
										
										
										
											2023-07-27 01:30:39 -07:00
										 |  |  | 	NotePath          = BasePathWithID + "/note" | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	RelationshipsPath = BasePath + "/relationships" | 
					
						
							|  |  |  | 	SearchPath        = BasePath + "/search" | 
					
						
							|  |  |  | 	StatusesPath      = BasePathWithID + "/statuses" | 
					
						
							|  |  |  | 	UnblockPath       = BasePathWithID + "/unblock" | 
					
						
							|  |  |  | 	UnfollowPath      = BasePathWithID + "/unfollow" | 
					
						
							|  |  |  | 	UpdatePath        = BasePath + "/update_credentials" | 
					
						
							|  |  |  | 	VerifyPath        = BasePath + "/verify_credentials" | 
					
						
							| 
									
										
										
										
											2024-01-16 17:22:44 +01:00
										 |  |  | 	MovePath          = BasePath + "/move" | 
					
						
							|  |  |  | 	AliasPath         = BasePath + "/alias" | 
					
						
							| 
									
										
										
										
											2021-04-01 20:46:45 +02:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-20 18:14:23 +02:00
										 |  |  | type Module struct { | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | 	processor *processing.Processor | 
					
						
							| 
									
										
										
										
											2021-04-01 20:46:45 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | func New(processor *processing.Processor) *Module { | 
					
						
							| 
									
										
										
										
											2021-04-20 18:14:23 +02:00
										 |  |  | 	return &Module{ | 
					
						
							| 
									
										
										
										
											2021-05-08 14:25:55 +02:00
										 |  |  | 		processor: processor, | 
					
						
							| 
									
										
										
										
											2021-04-01 20:46:45 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | func (m *Module) Route(attachHandler func(method string, path string, f ...gin.HandlerFunc) gin.IRoutes) { | 
					
						
							| 
									
										
										
										
											2021-07-11 16:22:21 +02:00
										 |  |  | 	// create account | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	attachHandler(http.MethodPost, BasePath, m.AccountCreatePOSTHandler) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// get account | 
					
						
							|  |  |  | 	attachHandler(http.MethodGet, BasePathWithID, m.AccountGETHandler) | 
					
						
							| 
									
										
										
										
											2021-07-11 16:22:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-15 16:12:35 +01:00
										 |  |  | 	// delete account | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	attachHandler(http.MethodPost, DeletePath, m.AccountDeletePOSTHandler) | 
					
						
							| 
									
										
										
										
											2022-03-15 16:12:35 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	// verify account | 
					
						
							|  |  |  | 	attachHandler(http.MethodGet, VerifyPath, m.AccountVerifyGETHandler) | 
					
						
							| 
									
										
										
										
											2021-07-11 16:22:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// modify account | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	attachHandler(http.MethodPatch, UpdatePath, m.AccountUpdateCredentialsPATCHHandler) | 
					
						
							| 
									
										
										
										
											2021-07-11 16:22:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// get account's statuses | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	attachHandler(http.MethodGet, StatusesPath, m.AccountStatusesGETHandler) | 
					
						
							| 
									
										
										
										
											2021-07-11 16:22:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// get following or followers | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	attachHandler(http.MethodGet, FollowersPath, m.AccountFollowersGETHandler) | 
					
						
							|  |  |  | 	attachHandler(http.MethodGet, FollowingPath, m.AccountFollowingGETHandler) | 
					
						
							| 
									
										
										
										
											2021-07-11 16:22:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// get relationship with account | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	attachHandler(http.MethodGet, RelationshipsPath, m.AccountRelationshipsGETHandler) | 
					
						
							| 
									
										
										
										
											2021-07-11 16:22:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// follow or unfollow account | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	attachHandler(http.MethodPost, FollowPath, m.AccountFollowPOSTHandler) | 
					
						
							|  |  |  | 	attachHandler(http.MethodPost, UnfollowPath, m.AccountUnfollowPOSTHandler) | 
					
						
							| 
									
										
										
										
											2021-07-11 16:22:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// block or unblock account | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	attachHandler(http.MethodPost, BlockPath, m.AccountBlockPOSTHandler) | 
					
						
							|  |  |  | 	attachHandler(http.MethodPost, UnblockPath, m.AccountUnblockPOSTHandler) | 
					
						
							| 
									
										
										
										
											2023-05-25 10:37:38 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// account lists | 
					
						
							|  |  |  | 	attachHandler(http.MethodGet, ListsPath, m.AccountListsGETHandler) | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-27 01:30:39 -07:00
										 |  |  | 	// account note | 
					
						
							|  |  |  | 	attachHandler(http.MethodPost, NotePath, m.AccountNotePOSTHandler) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-21 18:26:40 +02:00
										 |  |  | 	// search for accounts | 
					
						
							|  |  |  | 	attachHandler(http.MethodGet, SearchPath, m.AccountSearchGETHandler) | 
					
						
							|  |  |  | 	attachHandler(http.MethodGet, LookupPath, m.AccountLookupGETHandler) | 
					
						
							| 
									
										
										
										
											2024-01-16 17:22:44 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// migration handlers | 
					
						
							|  |  |  | 	attachHandler(http.MethodPost, AliasPath, m.AccountAliasPOSTHandler) | 
					
						
							| 
									
										
										
										
											2024-03-13 14:45:50 +01:00
										 |  |  | 	attachHandler(http.MethodPost, MovePath, m.AccountMovePOSTHandler) | 
					
						
							| 
									
										
										
										
											2021-04-01 20:46:45 +02:00
										 |  |  | } |