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"
}
domain := os.Getenv("DOMAIN")
if domain == "" {
domain = "http://localhost:" + port + "/"
os.Setenv("DOMAIN", domain)
}
err = r.Run(":" + port)
if err != nil {
return

View File

@@ -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)
}
}()

View File

@@ -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)

View File

@@ -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 {