add clickable notification
This commit is contained in:
@@ -90,7 +90,8 @@ func (h *Handler) Upload(c *gin.Context) {
|
||||
go func() {
|
||||
title := "ReSendit: new upload"
|
||||
msg := fmt.Sprintf("%s (%s)\nID: %s", record.Filename, util.HumanSize(record.Size), record.ID)
|
||||
if err := notify.Publish(ntfyURL, topic, title, msg); err != nil {
|
||||
clickUrl := fmt.Sprintf("f/%s", record.ViewID)
|
||||
if err := notify.Publish(ntfyURL, topic, title, msg, clickUrl); err != nil {
|
||||
log.Printf("ntfy publish failed: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -3,11 +3,12 @@ package notify
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Publish(ntfyURL, topic, title, message string) error {
|
||||
func Publish(ntfyURL, topic, title, message string, clickUrl string) error {
|
||||
ntfyURL = strings.TrimRight(ntfyURL, "/")
|
||||
if ntfyURL == "" || topic == "" {
|
||||
return nil // nothing configured
|
||||
@@ -21,6 +22,8 @@ func Publish(ntfyURL, topic, title, message string) error {
|
||||
req.Header.Set("Title", title)
|
||||
}
|
||||
req.Header.Set("Content-Type", "text/plain; charset=utf-8")
|
||||
domain := os.Getenv("DOMAIN")
|
||||
req.Header.Set("Click", fmt.Sprintf("%s%s", domain, clickUrl))
|
||||
|
||||
client := &http.Client{Timeout: 3 * time.Second}
|
||||
res, err := client.Do(req)
|
||||
|
||||
@@ -15,12 +15,15 @@ type Handler struct {
|
||||
configService ConfigService
|
||||
}
|
||||
|
||||
// ConfigService is the small interface needed by the web layer.
|
||||
type ConfigService interface {
|
||||
GetIntDefault(key string, def int) int
|
||||
GetInt64Default(key string, def int64) int64
|
||||
SetString(key, value string) error
|
||||
GetStringDefault(key string, value string) string
|
||||
GetStringDefault(key string, def string) string
|
||||
|
||||
//SetInt(key string, value int) error
|
||||
//SetInt64(key string, value int64) error
|
||||
//SetBool(key string, value bool) error
|
||||
SetString(key string, value string) error
|
||||
}
|
||||
|
||||
func NewHandler(fileService *file.Service, cfg ConfigService) *Handler {
|
||||
|
||||
Reference in New Issue
Block a user