-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpush.go
40 lines (36 loc) · 996 Bytes
/
webpush.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package push
import (
"github.com/ZNotify/server/app/api/common"
"github.com/ZNotify/server/app/manager/push"
"github.com/ZNotify/server/app/manager/push/enum"
"github.com/ZNotify/server/app/manager/push/provider/webpush"
)
type info struct {
Enable bool `json:"enable"`
PublicKey string `json:"public_key"`
}
// WebPush
//
// @Summary Endpoint for webpush info check
// @Id webpush
// @Tags Push
// @Description Check if this znotify instance support webpush and get public key
// @Produce json
// @Success 200 {object} common.Response[info]
// @Router /webpush [get]
func WebPush(ctx *common.Context) {
enable := push.IsSenderActive(enum.SenderWebPush)
if enable {
sender, _ := push.GetSender(enum.SenderWebPush)
webpushSender := sender.(*webpush.Provider)
ctx.JSONResult(info{
Enable: true,
PublicKey: webpushSender.VAPIDPublicKey,
})
} else {
ctx.JSONResult(info{
Enable: false,
PublicKey: "",
})
}
}