feat: establish NekoNest Cloud control and relay
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package pushsink
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/klarkxy/nekonest/relaycore"
|
||||
corestore "github.com/klarkxy/nekonest/relaycore/store"
|
||||
webpush "github.com/klarkxy/nekonest/relaycore/webpush"
|
||||
)
|
||||
|
||||
type Sink struct{}
|
||||
|
||||
func (Sink) Enabled() bool { return webpush.Enabled() }
|
||||
func (Sink) PublicKey() string { return webpush.PublicKey() }
|
||||
|
||||
func (Sink) Validate(endpoint, p256dh, auth string) error {
|
||||
if err := webpush.ValidateEndpoint(endpoint); err != nil {
|
||||
return err
|
||||
}
|
||||
return webpush.ValidateKeys(p256dh, auth)
|
||||
}
|
||||
|
||||
func (Sink) Send(_ context.Context, subscriptions []corestore.PushSubscription, message relaycore.PushMessage, onGone func(string)) bool {
|
||||
converted := make([]webpush.Subscription, 0, len(subscriptions))
|
||||
for _, subscription := range subscriptions {
|
||||
converted = append(converted, webpush.Subscription{
|
||||
Endpoint: subscription.Endpoint,
|
||||
P256DH: subscription.P256DH,
|
||||
Auth: subscription.Auth,
|
||||
})
|
||||
}
|
||||
return webpush.Send(converted, message.Title, message.Body, message.URL, message.DeviceID, message.SessionID, onGone)
|
||||
}
|
||||
Reference in New Issue
Block a user