add clickable notification

This commit is contained in:
2026-04-10 10:14:19 +02:00
parent 0ce248b2f9
commit 8ae5dfc483
4 changed files with 18 additions and 5 deletions

View File

@@ -108,6 +108,12 @@ func main() {
port = "8080" port = "8080"
} }
domain := os.Getenv("DOMAIN")
if domain == "" {
domain = "http://localhost:" + port + "/"
os.Setenv("DOMAIN", domain)
}
err = r.Run(":" + port) err = r.Run(":" + port)
if err != nil { if err != nil {
return return

View File

@@ -90,7 +90,8 @@ func (h *Handler) Upload(c *gin.Context) {
go func() { go func() {
title := "ReSendit: new upload" title := "ReSendit: new upload"
msg := fmt.Sprintf("%s (%s)\nID: %s", record.Filename, util.HumanSize(record.Size), record.ID) 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) log.Printf("ntfy publish failed: %v", err)
} }
}() }()

View File

@@ -3,11 +3,12 @@ package notify
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"os"
"strings" "strings"
"time" "time"
) )
func Publish(ntfyURL, topic, title, message string) error { func Publish(ntfyURL, topic, title, message string, clickUrl string) error {
ntfyURL = strings.TrimRight(ntfyURL, "/") ntfyURL = strings.TrimRight(ntfyURL, "/")
if ntfyURL == "" || topic == "" { if ntfyURL == "" || topic == "" {
return nil // nothing configured return nil // nothing configured
@@ -21,6 +22,8 @@ func Publish(ntfyURL, topic, title, message string) error {
req.Header.Set("Title", title) req.Header.Set("Title", title)
} }
req.Header.Set("Content-Type", "text/plain; charset=utf-8") 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} client := &http.Client{Timeout: 3 * time.Second}
res, err := client.Do(req) res, err := client.Do(req)

View File

@@ -15,12 +15,15 @@ type Handler struct {
configService ConfigService configService ConfigService
} }
// ConfigService is the small interface needed by the web layer.
type ConfigService interface { type ConfigService interface {
GetIntDefault(key string, def int) int GetIntDefault(key string, def int) int
GetInt64Default(key string, def int64) int64 GetInt64Default(key string, def int64) int64
SetString(key, value string) error GetStringDefault(key string, def string) string
GetStringDefault(key string, value 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 { func NewHandler(fileService *file.Service, cfg ConfigService) *Handler {