diff --git a/cmd/server/main.go b/cmd/server/main.go index eb5b02c..00fdeea 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -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 diff --git a/internal/file/handlers.go b/internal/file/handlers.go index 2b36440..1b23fde 100644 --- a/internal/file/handlers.go +++ b/internal/file/handlers.go @@ -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) } }() diff --git a/internal/notify/ntfy.go b/internal/notify/ntfy.go index dbb2c81..3980d61 100644 --- a/internal/notify/ntfy.go +++ b/internal/notify/ntfy.go @@ -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) diff --git a/internal/web/handler.go b/internal/web/handler.go index 7ba349d..509fe5f 100644 --- a/internal/web/handler.go +++ b/internal/web/handler.go @@ -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 {