Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions internal/api/arrs_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,14 @@ func (s *Server) handleArrsWebhook(c *fiber.Ctx) error {
var releaseDate *time.Time
var sourceNzb *string

// Handle Rename specifically: try to find and re-link old record
if req.EventType == "Rename" {
// Handle Rename and Download specifically: try to find and re-link old record
if req.EventType == "Rename" || req.EventType == "Download" {
fileName := filepath.Base(normalizedPath)
// Try to find a record with the same filename but currently under /complete/
// or with a NULL library_path
if err := s.healthRepo.RelinkFileByFilename(c.Context(), fileName, normalizedPath, path); err == nil {
slog.InfoContext(c.Context(), "Successfully re-linked health record during Rename webhook",
"filename", fileName, "new_library_path", path)
slog.InfoContext(c.Context(), "Successfully re-linked health record during webhook",
"event", req.EventType, "filename", fileName, "new_library_path", path)
continue // Successfully re-linked, no need to add new
}
}
Expand Down
35 changes: 24 additions & 11 deletions internal/database/health_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -1506,18 +1506,31 @@ func (r *HealthRepository) RenameHealthRecord(ctx context.Context, oldPath, newP
oldPath = strings.TrimPrefix(oldPath, "/")
newPath = strings.TrimPrefix(newPath, "/")

query := `
UPDATE file_health
SET file_path = ?,
library_path = CASE
WHEN library_path = ? THEN ?
ELSE library_path
END,
updated_at = datetime('now')
WHERE file_path = ?
`
query := `

UPDATE file_health

SET file_path = ?,

library_path = CASE

_, err := r.db.ExecContext(ctx, query, newPath, oldPath, newPath, oldPath)
WHEN library_path IS NULL OR library_path = ? OR library_path = '/' || ? OR library_path LIKE '%' || ? THEN ?

ELSE library_path

END,

updated_at = datetime('now')

WHERE file_path = ?

`



_, err := r.db.ExecContext(ctx, query, newPath, oldPath, oldPath, oldPath, newPath, oldPath)


if err != nil {
return fmt.Errorf("failed to rename health record: %w", err)
}
Expand Down
Loading