mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-03 12:26:36 +08:00
fix scanner missing library errors
This commit is contained in:
@@ -1,12 +1,14 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
|
||||||
"github.com/ShukeBta/MediaStationGo/internal/config"
|
"github.com/ShukeBta/MediaStationGo/internal/config"
|
||||||
"github.com/ShukeBta/MediaStationGo/internal/model"
|
"github.com/ShukeBta/MediaStationGo/internal/model"
|
||||||
@@ -61,6 +63,30 @@ func TestIngestPathAddsSingleFile(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestScanLibraryReturnsNotFoundForMissingLibrary(t *testing.T) {
|
||||||
|
sc, _ := newScannerTestEnv(t)
|
||||||
|
|
||||||
|
res, err := sc.ScanLibrary(t.Context(), "missing-library")
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("ScanLibrary() error = nil, result = %#v", res)
|
||||||
|
}
|
||||||
|
if !errors.Is(err, gorm.ErrRecordNotFound) && err.Error() != "library not found" {
|
||||||
|
t.Fatalf("ScanLibrary() error = %v, want not found", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestIngestPathReturnsNotFoundForMissingLibrary(t *testing.T) {
|
||||||
|
sc, _ := newScannerTestEnv(t)
|
||||||
|
|
||||||
|
added, err := sc.IngestPath(t.Context(), "missing-library", filepath.Join(t.TempDir(), "movie.mkv"))
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("IngestPath() error = nil, added = %v", added)
|
||||||
|
}
|
||||||
|
if !errors.Is(err, gorm.ErrRecordNotFound) && err.Error() != "library not found" {
|
||||||
|
t.Fatalf("IngestPath() error = %v, want not found", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestScanLibraryReadsLocalSTRMTarget(t *testing.T) {
|
func TestScanLibraryReadsLocalSTRMTarget(t *testing.T) {
|
||||||
sc, repos := newScannerTestEnv(t)
|
sc, repos := newScannerTestEnv(t)
|
||||||
root := t.TempDir()
|
root := t.TempDir()
|
||||||
|
|||||||
@@ -68,9 +68,12 @@ func (s *ScannerService) TryBeginLocalScan(libraryID string) (func(), bool) {
|
|||||||
|
|
||||||
func (s *ScannerService) scanLibrary(ctx context.Context, libraryID string, autoScrape bool) (*ScanResult, error) {
|
func (s *ScannerService) scanLibrary(ctx context.Context, libraryID string, autoScrape bool) (*ScanResult, error) {
|
||||||
lib, err := s.repo.Library.FindByID(ctx, libraryID)
|
lib, err := s.repo.Library.FindByID(ctx, libraryID)
|
||||||
if err != nil || lib == nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if lib == nil {
|
||||||
|
return nil, errors.New("library not found")
|
||||||
|
}
|
||||||
if mount, ok := ParseCloudLibraryMount(lib.Path); ok {
|
if mount, ok := ParseCloudLibraryMount(lib.Path); ok {
|
||||||
return s.scanMountedCloudLibrary(ctx, lib, mount, autoScrape)
|
return s.scanMountedCloudLibrary(ctx, lib, mount, autoScrape)
|
||||||
}
|
}
|
||||||
@@ -229,9 +232,12 @@ func (s *ScannerService) finishLocalLibraryScan(ctx context.Context, lib *model.
|
|||||||
// added or updated.
|
// added or updated.
|
||||||
func (s *ScannerService) IngestPath(ctx context.Context, libraryID, path string) (bool, error) {
|
func (s *ScannerService) IngestPath(ctx context.Context, libraryID, path string) (bool, error) {
|
||||||
lib, err := s.repo.Library.FindByID(ctx, libraryID)
|
lib, err := s.repo.Library.FindByID(ctx, libraryID)
|
||||||
if err != nil || lib == nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
if lib == nil {
|
||||||
|
return false, errors.New("library not found")
|
||||||
|
}
|
||||||
root, err := s.localLibraryRootForPath(ctx, lib, path)
|
root, err := s.localLibraryRootForPath(ctx, lib, path)
|
||||||
if err != nil || root == nil {
|
if err != nil || root == nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
|||||||
Reference in New Issue
Block a user