mirror of
https://github.com/fiatjaf/khatru.git
synced 2026-04-19 19:28:01 +02:00
GetIP() and GetOpenSubscriptions() utils.
This commit is contained in:
25
utils.go
25
utils.go
@@ -2,6 +2,9 @@ package khatru
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
"github.com/sebest/xff"
|
||||
)
|
||||
|
||||
func GetConnection(ctx context.Context) *WebSocket {
|
||||
@@ -9,9 +12,21 @@ func GetConnection(ctx context.Context) *WebSocket {
|
||||
}
|
||||
|
||||
func GetAuthed(ctx context.Context) string {
|
||||
authedPubkey := ctx.Value(AUTH_CONTEXT_KEY)
|
||||
if authedPubkey == nil {
|
||||
return ""
|
||||
}
|
||||
return authedPubkey.(string)
|
||||
return GetConnection(ctx).AuthedPublicKey
|
||||
}
|
||||
|
||||
func GetIP(ctx context.Context) string {
|
||||
return xff.GetRemoteAddr(GetConnection(ctx).Request)
|
||||
}
|
||||
|
||||
func GetOpenSubscriptions(ctx context.Context) []nostr.Filter {
|
||||
if listeners, ok := listeners.Load(GetConnection(ctx)); ok {
|
||||
res := make([]nostr.Filter, 0, listeners.Size()*2)
|
||||
listeners.Range(func(_ string, listener *Listener) bool {
|
||||
res = append(res, listener.filters...)
|
||||
return true
|
||||
})
|
||||
return res
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user