From 35d296b501a95760be5d068c3504d07fe33d9a53 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 22 Jun 2024 20:15:01 +0800 Subject: [PATCH] :bug: Fix get user crashes --- pkg/internal/server/api/calls_api.go | 6 +++--- pkg/internal/server/api/channel_members_api.go | 12 ++++++------ pkg/internal/server/api/channels_api.go | 12 ++++++------ pkg/internal/server/api/direct_channels_api.go | 2 +- pkg/internal/server/api/messages_api.go | 8 ++++---- pkg/internal/server/api/users_api.go | 2 +- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/pkg/internal/server/api/calls_api.go b/pkg/internal/server/api/calls_api.go index 5f9d0d8..824bbd3 100644 --- a/pkg/internal/server/api/calls_api.go +++ b/pkg/internal/server/api/calls_api.go @@ -46,10 +46,10 @@ func getOngoingCall(c *fiber.Ctx) error { } func startCall(c *fiber.Ctx) error { - user := c.Locals("user").(models.Account) if err := gap.H.EnsureAuthenticated(c); err != nil { return err } + user := c.Locals("user").(models.Account) alias := c.Params("channel") var channel models.Channel @@ -76,10 +76,10 @@ func startCall(c *fiber.Ctx) error { } func endCall(c *fiber.Ctx) error { - user := c.Locals("user").(models.Account) if err := gap.H.EnsureAuthenticated(c); err != nil { return err } + user := c.Locals("user").(models.Account) alias := c.Params("channel") var channel models.Channel @@ -112,10 +112,10 @@ func endCall(c *fiber.Ctx) error { } func exchangeCallToken(c *fiber.Ctx) error { - user := c.Locals("user").(models.Account) if err := gap.H.EnsureAuthenticated(c); err != nil { return err } + user := c.Locals("user").(models.Account) alias := c.Params("channel") var channel models.Channel diff --git a/pkg/internal/server/api/channel_members_api.go b/pkg/internal/server/api/channel_members_api.go index 3761035..15b8f46 100644 --- a/pkg/internal/server/api/channel_members_api.go +++ b/pkg/internal/server/api/channel_members_api.go @@ -34,10 +34,10 @@ func listChannelMembers(c *fiber.Ctx) error { func getMyChannelMembership(c *fiber.Ctx) error { alias := c.Params("channel") - user := c.Locals("user").(models.Account) if err := gap.H.EnsureAuthenticated(c); err != nil { return err } + user := c.Locals("user").(models.Account) var err error var channel models.Channel @@ -58,10 +58,10 @@ func getMyChannelMembership(c *fiber.Ctx) error { } func addChannelMember(c *fiber.Ctx) error { - user := c.Locals("user").(models.Account) if err := gap.H.EnsureAuthenticated(c); err != nil { return err } + user := c.Locals("user").(models.Account) alias := c.Params("channel") var data struct { @@ -102,10 +102,10 @@ func addChannelMember(c *fiber.Ctx) error { } func removeChannelMember(c *fiber.Ctx) error { - user := c.Locals("user").(models.Account) if err := gap.H.EnsureAuthenticated(c); err != nil { return err } + user := c.Locals("user").(models.Account) alias := c.Params("channel") var data struct { @@ -147,10 +147,10 @@ func removeChannelMember(c *fiber.Ctx) error { } func editMyChannelMembership(c *fiber.Ctx) error { - user := c.Locals("user").(models.Account) if err := gap.H.EnsureAuthenticated(c); err != nil { return err } + user := c.Locals("user").(models.Account) alias := c.Params("channel") var data struct { @@ -196,10 +196,10 @@ func editMyChannelMembership(c *fiber.Ctx) error { } func joinChannel(c *fiber.Ctx) error { - user := c.Locals("user").(models.Account) if err := gap.H.EnsureAuthenticated(c); err != nil { return err } + user := c.Locals("user").(models.Account) alias := c.Params("channel") var channel models.Channel @@ -227,10 +227,10 @@ func joinChannel(c *fiber.Ctx) error { } func leaveChannel(c *fiber.Ctx) error { - user := c.Locals("user").(models.Account) if err := gap.H.EnsureAuthenticated(c); err != nil { return err } + user := c.Locals("user").(models.Account) alias := c.Params("channel") var channel models.Channel diff --git a/pkg/internal/server/api/channels_api.go b/pkg/internal/server/api/channels_api.go index ec9024c..fe8dde5 100644 --- a/pkg/internal/server/api/channels_api.go +++ b/pkg/internal/server/api/channels_api.go @@ -29,10 +29,10 @@ func getChannel(c *fiber.Ctx) error { } func getChannelIdentity(c *fiber.Ctx) error { - user := c.Locals("user").(models.Account) if err := gap.H.EnsureAuthenticated(c); err != nil { return err } + user := c.Locals("user").(models.Account) alias := c.Params("channel") var err error @@ -65,10 +65,10 @@ func listChannel(c *fiber.Ctx) error { } func listOwnedChannel(c *fiber.Ctx) error { - user := c.Locals("user").(models.Account) if err := gap.H.EnsureAuthenticated(c); err != nil { return err } + user := c.Locals("user").(models.Account) var err error var channels []models.Channel @@ -85,10 +85,10 @@ func listOwnedChannel(c *fiber.Ctx) error { } func listAvailableChannel(c *fiber.Ctx) error { - user := c.Locals("user").(models.Account) if err := gap.H.EnsureAuthenticated(c); err != nil { return err } + user := c.Locals("user").(models.Account) var err error var channels []models.Channel @@ -105,10 +105,10 @@ func listAvailableChannel(c *fiber.Ctx) error { } func createChannel(c *fiber.Ctx) error { - user := c.Locals("user").(models.Account) if err := gap.H.EnsureAuthenticated(c); err != nil { return err } + user := c.Locals("user").(models.Account) var data struct { Alias string `json:"alias" validate:"required,lowercase,min=4,max=32"` @@ -159,10 +159,10 @@ func createChannel(c *fiber.Ctx) error { } func editChannel(c *fiber.Ctx) error { - user := c.Locals("user").(models.Account) if err := gap.H.EnsureAuthenticated(c); err != nil { return err } + user := c.Locals("user").(models.Account) id, _ := c.ParamsInt("channelId", 0) var data struct { @@ -212,10 +212,10 @@ func editChannel(c *fiber.Ctx) error { } func deleteChannel(c *fiber.Ctx) error { - user := c.Locals("user").(models.Account) if err := gap.H.EnsureAuthenticated(c); err != nil { return err } + user := c.Locals("user").(models.Account) id, _ := c.ParamsInt("channelId", 0) tx := database.C.Where(&models.Channel{BaseModel: models.BaseModel{ID: uint(id)}}) diff --git a/pkg/internal/server/api/direct_channels_api.go b/pkg/internal/server/api/direct_channels_api.go index 5a8a45c..436ea20 100644 --- a/pkg/internal/server/api/direct_channels_api.go +++ b/pkg/internal/server/api/direct_channels_api.go @@ -12,10 +12,10 @@ import ( ) func createDirectChannel(c *fiber.Ctx) error { - user := c.Locals("user").(models.Account) if err := gap.H.EnsureAuthenticated(c); err != nil { return err } + user := c.Locals("user").(models.Account) var data struct { Alias string `json:"alias" validate:"required,lowercase,min=4,max=32"` diff --git a/pkg/internal/server/api/messages_api.go b/pkg/internal/server/api/messages_api.go index 3fccb98..aa673e7 100644 --- a/pkg/internal/server/api/messages_api.go +++ b/pkg/internal/server/api/messages_api.go @@ -12,10 +12,10 @@ import ( ) func listMessage(c *fiber.Ctx) error { - user := c.Locals("user").(models.Account) if err := gap.H.EnsureAuthenticated(c); err != nil { return err } + user := c.Locals("user").(models.Account) take := c.QueryInt("take", 0) offset := c.QueryInt("offset", 0) alias := c.Params("channel") @@ -46,10 +46,10 @@ func listMessage(c *fiber.Ctx) error { } func newMessage(c *fiber.Ctx) error { - user := c.Locals("user").(models.Account) if err := gap.H.EnsureAuthenticated(c); err != nil { return err } + user := c.Locals("user").(models.Account) alias := c.Params("channel") var data struct { @@ -128,10 +128,10 @@ func newMessage(c *fiber.Ctx) error { } func editMessage(c *fiber.Ctx) error { - user := c.Locals("user").(models.Account) if err := gap.H.EnsureAuthenticated(c); err != nil { return err } + user := c.Locals("user").(models.Account) alias := c.Params("channel") messageId, _ := c.ParamsInt("messageId", 0) @@ -185,10 +185,10 @@ func editMessage(c *fiber.Ctx) error { } func deleteMessage(c *fiber.Ctx) error { - user := c.Locals("user").(models.Account) if err := gap.H.EnsureAuthenticated(c); err != nil { return err } + user := c.Locals("user").(models.Account) alias := c.Params("channel") messageId, _ := c.ParamsInt("messageId", 0) diff --git a/pkg/internal/server/api/users_api.go b/pkg/internal/server/api/users_api.go index 9e1a330..6dbc7e0 100644 --- a/pkg/internal/server/api/users_api.go +++ b/pkg/internal/server/api/users_api.go @@ -8,10 +8,10 @@ import ( ) func getUserinfo(c *fiber.Ctx) error { - user := c.Locals("user").(models.Account) if err := gap.H.EnsureAuthenticated(c); err != nil { return err } + user := c.Locals("user").(models.Account) var data models.Account if err := database.C.