diff --git a/scnserver/api/handler/apiKeyToken.go b/scnserver/api/handler/apiKeyToken.go index 63726b3..22d5d51 100644 --- a/scnserver/api/handler/apiKeyToken.go +++ b/scnserver/api/handler/apiKeyToken.go @@ -45,12 +45,12 @@ func (h APIHandler) ListUserKeys(g *gin.Context) ginresp.HTTPResponse { return *permResp } - clients, err := h.database.ListKeyTokens(ctx, u.UserID) + toks, err := h.database.ListKeyTokens(ctx, u.UserID) if err != nil { return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to query keys", err) } - res := langext.ArrMap(clients, func(v models.KeyToken) models.KeyTokenJSON { return v.JSON() }) + res := langext.ArrMap(toks, func(v models.KeyToken) models.KeyTokenJSON { return v.JSON() }) return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{Keys: res})) } diff --git a/scnserver/models/keytoken.go b/scnserver/models/keytoken.go index c7dfe6f..6b8b8ca 100644 --- a/scnserver/models/keytoken.go +++ b/scnserver/models/keytoken.go @@ -129,6 +129,12 @@ type KeyTokenDB struct { } func (k KeyTokenDB) Model() KeyToken { + + channels := make([]ChannelID, 0) + if strings.TrimSpace(k.Channels) != "" { + channels = langext.ArrMap(strings.Split(k.Channels, ";"), func(v string) ChannelID { return ChannelID(v) }) + } + return KeyToken{ KeyTokenID: k.KeyTokenID, Name: k.Name, @@ -136,7 +142,7 @@ func (k KeyTokenDB) Model() KeyToken { TimestampLastUsed: timeOptFromMilli(k.TimestampLastUsed), OwnerUserID: k.OwnerUserID, AllChannels: k.AllChannels, - Channels: langext.ArrMap(strings.Split(k.Channels, ";"), func(v string) ChannelID { return ChannelID(v) }), + Channels: channels, Token: k.Token, Permissions: ParseTokenPermissionList(k.Permissions), MessagesSent: k.MessagesSent,