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