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
6 changes: 4 additions & 2 deletions frontend/src/components/queue/ImportMethods.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ function EnhancedUploadSection() {
const categories = config?.sabnzbd?.categories ?? [];

const validateFile = useCallback((file: File): string | null => {
if (!file.name.toLowerCase().endsWith(".nzb")) return "Only .nzb files are allowed";
const name = file.name.toLowerCase();
if (!name.endsWith(".nzb") && !name.endsWith(".nzb.gz"))
return "Only .nzb or .nzb.gz files are allowed";
if (file.size > 100 * 1024 * 1024) return "File size must be less than 100MB";
return null;
}, []);
Expand Down Expand Up @@ -482,7 +484,7 @@ function EnhancedUploadSection() {
<input
type="file"
multiple
accept=".nzb"
accept=".nzb,.nzb.gz"
onChange={handleFileInput}
className="hidden"
/>
Expand Down
4 changes: 2 additions & 2 deletions internal/api/nzb_stremio_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ func (s *Server) handleNzbStreams(c *fiber.Ctx) error {
return RespondBadRequest(c, "No file provided", "A .nzb file must be uploaded")
}

if !strings.HasSuffix(strings.ToLower(file.Filename), ".nzb") {
return RespondValidationError(c, "Invalid file type", "Only .nzb files are allowed")
if !nzbtrim.HasNzbExtension(file.Filename) {
return RespondValidationError(c, "Invalid file type", "Only .nzb or .nzb.gz files are allowed")
}

const maxUploadSize = 100 * 1024 * 1024 // 100 MB
Expand Down
5 changes: 3 additions & 2 deletions internal/api/queue_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/gofiber/fiber/v2"
"github.com/javi11/altmount/internal/database"
internalerrors "github.com/javi11/altmount/internal/errors"
"github.com/javi11/altmount/internal/importer/utils/nzbtrim"
"github.com/javi11/altmount/internal/nzblnk"
)

Expand Down Expand Up @@ -576,8 +577,8 @@ func (s *Server) handleUploadToQueue(c *fiber.Ctx) error {
}

// Validate file extension
if !strings.HasSuffix(strings.ToLower(file.Filename), ".nzb") {
return RespondValidationError(c, "Invalid file type", "Only .nzb files are allowed")
if !nzbtrim.HasNzbExtension(file.Filename) {
return RespondValidationError(c, "Invalid file type", "Only .nzb or .nzb.gz files are allowed")
}

// Validate file size (100MB limit)
Expand Down
9 changes: 5 additions & 4 deletions internal/api/sabnzbd_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/javi11/altmount/internal/database"
"github.com/javi11/altmount/internal/httpclient"
"github.com/javi11/altmount/internal/importer/utils"
"github.com/javi11/altmount/internal/importer/utils/nzbtrim"
"github.com/javi11/altmount/internal/pathutil"
)

Expand Down Expand Up @@ -319,8 +320,8 @@ func (s *Server) handleSABnzbdAddFile(c *fiber.Ctx) error {
}

// Validate file extension
if !strings.HasSuffix(strings.ToLower(file.Filename), ".nzb") {
return s.writeSABnzbdErrorFiber(c, "Invalid file type, must be .nzb")
if !nzbtrim.HasNzbExtension(file.Filename) {
return s.writeSABnzbdErrorFiber(c, "Invalid file type, must be .nzb or .nzb.gz")
}

// Get and validate category from form first
Expand Down Expand Up @@ -475,8 +476,8 @@ func (s *Server) handleSABnzbdAddUrl(c *fiber.Ctx) error {
filename = "downloaded.nzb"
}

// Ensure .nzb extension
if !strings.HasSuffix(strings.ToLower(filename), ".nzb") {
// Ensure .nzb or .nzb.gz extension
if !nzbtrim.HasNzbExtension(filename) {
filename += ".nzb"
}

Expand Down
5 changes: 3 additions & 2 deletions internal/importer/scanner/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"strings"
"sync"
"time"

"github.com/javi11/altmount/internal/importer/utils/nzbtrim"
)

// QueueAdder defines the interface for adding items to the queue
Expand Down Expand Up @@ -176,8 +178,7 @@ func (d *DirectoryScanner) performScan(ctx context.Context, scanPath string) {
d.info.FilesFound++
d.mu.Unlock()

ext := strings.ToLower(path)
if !strings.HasSuffix(ext, ".nzb") && !strings.HasSuffix(ext, ".strm") {
if !nzbtrim.HasNzbExtension(path) && !strings.HasSuffix(strings.ToLower(path), ".strm") {
return nil
}

Expand Down
3 changes: 2 additions & 1 deletion internal/importer/scanner/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/javi11/altmount/internal/config"
"github.com/javi11/altmount/internal/database"
"github.com/javi11/altmount/internal/importer/utils/nzbtrim"
)

// WatchQueueAdder interface for adding items to the import queue from directory watcher
Expand Down Expand Up @@ -113,7 +114,7 @@ func (w *Watcher) scanDirectory(ctx context.Context, watchDir string) {
}

// Check extension
if !strings.HasSuffix(strings.ToLower(d.Name()), ".nzb") {
if !nzbtrim.HasNzbExtension(d.Name()) {
return nil
}

Expand Down
6 changes: 6 additions & 0 deletions internal/importer/utils/nzbtrim/nzb_trim.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ func TrimNzbExtension(filename string) string {
// Fallback to standard extension removal if it's not a known NZB extension
return strings.TrimSuffix(filename, filepath.Ext(filename))
}

// HasNzbExtension returns true when filename ends with .nzb or .nzb.gz (case-insensitive).
func HasNzbExtension(filename string) bool {
lower := strings.ToLower(filename)
return strings.HasSuffix(lower, ".nzb") || strings.HasSuffix(lower, ".nzb.gz")
}
Loading