| 
									
										
										
										
											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/>. | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | package api | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2023-01-08 11:43:08 +00:00
										 |  |  | 	"time" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-03 10:50:59 +00:00
										 |  |  | 	"github.com/gin-gonic/gin" | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/accounts" | 
					
						
							|  |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/admin" | 
					
						
							| 
									
										
										
										
											2024-12-23 16:43:50 +01:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/announcements" | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/apps" | 
					
						
							|  |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/blocks" | 
					
						
							|  |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/bookmarks" | 
					
						
							| 
									
										
										
										
											2024-04-18 12:36:02 +02:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/conversations" | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/customemojis" | 
					
						
							| 
									
										
										
										
											2024-07-31 16:03:34 +02:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/exports" | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/favourites" | 
					
						
							| 
									
										
										
										
											2023-02-05 10:50:09 +01:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/featuredtags" | 
					
						
							| 
									
										
										
										
											2024-03-06 02:15:58 -08:00
										 |  |  | 	filtersV1 "github.com/superseriousbusiness/gotosocial/internal/api/client/filters/v1" | 
					
						
							| 
									
										
										
										
											2024-05-31 03:55:56 -07:00
										 |  |  | 	filtersV2 "github.com/superseriousbusiness/gotosocial/internal/api/client/filters/v2" | 
					
						
							| 
									
										
										
										
											2024-07-29 11:26:31 -07:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/followedtags" | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/followrequests" | 
					
						
							| 
									
										
										
										
											2024-08-02 13:41:46 +02:00
										 |  |  | 	importdata "github.com/superseriousbusiness/gotosocial/internal/api/client/import" | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/instance" | 
					
						
							| 
									
										
										
										
											2024-07-17 16:46:52 +02:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/interactionpolicies" | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/interactionrequests" | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/lists" | 
					
						
							| 
									
										
										
										
											2023-07-29 03:49:14 -07:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/markers" | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/media" | 
					
						
							| 
									
										
										
										
											2024-04-18 10:59:47 +02:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/mutes" | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/notifications" | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/polls" | 
					
						
							| 
									
										
										
										
											2023-05-06 17:42:58 +02:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/preferences" | 
					
						
							| 
									
										
										
										
											2025-01-23 16:47:30 -08:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/push" | 
					
						
							| 
									
										
										
										
											2023-01-23 13:14:21 +01:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/reports" | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/search" | 
					
						
							|  |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/statuses" | 
					
						
							|  |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/streaming" | 
					
						
							| 
									
										
										
										
											2024-07-29 11:26:31 -07:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/tags" | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/timelines" | 
					
						
							|  |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/api/client/user" | 
					
						
							|  |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/db" | 
					
						
							|  |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/middleware" | 
					
						
							|  |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/processing" | 
					
						
							|  |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/router" | 
					
						
							| 
									
										
										
										
											2024-05-29 12:56:17 +02:00
										 |  |  | 	"github.com/superseriousbusiness/gotosocial/internal/state" | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type Client struct { | 
					
						
							| 
									
										
										
										
											2023-02-22 16:05:26 +01:00
										 |  |  | 	processor *processing.Processor | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	db        db.DB | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-29 11:26:31 -07:00
										 |  |  | 	accounts            *accounts.Module            // api/v1/accounts, api/v1/profile | 
					
						
							| 
									
										
										
										
											2024-07-17 16:46:52 +02:00
										 |  |  | 	admin               *admin.Module               // api/v1/admin | 
					
						
							| 
									
										
										
										
											2024-12-23 16:43:50 +01:00
										 |  |  | 	announcements       *announcements.Module       // api/v1/announcements | 
					
						
							| 
									
										
										
										
											2024-07-17 16:46:52 +02:00
										 |  |  | 	apps                *apps.Module                // api/v1/apps | 
					
						
							|  |  |  | 	blocks              *blocks.Module              // api/v1/blocks | 
					
						
							|  |  |  | 	bookmarks           *bookmarks.Module           // api/v1/bookmarks | 
					
						
							|  |  |  | 	conversations       *conversations.Module       // api/v1/conversations | 
					
						
							|  |  |  | 	customEmojis        *customemojis.Module        // api/v1/custom_emojis | 
					
						
							| 
									
										
										
										
											2024-07-31 16:03:34 +02:00
										 |  |  | 	exports             *exports.Module             // api/v1/exports | 
					
						
							| 
									
										
										
										
											2024-07-17 16:46:52 +02:00
										 |  |  | 	favourites          *favourites.Module          // api/v1/favourites | 
					
						
							|  |  |  | 	featuredTags        *featuredtags.Module        // api/v1/featured_tags | 
					
						
							|  |  |  | 	filtersV1           *filtersV1.Module           // api/v1/filters | 
					
						
							|  |  |  | 	filtersV2           *filtersV2.Module           // api/v2/filters | 
					
						
							|  |  |  | 	followRequests      *followrequests.Module      // api/v1/follow_requests | 
					
						
							| 
									
										
										
										
											2024-07-29 11:26:31 -07:00
										 |  |  | 	followedTags        *followedtags.Module        // api/v1/followed_tags | 
					
						
							| 
									
										
										
										
											2024-08-02 13:41:46 +02:00
										 |  |  | 	importData          *importdata.Module          // api/v1/import | 
					
						
							| 
									
										
										
										
											2024-07-17 16:46:52 +02:00
										 |  |  | 	instance            *instance.Module            // api/v1/instance | 
					
						
							|  |  |  | 	interactionPolicies *interactionpolicies.Module // api/v1/interaction_policies | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 	interactionRequests *interactionrequests.Module // api/v1/interaction_requests | 
					
						
							| 
									
										
										
										
											2024-07-17 16:46:52 +02:00
										 |  |  | 	lists               *lists.Module               // api/v1/lists | 
					
						
							|  |  |  | 	markers             *markers.Module             // api/v1/markers | 
					
						
							|  |  |  | 	media               *media.Module               // api/v1/media, api/v2/media | 
					
						
							|  |  |  | 	mutes               *mutes.Module               // api/v1/mutes | 
					
						
							|  |  |  | 	notifications       *notifications.Module       // api/v1/notifications | 
					
						
							|  |  |  | 	polls               *polls.Module               // api/v1/polls | 
					
						
							|  |  |  | 	preferences         *preferences.Module         // api/v1/preferences | 
					
						
							| 
									
										
										
										
											2025-01-23 16:47:30 -08:00
										 |  |  | 	push                *push.Module                // api/v1/push | 
					
						
							| 
									
										
										
										
											2024-07-17 16:46:52 +02:00
										 |  |  | 	reports             *reports.Module             // api/v1/reports | 
					
						
							|  |  |  | 	search              *search.Module              // api/v1/search, api/v2/search | 
					
						
							|  |  |  | 	statuses            *statuses.Module            // api/v1/statuses | 
					
						
							|  |  |  | 	streaming           *streaming.Module           // api/v1/streaming | 
					
						
							| 
									
										
										
										
											2024-07-29 11:26:31 -07:00
										 |  |  | 	tags                *tags.Module                // api/v1/tags | 
					
						
							| 
									
										
										
										
											2024-07-17 16:46:52 +02:00
										 |  |  | 	timelines           *timelines.Module           // api/v1/timelines | 
					
						
							|  |  |  | 	user                *user.Module                // api/v1/user | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-13 19:48:51 +01:00
										 |  |  | func (c *Client) Route(r *router.Router, m ...gin.HandlerFunc) { | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	// create a new group on the top level client 'api' prefix | 
					
						
							|  |  |  | 	apiGroup := r.AttachGroup("api") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// attach non-global middlewares appropriate to the client api | 
					
						
							| 
									
										
										
										
											2023-01-03 10:50:59 +00:00
										 |  |  | 	apiGroup.Use(m...) | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	apiGroup.Use( | 
					
						
							|  |  |  | 		middleware.TokenCheck(c.db, c.processor.OAuthValidateBearerToken), | 
					
						
							| 
									
										
										
										
											2023-07-13 21:27:25 +02:00
										 |  |  | 		middleware.CacheControl(middleware.CacheControlConfig{ | 
					
						
							|  |  |  | 			// Never cache client api responses. | 
					
						
							|  |  |  | 			Directives: []string{"no-store"}, | 
					
						
							|  |  |  | 		}), | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// for each client api module, pass it the Handle function | 
					
						
							|  |  |  | 	// so that the module can attach its routes to this group | 
					
						
							|  |  |  | 	h := apiGroup.Handle | 
					
						
							|  |  |  | 	c.accounts.Route(h) | 
					
						
							|  |  |  | 	c.admin.Route(h) | 
					
						
							| 
									
										
										
										
											2024-12-23 16:43:50 +01:00
										 |  |  | 	c.announcements.Route(h) | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	c.apps.Route(h) | 
					
						
							|  |  |  | 	c.blocks.Route(h) | 
					
						
							|  |  |  | 	c.bookmarks.Route(h) | 
					
						
							| 
									
										
										
										
											2024-04-18 12:36:02 +02:00
										 |  |  | 	c.conversations.Route(h) | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	c.customEmojis.Route(h) | 
					
						
							| 
									
										
										
										
											2024-07-31 16:03:34 +02:00
										 |  |  | 	c.exports.Route(h) | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	c.favourites.Route(h) | 
					
						
							| 
									
										
										
										
											2023-02-05 10:50:09 +01:00
										 |  |  | 	c.featuredTags.Route(h) | 
					
						
							| 
									
										
										
										
											2024-03-06 02:15:58 -08:00
										 |  |  | 	c.filtersV1.Route(h) | 
					
						
							| 
									
										
										
										
											2024-05-31 03:55:56 -07:00
										 |  |  | 	c.filtersV2.Route(h) | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	c.followRequests.Route(h) | 
					
						
							| 
									
										
										
										
											2024-07-29 11:26:31 -07:00
										 |  |  | 	c.followedTags.Route(h) | 
					
						
							| 
									
										
										
										
											2024-08-02 13:41:46 +02:00
										 |  |  | 	c.importData.Route(h) | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	c.instance.Route(h) | 
					
						
							| 
									
										
										
										
											2024-07-17 16:46:52 +02:00
										 |  |  | 	c.interactionPolicies.Route(h) | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 	c.interactionRequests.Route(h) | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	c.lists.Route(h) | 
					
						
							| 
									
										
										
										
											2023-07-29 03:49:14 -07:00
										 |  |  | 	c.markers.Route(h) | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	c.media.Route(h) | 
					
						
							| 
									
										
										
										
											2024-04-18 10:59:47 +02:00
										 |  |  | 	c.mutes.Route(h) | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	c.notifications.Route(h) | 
					
						
							| 
									
										
										
										
											2023-11-08 14:32:17 +00:00
										 |  |  | 	c.polls.Route(h) | 
					
						
							| 
									
										
										
										
											2023-05-06 17:42:58 +02:00
										 |  |  | 	c.preferences.Route(h) | 
					
						
							| 
									
										
										
										
											2025-01-23 16:47:30 -08:00
										 |  |  | 	c.push.Route(h) | 
					
						
							| 
									
										
										
										
											2023-01-23 13:14:21 +01:00
										 |  |  | 	c.reports.Route(h) | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	c.search.Route(h) | 
					
						
							|  |  |  | 	c.statuses.Route(h) | 
					
						
							|  |  |  | 	c.streaming.Route(h) | 
					
						
							| 
									
										
										
										
											2024-07-29 11:26:31 -07:00
										 |  |  | 	c.tags.Route(h) | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	c.timelines.Route(h) | 
					
						
							|  |  |  | 	c.user.Route(h) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-29 12:56:17 +02:00
										 |  |  | func NewClient(state *state.State, p *processing.Processor) *Client { | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	return &Client{ | 
					
						
							|  |  |  | 		processor: p, | 
					
						
							| 
									
										
										
										
											2024-05-29 12:56:17 +02:00
										 |  |  | 		db:        state.DB, | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-17 16:46:52 +02:00
										 |  |  | 		accounts:            accounts.New(p), | 
					
						
							|  |  |  | 		admin:               admin.New(state, p), | 
					
						
							| 
									
										
										
										
											2024-12-23 16:43:50 +01:00
										 |  |  | 		announcements:       announcements.New(p), | 
					
						
							| 
									
										
										
										
											2024-07-17 16:46:52 +02:00
										 |  |  | 		apps:                apps.New(p), | 
					
						
							|  |  |  | 		blocks:              blocks.New(p), | 
					
						
							|  |  |  | 		bookmarks:           bookmarks.New(p), | 
					
						
							|  |  |  | 		conversations:       conversations.New(p), | 
					
						
							|  |  |  | 		customEmojis:        customemojis.New(p), | 
					
						
							| 
									
										
										
										
											2024-07-31 16:03:34 +02:00
										 |  |  | 		exports:             exports.New(p), | 
					
						
							| 
									
										
										
										
											2024-07-17 16:46:52 +02:00
										 |  |  | 		favourites:          favourites.New(p), | 
					
						
							|  |  |  | 		featuredTags:        featuredtags.New(p), | 
					
						
							|  |  |  | 		filtersV1:           filtersV1.New(p), | 
					
						
							|  |  |  | 		filtersV2:           filtersV2.New(p), | 
					
						
							|  |  |  | 		followRequests:      followrequests.New(p), | 
					
						
							| 
									
										
										
										
											2024-07-29 11:26:31 -07:00
										 |  |  | 		followedTags:        followedtags.New(p), | 
					
						
							| 
									
										
										
										
											2024-08-02 13:41:46 +02:00
										 |  |  | 		importData:          importdata.New(p), | 
					
						
							| 
									
										
										
										
											2024-07-17 16:46:52 +02:00
										 |  |  | 		instance:            instance.New(p), | 
					
						
							|  |  |  | 		interactionPolicies: interactionpolicies.New(p), | 
					
						
							| 
									
										
										
										
											2024-08-24 11:49:37 +02:00
										 |  |  | 		interactionRequests: interactionrequests.New(p), | 
					
						
							| 
									
										
										
										
											2024-07-17 16:46:52 +02:00
										 |  |  | 		lists:               lists.New(p), | 
					
						
							|  |  |  | 		markers:             markers.New(p), | 
					
						
							|  |  |  | 		media:               media.New(p), | 
					
						
							|  |  |  | 		mutes:               mutes.New(p), | 
					
						
							|  |  |  | 		notifications:       notifications.New(p), | 
					
						
							|  |  |  | 		polls:               polls.New(p), | 
					
						
							|  |  |  | 		preferences:         preferences.New(p), | 
					
						
							| 
									
										
										
										
											2025-01-23 16:47:30 -08:00
										 |  |  | 		push:                push.New(p), | 
					
						
							| 
									
										
										
										
											2024-07-17 16:46:52 +02:00
										 |  |  | 		reports:             reports.New(p), | 
					
						
							|  |  |  | 		search:              search.New(p), | 
					
						
							|  |  |  | 		statuses:            statuses.New(p), | 
					
						
							|  |  |  | 		streaming:           streaming.New(p, time.Second*30, 4096), | 
					
						
							| 
									
										
										
										
											2024-07-29 11:26:31 -07:00
										 |  |  | 		tags:                tags.New(p), | 
					
						
							| 
									
										
										
										
											2024-07-17 16:46:52 +02:00
										 |  |  | 		timelines:           timelines.New(p), | 
					
						
							|  |  |  | 		user:                user.New(p), | 
					
						
							| 
									
										
										
										
											2023-01-02 13:10:50 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | } |