Fix empty string in channels field in GetKeys route
This commit is contained in:
parent
686f89f75d
commit
90830fe384
@ -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}))
|
||||
}
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user