add ntfy integration

This commit is contained in:
2026-03-26 14:01:08 +01:00
parent fc85e859e0
commit b0d1f17540
2 changed files with 53 additions and 0 deletions

View File

@@ -2,8 +2,10 @@ package file
import (
"ResendIt/internal/config"
"ResendIt/internal/notify"
"ResendIt/internal/util"
"fmt"
"log"
"net/http"
"path/filepath"
"strconv"
@@ -22,6 +24,7 @@ type Handler struct {
type ConfigService interface {
GetIntDefault(key string, def int) int
GetInt64Default(key string, def int64) int64
GetStringDefault(key string, def string) string
}
func NewHandler(s *Service, cfg ConfigService) *Handler {
@@ -79,6 +82,20 @@ func (h *Handler) Upload(c *gin.Context) {
return
}
enabled := h.configService.GetIntDefault(config.KeyUseNtfy, config.DefaultUseNtfy)
if enabled == 1 {
ntfyURL := h.configService.GetStringDefault(config.KeyNtfyUrl, "")
topic := h.configService.GetStringDefault(config.KeyNtfyTopic, config.DefaultNtfyTopic)
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 {
log.Printf("ntfy publish failed: %v", err)
}
}()
}
c.JSON(http.StatusOK, gin.H{
"id": record.ID,
"deletion_id": record.DeletionID,