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