2023-01-02 15:10:50 +03:00
|
|
|
/*
|
|
|
|
GoToSocial
|
2023-01-05 14:43:00 +03:00
|
|
|
Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
|
2023-01-02 15:10:50 +03:00
|
|
|
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
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-01-03 13:50:59 +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
|
|
|
|
cacheControlMiddleware := middleware.CacheControl("no-store")
|
2023-01-03 13:50:59 +03:00
|
|
|
emojiGroup.Use(m...)
|
|
|
|
usersGroup.Use(m...)
|
2023-02-08 17:10:56 +03:00
|
|
|
emojiGroup.Use(a.signatureCheckMiddleware, cacheControlMiddleware)
|
|
|
|
usersGroup.Use(a.signatureCheckMiddleware, cacheControlMiddleware)
|
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.
|
|
|
|
func (a *ActivityPub) RoutePublicKey(r router.Router, m ...gin.HandlerFunc) {
|
|
|
|
publicKeyGroup := r.AttachGroup(publickey.PublicKeyPath)
|
|
|
|
publicKeyGroup.Use(a.signatureCheckMiddleware, middleware.CacheControl("public,max-age=604800"))
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|