mirror of
https://github.com/owncast/owncast.git
synced 2024-11-23 05:14:20 +03:00
Use the @unclearParadigm REST parameter helper
This commit is contained in:
parent
ed25f11458
commit
c8af8a413f
3 changed files with 22 additions and 13 deletions
|
@ -2,7 +2,6 @@ package controllers
|
|||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
|
@ -10,6 +9,7 @@ import (
|
|||
"github.com/owncast/owncast/activitypub/crypto"
|
||||
"github.com/owncast/owncast/activitypub/requests"
|
||||
"github.com/owncast/owncast/core/data"
|
||||
"github.com/owncast/owncast/utils"
|
||||
)
|
||||
|
||||
// ActorHandler handles requests for a single actor.
|
||||
|
@ -19,8 +19,12 @@ func ActorHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
pathComponents := strings.Split(r.URL.Path, "/")
|
||||
accountName := pathComponents[3]
|
||||
accountName, err := utils.ReadRestURLParameter(r, "user")
|
||||
if err != nil || accountName == "" {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
resource, _ := utils.ReadRestURLParameter(r, "resource")
|
||||
|
||||
if _, valid := data.GetFederatedInboxMap()[accountName]; !valid {
|
||||
// User is not valid
|
||||
|
@ -30,20 +34,17 @@ func ActorHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// If this request is for an actor's inbox then pass
|
||||
// the request to the inbox controller.
|
||||
if len(pathComponents) == 5 && pathComponents[4] == "inbox" {
|
||||
if resource == "inbox" {
|
||||
InboxHandler(w, r)
|
||||
return
|
||||
} else if len(pathComponents) == 5 && pathComponents[4] == "outbox" {
|
||||
} else if resource == "outbox" {
|
||||
OutboxHandler(w, r)
|
||||
return
|
||||
// } else if len(pathComponents) == 5 {
|
||||
// ActorObjectHandler(w, r)
|
||||
// return
|
||||
} else if len(pathComponents) == 5 && pathComponents[4] == "followers" {
|
||||
} else if resource == "followers" {
|
||||
// followers list
|
||||
FollowersHandler(w, r)
|
||||
return
|
||||
} else if len(pathComponents) == 5 && pathComponents[4] == "following" {
|
||||
} else if resource == "following" {
|
||||
// following list (none)
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/owncast/owncast/activitypub/persistence"
|
||||
"github.com/owncast/owncast/activitypub/requests"
|
||||
"github.com/owncast/owncast/core/data"
|
||||
"github.com/owncast/owncast/utils"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
@ -18,7 +19,13 @@ func ObjectHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
object, err := persistence.GetObjectByIRI(r.URL.Path)
|
||||
objectID, err := utils.ReadRestURLParameter(r, "object")
|
||||
if err != nil || objectID == "" {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
object, err := persistence.GetObjectByID(objectID)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/owncast/owncast/activitypub/controllers"
|
||||
"github.com/owncast/owncast/router/middleware"
|
||||
"github.com/owncast/owncast/utils"
|
||||
)
|
||||
|
||||
// StartRouter will start the federation specific http router.
|
||||
|
@ -28,8 +29,8 @@ func StartRouter() {
|
|||
http.HandleFunc("/api/v1/instance", controllers.InstanceV1Controller)
|
||||
|
||||
// Single ActivityPub Actor
|
||||
http.HandleFunc("/federation/user/", controllers.ActorHandler)
|
||||
http.HandleFunc(utils.RestEndpoint("/federation/user/{user}/{resource}", controllers.ActorHandler))
|
||||
|
||||
// Single AP object
|
||||
http.HandleFunc("/federation/", middleware.RequireActivityPubOrRedirect(controllers.ObjectHandler))
|
||||
http.HandleFunc(utils.RestEndpoint("/federation/{object}", middleware.RequireActivityPubOrRedirect(controllers.ObjectHandler)))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue