2023-03-12 15:00:57 +00: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 18:46:45 +00:00
|
|
|
|
2023-01-02 12:10:50 +00:00
|
|
|
package accounts
|
2021-04-01 18:46:45 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
2021-05-30 11:12:00 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/processing"
|
2021-04-01 18:46:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2022-04-15 12:33:01 +00:00
|
|
|
ExcludeReblogsKey = "exclude_reblogs"
|
2023-06-21 16:26:40 +00: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 16:14:23 +00:00
|
|
|
BasePathWithID = BasePath + "/:" + IDKey
|
2023-06-21 16:26:40 +00: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 08:30:39 +00:00
|
|
|
NotePath = BasePathWithID + "/note"
|
2023-06-21 16:26:40 +00: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 16:22:44 +00:00
|
|
|
MovePath = BasePath + "/move"
|
|
|
|
AliasPath = BasePath + "/alias"
|
2021-04-01 18:46:45 +00:00
|
|
|
)
|
|
|
|
|
2021-04-20 16:14:23 +00:00
|
|
|
type Module struct {
|
2023-02-22 15:05:26 +00:00
|
|
|
processor *processing.Processor
|
2021-04-01 18:46:45 +00:00
|
|
|
}
|
|
|
|
|
2023-02-22 15:05:26 +00:00
|
|
|
func New(processor *processing.Processor) *Module {
|
2021-04-20 16:14:23 +00:00
|
|
|
return &Module{
|
2021-05-08 12:25:55 +00:00
|
|
|
processor: processor,
|
2021-04-01 18:46:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-02 12:10:50 +00:00
|
|
|
func (m *Module) Route(attachHandler func(method string, path string, f ...gin.HandlerFunc) gin.IRoutes) {
|
2021-07-11 14:22:21 +00:00
|
|
|
// create account
|
2023-01-02 12:10:50 +00:00
|
|
|
attachHandler(http.MethodPost, BasePath, m.AccountCreatePOSTHandler)
|
|
|
|
|
|
|
|
// get account
|
|
|
|
attachHandler(http.MethodGet, BasePathWithID, m.AccountGETHandler)
|
2021-07-11 14:22:21 +00:00
|
|
|
|
2022-03-15 15:12:35 +00:00
|
|
|
// delete account
|
2023-06-21 16:26:40 +00:00
|
|
|
attachHandler(http.MethodPost, DeletePath, m.AccountDeletePOSTHandler)
|
2022-03-15 15:12:35 +00:00
|
|
|
|
2023-01-02 12:10:50 +00:00
|
|
|
// verify account
|
|
|
|
attachHandler(http.MethodGet, VerifyPath, m.AccountVerifyGETHandler)
|
2021-07-11 14:22:21 +00:00
|
|
|
|
|
|
|
// modify account
|
2023-06-21 16:26:40 +00:00
|
|
|
attachHandler(http.MethodPatch, UpdatePath, m.AccountUpdateCredentialsPATCHHandler)
|
2021-07-11 14:22:21 +00:00
|
|
|
|
|
|
|
// get account's statuses
|
2023-06-21 16:26:40 +00:00
|
|
|
attachHandler(http.MethodGet, StatusesPath, m.AccountStatusesGETHandler)
|
2021-07-11 14:22:21 +00:00
|
|
|
|
|
|
|
// get following or followers
|
2023-06-21 16:26:40 +00:00
|
|
|
attachHandler(http.MethodGet, FollowersPath, m.AccountFollowersGETHandler)
|
|
|
|
attachHandler(http.MethodGet, FollowingPath, m.AccountFollowingGETHandler)
|
2021-07-11 14:22:21 +00:00
|
|
|
|
|
|
|
// get relationship with account
|
2023-06-21 16:26:40 +00:00
|
|
|
attachHandler(http.MethodGet, RelationshipsPath, m.AccountRelationshipsGETHandler)
|
2021-07-11 14:22:21 +00:00
|
|
|
|
|
|
|
// follow or unfollow account
|
2023-01-02 12:10:50 +00:00
|
|
|
attachHandler(http.MethodPost, FollowPath, m.AccountFollowPOSTHandler)
|
|
|
|
attachHandler(http.MethodPost, UnfollowPath, m.AccountUnfollowPOSTHandler)
|
2021-07-11 14:22:21 +00:00
|
|
|
|
|
|
|
// block or unblock account
|
2023-01-02 12:10:50 +00:00
|
|
|
attachHandler(http.MethodPost, BlockPath, m.AccountBlockPOSTHandler)
|
|
|
|
attachHandler(http.MethodPost, UnblockPath, m.AccountUnblockPOSTHandler)
|
2023-05-25 08:37:38 +00:00
|
|
|
|
|
|
|
// account lists
|
|
|
|
attachHandler(http.MethodGet, ListsPath, m.AccountListsGETHandler)
|
2023-06-21 16:26:40 +00:00
|
|
|
|
2023-07-27 08:30:39 +00:00
|
|
|
// account note
|
|
|
|
attachHandler(http.MethodPost, NotePath, m.AccountNotePOSTHandler)
|
|
|
|
|
2023-06-21 16:26:40 +00:00
|
|
|
// search for accounts
|
|
|
|
attachHandler(http.MethodGet, SearchPath, m.AccountSearchGETHandler)
|
|
|
|
attachHandler(http.MethodGet, LookupPath, m.AccountLookupGETHandler)
|
2024-01-16 16:22:44 +00:00
|
|
|
|
|
|
|
// migration handlers
|
|
|
|
attachHandler(http.MethodPost, AliasPath, m.AccountAliasPOSTHandler)
|
2024-03-13 13:45:50 +00:00
|
|
|
attachHandler(http.MethodPost, MovePath, m.AccountMovePOSTHandler)
|
2021-04-01 18:46:45 +00:00
|
|
|
}
|