refactor: replace two seperate download url properties by only one

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
dw-0
2024-04-28 19:41:38 +02:00
parent 51f0713c5a
commit 5225e70e83
4 changed files with 26 additions and 34 deletions

View File

@@ -59,12 +59,7 @@ class BaseWebClient(ABC):
@property @property
@abstractmethod @abstractmethod
def stable_url(self) -> str: def download_url(self) -> str:
raise NotImplementedError
@property
@abstractmethod
def unstable_url(self) -> str:
raise NotImplementedError raise NotImplementedError
@property @property

View File

@@ -22,10 +22,11 @@ from components.webui_client.base_data import (
from components.webui_client.mainsail_data import MainsailData from components.webui_client.mainsail_data import MainsailData
from core.backup_manager.backup_manager import BackupManager from core.backup_manager.backup_manager import BackupManager
from core.repo_manager.repo_manager import RepoManager 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 import NGINX_SITES_AVAILABLE, NGINX_CONFD
from utils.common import get_install_status_webui from utils.common import get_install_status_webui
from utils.constants import COLOR_CYAN, RESET_FORMAT, COLOR_YELLOW 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 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} clients = clients - {client_to_ignore.value}
return True if len(clients) > 0 else False 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

View File

@@ -18,8 +18,8 @@ from components.webui_client.base_data import (
WebClientType, WebClientType,
BaseWebClient, BaseWebClient,
) )
from components.webui_client.client_utils import get_download_url
from core.backup_manager import BACKUP_ROOT_DIR from core.backup_manager import BACKUP_ROOT_DIR
from utils.git_utils import get_latest_unstable_tag
@dataclass(frozen=True) @dataclass(frozen=True)
@@ -46,19 +46,8 @@ class FluiddData(BaseWebClient):
repo_path: str = "fluidd-core/fluidd" repo_path: str = "fluidd-core/fluidd"
@property @property
def stable_url(self) -> str: def download_url(self) -> str:
return f"{self.BASE_DL_URL}/latest/download/fluidd.zip" return get_download_url(self.BASE_DL_URL, self)
@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
@property @property
def client_config(self) -> BaseWebClientConfig: def client_config(self) -> BaseWebClientConfig:

View File

@@ -19,7 +19,6 @@ from components.webui_client.base_data import (
BaseWebClient, BaseWebClient,
) )
from core.backup_manager import BACKUP_ROOT_DIR from core.backup_manager import BACKUP_ROOT_DIR
from utils.git_utils import get_latest_unstable_tag
@dataclass(frozen=True) @dataclass(frozen=True)
@@ -46,19 +45,10 @@ class MainsailData(BaseWebClient):
repo_path: str = "mainsail-crew/mainsail" repo_path: str = "mainsail-crew/mainsail"
@property @property
def stable_url(self) -> str: def download_url(self) -> str:
return f"{self.BASE_DL_URL}/latest/download/mainsail.zip" from components.webui_client.client_utils import get_download_url
@property return get_download_url(self.BASE_DL_URL, self)
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
@property @property
def client_config(self) -> BaseWebClientConfig: def client_config(self) -> BaseWebClientConfig: