refactor: replace two seperate download url properties by only one
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user