Can check channel availability with API

This commit is contained in:
LittleSheep 2024-05-06 21:54:01 +08:00
parent eb78e93cb2
commit d66b591f92
2 changed files with 19 additions and 0 deletions

View File

@ -25,6 +25,24 @@ func getChannel(c *fiber.Ctx) error {
return c.JSON(channel) return c.JSON(channel)
} }
func getChannelAvailability(c *fiber.Ctx) error {
user := c.Locals("principal").(models.Account)
alias := c.Params("channel")
var err error
var channel models.Channel
if val, ok := c.Locals("realm").(models.Realm); ok {
channel, _, err = services.GetAvailableChannelWithAlias(alias, user, val.ID)
} else {
channel, _, err = services.GetAvailableChannelWithAlias(alias, user)
}
if err != nil {
return fiber.NewError(fiber.StatusForbidden, err.Error())
}
return c.JSON(channel)
}
func listChannel(c *fiber.Ctx) error { func listChannel(c *fiber.Ctx) error {
var err error var err error
var channels []models.Channel var channels []models.Channel

View File

@ -79,6 +79,7 @@ func NewServer() {
{ {
channels.Get("/", listChannel) channels.Get("/", listChannel)
channels.Get("/:channel", getChannel) channels.Get("/:channel", getChannel)
channels.Get("/:channel/available", authMiddleware, getChannelAvailability)
channels.Get("/me", authMiddleware, listOwnedChannel) channels.Get("/me", authMiddleware, listOwnedChannel)
channels.Get("/me/available", authMiddleware, listAvailableChannel) channels.Get("/me/available", authMiddleware, listAvailableChannel)