gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

admin.go (3916B)


      1 // GoToSocial
      2 // Copyright (C) GoToSocial Authors admin@gotosocial.org
      3 // SPDX-License-Identifier: AGPL-3.0-or-later
      4 //
      5 // This program is free software: you can redistribute it and/or modify
      6 // it under the terms of the GNU Affero General Public License as published by
      7 // the Free Software Foundation, either version 3 of the License, or
      8 // (at your option) any later version.
      9 //
     10 // This program is distributed in the hope that it will be useful,
     11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 // GNU Affero General Public License for more details.
     14 //
     15 // You should have received a copy of the GNU Affero General Public License
     16 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 
     18 package admin
     19 
     20 import (
     21 	"net/http"
     22 
     23 	"github.com/gin-gonic/gin"
     24 	"github.com/superseriousbusiness/gotosocial/internal/processing"
     25 )
     26 
     27 const (
     28 	BasePath               = "/v1/admin"
     29 	EmojiPath              = BasePath + "/custom_emojis"
     30 	EmojiPathWithID        = EmojiPath + "/:" + IDKey
     31 	EmojiCategoriesPath    = EmojiPath + "/categories"
     32 	DomainBlocksPath       = BasePath + "/domain_blocks"
     33 	DomainBlocksPathWithID = DomainBlocksPath + "/:" + IDKey
     34 	AccountsPath           = BasePath + "/accounts"
     35 	AccountsPathWithID     = AccountsPath + "/:" + IDKey
     36 	AccountsActionPath     = AccountsPathWithID + "/action"
     37 	MediaCleanupPath       = BasePath + "/media_cleanup"
     38 	MediaRefetchPath       = BasePath + "/media_refetch"
     39 	ReportsPath            = BasePath + "/reports"
     40 	ReportsPathWithID      = ReportsPath + "/:" + IDKey
     41 	ReportsResolvePath     = ReportsPathWithID + "/resolve"
     42 	EmailPath              = BasePath + "/email"
     43 	EmailTestPath          = EmailPath + "/test"
     44 
     45 	ExportQueryKey        = "export"
     46 	ImportQueryKey        = "import"
     47 	IDKey                 = "id"
     48 	FilterQueryKey        = "filter"
     49 	MaxShortcodeDomainKey = "max_shortcode_domain"
     50 	MinShortcodeDomainKey = "min_shortcode_domain"
     51 	LimitKey              = "limit"
     52 	DomainQueryKey        = "domain"
     53 	ResolvedKey           = "resolved"
     54 	AccountIDKey          = "account_id"
     55 	TargetAccountIDKey    = "target_account_id"
     56 	MaxIDKey              = "max_id"
     57 	SinceIDKey            = "since_id"
     58 	MinIDKey              = "min_id"
     59 )
     60 
     61 type Module struct {
     62 	processor *processing.Processor
     63 }
     64 
     65 func New(processor *processing.Processor) *Module {
     66 	return &Module{
     67 		processor: processor,
     68 	}
     69 }
     70 
     71 func (m *Module) Route(attachHandler func(method string, path string, f ...gin.HandlerFunc) gin.IRoutes) {
     72 	// emoji stuff
     73 	attachHandler(http.MethodPost, EmojiPath, m.EmojiCreatePOSTHandler)
     74 	attachHandler(http.MethodGet, EmojiPath, m.EmojisGETHandler)
     75 	attachHandler(http.MethodDelete, EmojiPathWithID, m.EmojiDELETEHandler)
     76 	attachHandler(http.MethodGet, EmojiPathWithID, m.EmojiGETHandler)
     77 	attachHandler(http.MethodPatch, EmojiPathWithID, m.EmojiPATCHHandler)
     78 	attachHandler(http.MethodGet, EmojiCategoriesPath, m.EmojiCategoriesGETHandler)
     79 
     80 	// domain block stuff
     81 	attachHandler(http.MethodPost, DomainBlocksPath, m.DomainBlocksPOSTHandler)
     82 	attachHandler(http.MethodGet, DomainBlocksPath, m.DomainBlocksGETHandler)
     83 	attachHandler(http.MethodGet, DomainBlocksPathWithID, m.DomainBlockGETHandler)
     84 	attachHandler(http.MethodDelete, DomainBlocksPathWithID, m.DomainBlockDELETEHandler)
     85 
     86 	// accounts stuff
     87 	attachHandler(http.MethodPost, AccountsActionPath, m.AccountActionPOSTHandler)
     88 
     89 	// media stuff
     90 	attachHandler(http.MethodPost, MediaCleanupPath, m.MediaCleanupPOSTHandler)
     91 	attachHandler(http.MethodPost, MediaRefetchPath, m.MediaRefetchPOSTHandler)
     92 
     93 	// reports stuff
     94 	attachHandler(http.MethodGet, ReportsPath, m.ReportsGETHandler)
     95 	attachHandler(http.MethodGet, ReportsPathWithID, m.ReportGETHandler)
     96 	attachHandler(http.MethodPost, ReportsResolvePath, m.ReportResolvePOSTHandler)
     97 
     98 	// email stuff
     99 	attachHandler(http.MethodPost, EmailTestPath, m.EmailTestPOSTHandler)
    100 }