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-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/activitypub/emoji"
|
2023-02-08 17:10:56 +03:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/api/activitypub/publickey"
|
2023-01-02 15:10:50 +03:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/api/activitypub/users"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/middleware"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/processing"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/router"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ActivityPub struct {
|
2023-02-08 17:10:56 +03:00
|
|
|
emoji *emoji.Module
|
|
|
|
users *users.Module
|
|
|
|
publicKey *publickey.Module
|
|
|
|
signatureCheckMiddleware gin.HandlerFunc
|
2023-01-02 15:10:50 +03:00
|
|
|
}
|
|
|
|
|
2023-11-13 21:48:51 +03:00
|
|
|
func (a *ActivityPub) Route(r *router.Router, m ...gin.HandlerFunc) {
|
2023-01-02 15:10:50 +03:00
|
|
|
// create groupings for the 'emoji' and 'users' prefixes
|
|
|
|
emojiGroup := r.AttachGroup("emoji")
|
|
|
|
usersGroup := r.AttachGroup("users")
|
|
|
|
|
2023-02-08 17:10:56 +03:00
|
|
|
// attach shared, non-global middlewares to both of these groups
|
2023-07-13 22:27:25 +03:00
|
|
|
ccMiddleware := middleware.CacheControl(middleware.CacheControlConfig{
|
|
|
|
Directives: []string{"no-store"},
|
|
|
|
})
|
2023-01-03 13:50:59 +03:00
|
|
|
emojiGroup.Use(m...)
|
|
|
|
usersGroup.Use(m...)
|
2023-07-13 22:27:25 +03:00
|
|
|
emojiGroup.Use(a.signatureCheckMiddleware, ccMiddleware)
|
|
|
|
usersGroup.Use(a.signatureCheckMiddleware, ccMiddleware)
|
2023-01-02 15:10:50 +03:00
|
|
|
|
|
|
|
a.emoji.Route(emojiGroup.Handle)
|
|
|
|
a.users.Route(usersGroup.Handle)
|
|
|
|
}
|
|
|
|
|
2023-02-08 17:10:56 +03:00
|
|
|
// Public key endpoint requires different middleware + cache policies from other AP endpoints.
|
2023-11-13 21:48:51 +03:00
|
|
|
func (a *ActivityPub) RoutePublicKey(r *router.Router, m ...gin.HandlerFunc) {
|
2023-07-13 22:27:25 +03:00
|
|
|
// Create grouping for the 'users/[username]/main-key' prefix.
|
2023-02-08 17:10:56 +03:00
|
|
|
publicKeyGroup := r.AttachGroup(publickey.PublicKeyPath)
|
2023-07-13 22:27:25 +03:00
|
|
|
|
|
|
|
// Attach middleware allowing public cacheing of main-key.
|
|
|
|
ccMiddleware := middleware.CacheControl(middleware.CacheControlConfig{
|
|
|
|
Directives: []string{"public", "max-age=604800"},
|
|
|
|
Vary: []string{"Accept", "Accept-Encoding"},
|
|
|
|
})
|
|
|
|
publicKeyGroup.Use(m...)
|
|
|
|
publicKeyGroup.Use(a.signatureCheckMiddleware, ccMiddleware)
|
|
|
|
|
2023-02-08 17:10:56 +03:00
|
|
|
a.publicKey.Route(publicKeyGroup.Handle)
|
|
|
|
}
|
|
|
|
|
2023-02-22 18:05:26 +03:00
|
|
|
func NewActivityPub(db db.DB, p *processing.Processor) *ActivityPub {
|
2023-01-02 15:10:50 +03:00
|
|
|
return &ActivityPub{
|
2023-02-08 17:10:56 +03:00
|
|
|
emoji: emoji.New(p),
|
|
|
|
users: users.New(p),
|
|
|
|
publicKey: publickey.New(p),
|
|
|
|
signatureCheckMiddleware: middleware.SignatureCheck(db.IsURIBlocked),
|
2023-01-02 15:10:50 +03:00
|
|
|
}
|
|
|
|
}
|