Merge pull request #78 from markbeep/allow-disabling-of-indexers

fix not being able to disable indexers
This commit is contained in:
Mark
2025-03-30 15:18:53 +02:00
committed by GitHub
4 changed files with 62 additions and 19 deletions

View File

@@ -17,6 +17,27 @@ class SessionContainer(BaseModel, arbitrary_types_allowed=True):
class AbstractIndexer[T: Configurations](ABC):
name: str
@staticmethod
@abstractmethod
async def get_configurations(
container: SessionContainer,
) -> T:
"""
Returns a list of configuration options that will be configurable on the frontend.
"""
pass
@abstractmethod
async def is_active(
self,
container: SessionContainer,
configurations: Any,
) -> bool:
"""
Returns true if the indexer is active and can be used.
"""
pass
@abstractmethod
async def setup(
self,
@@ -33,16 +54,6 @@ class AbstractIndexer[T: Configurations](ABC):
"""
pass
@staticmethod
@abstractmethod
async def get_configurations(
container: SessionContainer,
) -> T:
"""
Returns a list of configuration options that will be configurable on the frontend.
"""
pass
@abstractmethod
async def is_matching_source(
self, source: ProwlarrSource, container: SessionContainer

View File

@@ -21,7 +21,10 @@ class IndexerContext(BaseModel, arbitrary_types_allowed=True):
async def get_indexer_contexts(
container: SessionContainer, *, check_required: bool = True
container: SessionContainer,
*,
check_required: bool = True,
return_disabled: bool = False,
) -> list[IndexerContext]:
contexts: list[IndexerContext] = []
for Indexer in indexers:
@@ -37,9 +40,18 @@ async def get_indexer_contexts(
container.session,
check_required=check_required,
)
indexer = Indexer()
if not return_disabled and not await indexer.is_active(
container, valued_configuration
):
logger.debug("Indexer %s is disabled", Indexer.name)
continue
contexts.append(
IndexerContext(
indexer=Indexer(),
indexer=indexer,
configuration=filtered_configuration,
valued=valued_configuration,
)

View File

@@ -48,6 +48,13 @@ class MamIndexer(AbstractIndexer[MamConfigurations]):
) -> MamConfigurations:
return MamConfigurations()
async def is_active(
self,
container: SessionContainer,
configurations: ValuedMamConfigurations,
) -> bool:
return configurations.mam_active
async def setup(
self,
request: BookRequest,

View File

@@ -1,4 +1,5 @@
import json
import logging
import uuid
from typing import Annotated, Any, Optional, cast
@@ -30,6 +31,8 @@ from app.util.templates import template_response
from app.util.time import Minute
from app.util.toast import ToastException
logger = logging.getLogger(__name__)
router = APIRouter(prefix="/settings")
@@ -720,6 +723,7 @@ async def read_indexers(
contexts = await get_indexer_contexts(
SessionContainer(session=session, client_session=client_session),
check_required=False,
return_disabled=True,
)
return template_response(
@@ -747,6 +751,7 @@ async def update_indexers(
contexts = await get_indexer_contexts(
SessionContainer(session=session, client_session=client_session),
check_required=False,
return_disabled=True,
)
updated_context: Optional[IndexerContext] = None
@@ -760,14 +765,22 @@ async def update_indexers(
form_values = await request.form()
for key, value in form_values.items():
if key in updated_context.configuration and type(value) is str:
if updated_context.configuration[key].type is bool:
indexer_configuration_cache.set(
session, key, "true" if value == "on" else ""
)
for key, context in updated_context.configuration.items():
value = form_values.get(key)
if value is None: # forms do not include false checkboxes
if context.type is bool:
value = False
else:
indexer_configuration_cache.set(session, key, str(value))
logger.error(
"Missing value for '%s' while trying to update indexer", key
)
continue
if context.type is bool:
indexer_configuration_cache.set(
session, key, "true" if value == "on" else ""
)
else:
indexer_configuration_cache.set(session, key, str(value))
flush_prowlarr_cache()