2024-06-22 10:05:41 +00:00
|
|
|
package api
|
2024-05-04 17:04:14 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2024-09-11 15:58:02 +00:00
|
|
|
|
2024-11-02 05:24:37 +00:00
|
|
|
"git.solsynth.dev/hypernet/messaging/pkg/internal/services"
|
2024-05-04 17:04:14 +00:00
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func realmMiddleware(c *fiber.Ctx) error {
|
|
|
|
realmAlias := c.Params("realm")
|
|
|
|
if len(realmAlias) > 0 && realmAlias != "global" {
|
|
|
|
realm, err := services.GetRealmWithAlias(realmAlias)
|
|
|
|
if err != nil {
|
|
|
|
return fiber.NewError(fiber.StatusInternalServerError, fmt.Sprintf("requested channel with realm, but realm was not found: %v", err))
|
|
|
|
} else {
|
|
|
|
c.Locals("realm", realm)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.Next()
|
|
|
|
}
|