diff --git a/kiauh/components/webui_client/base_data.py b/kiauh/components/webui_client/base_data.py index 0fe34da..3e7ce42 100644 --- a/kiauh/components/webui_client/base_data.py +++ b/kiauh/components/webui_client/base_data.py @@ -59,12 +59,7 @@ class BaseWebClient(ABC): @property @abstractmethod - def stable_url(self) -> str: - raise NotImplementedError - - @property - @abstractmethod - def unstable_url(self) -> str: + def download_url(self) -> str: raise NotImplementedError @property diff --git a/kiauh/components/webui_client/client_utils.py b/kiauh/components/webui_client/client_utils.py index 2d1d5bd..819bcd6 100644 --- a/kiauh/components/webui_client/client_utils.py +++ b/kiauh/components/webui_client/client_utils.py @@ -22,10 +22,11 @@ from components.webui_client.base_data import ( from components.webui_client.mainsail_data import MainsailData from core.backup_manager.backup_manager import BackupManager from core.repo_manager.repo_manager import RepoManager +from core.settings.kiauh_settings import KiauhSettings from utils import NGINX_SITES_AVAILABLE, NGINX_CONFD from utils.common import get_install_status_webui from utils.constants import COLOR_CYAN, RESET_FORMAT, COLOR_YELLOW -from utils.git_utils import get_latest_tag +from utils.git_utils import get_latest_tag, get_latest_unstable_tag from utils.logger import Logger @@ -201,3 +202,20 @@ def config_for_other_client_exist(client_to_ignore: WebClientType) -> bool: clients = clients - {client_to_ignore.value} return True if len(clients) > 0 else False + + +def get_download_url(base_url: str, client: BaseWebClient) -> str: + settings = KiauhSettings() + use_unstable = settings.get(client.name, "unstable_releases") + stable_url = f"{base_url}/latest/download/{client.name}.zip" + + if not use_unstable: + return stable_url + + try: + unstable_tag = get_latest_unstable_tag(client.repo_path) + if unstable_tag == "": + raise Exception + return f"{base_url}/download/{unstable_tag}/{client.name}.zip" + except Exception: + return stable_url diff --git a/kiauh/components/webui_client/fluidd_data.py b/kiauh/components/webui_client/fluidd_data.py index 4099eeb..6d34279 100644 --- a/kiauh/components/webui_client/fluidd_data.py +++ b/kiauh/components/webui_client/fluidd_data.py @@ -18,8 +18,8 @@ from components.webui_client.base_data import ( WebClientType, BaseWebClient, ) +from components.webui_client.client_utils import get_download_url from core.backup_manager import BACKUP_ROOT_DIR -from utils.git_utils import get_latest_unstable_tag @dataclass(frozen=True) @@ -46,19 +46,8 @@ class FluiddData(BaseWebClient): repo_path: str = "fluidd-core/fluidd" @property - def stable_url(self) -> str: - return f"{self.BASE_DL_URL}/latest/download/fluidd.zip" - - @property - def unstable_url(self) -> str: - try: - unstable_tag = get_latest_unstable_tag(self.repo_path) - if unstable_tag != "": - return f"{self.BASE_DL_URL}/download/{unstable_tag}/fluidd.zip" - else: - raise Exception - except Exception: - return self.stable_url + def download_url(self) -> str: + return get_download_url(self.BASE_DL_URL, self) @property def client_config(self) -> BaseWebClientConfig: diff --git a/kiauh/components/webui_client/mainsail_data.py b/kiauh/components/webui_client/mainsail_data.py index 208ce2c..91299c2 100644 --- a/kiauh/components/webui_client/mainsail_data.py +++ b/kiauh/components/webui_client/mainsail_data.py @@ -19,7 +19,6 @@ from components.webui_client.base_data import ( BaseWebClient, ) from core.backup_manager import BACKUP_ROOT_DIR -from utils.git_utils import get_latest_unstable_tag @dataclass(frozen=True) @@ -46,19 +45,10 @@ class MainsailData(BaseWebClient): repo_path: str = "mainsail-crew/mainsail" @property - def stable_url(self) -> str: - return f"{self.BASE_DL_URL}/latest/download/mainsail.zip" + def download_url(self) -> str: + from components.webui_client.client_utils import get_download_url - @property - def unstable_url(self) -> str: - try: - unstable_tag = get_latest_unstable_tag(self.repo_path) - if unstable_tag != "": - return f"{self.BASE_DL_URL}/download/{unstable_tag}/mainsail.zip" - else: - raise Exception - except Exception: - return self.stable_url + return get_download_url(self.BASE_DL_URL, self) @property def client_config(self) -> BaseWebClientConfig: