diff --git a/app/library/ItemDTO.py b/app/library/ItemDTO.py index e9fc570e..2619675a 100644 --- a/app/library/ItemDTO.py +++ b/app/library/ItemDTO.py @@ -134,6 +134,12 @@ class Item: preset = item.get("preset") if preset and isinstance(preset, str) and preset != Item._default_preset(): + from .Presets import Presets + + if not Presets.get_instance().has(preset): + msg = f"Preset '{preset}' does not exist." + raise ValueError(msg) + data["preset"] = preset if item.get("folder") and isinstance(item.get("folder"), str): diff --git a/app/library/Presets.py b/app/library/Presets.py index cfec885b..a123e7c3 100644 --- a/app/library/Presets.py +++ b/app/library/Presets.py @@ -266,6 +266,19 @@ class Presets(metaclass=Singleton): return self + def has(self, id_or_name: str) -> bool: + """ + Check if the preset exists by id or name. + + Args: + id_or_name (str): The id or name of the preset. + + Returns: + bool: True if the preset exists, False otherwise. + + """ + return self.get(id_or_name) is not None + def get(self, id_or_name: str) -> Preset | None: """ Get the preset by id or name.