From 12b758542384b289a7ea67ebc9c638138b23f720 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Wed, 1 Jan 2025 13:31:03 +0100 Subject: [PATCH] add cover and description support --- README.md | 24 +++++++++++++----------- requirements.txt | 3 ++- sync/core/Config.py | 33 +++++++++++++++++++++++++++++++++ sync/core/Config.pyi | 6 ++++++ sync/core/Index.py | 2 ++ sync/model/ModulesJson.pyi | 2 ++ 6 files changed, 58 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 8ec3459..081b1f0 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,7 @@ options: "support": "https://github.com/Googlers-Repo/repo/issues", "donate": "https://github.com/sponsors/DerGoogler", "submission": null, + "description": null, "base_url": "https://gr.dergoogler.com/repo/", "max_num": 3, "enable_log": true, @@ -120,17 +121,18 @@ options: } ``` -| Key | Attribute | Description | -| ---------- | --------- | ----------------------------------------------- | -| name | required | Name of your module repository | -| base_url | required | Need to end with `/` | -| website | optional | Name of your website | -| donate | optional | Name of your donation url | -| submission | optional | Link to your submission requests | -| support | optional | Link to your support chat | -| max_num | optional | Max num of versions for modules, default is `3` | -| enable_log | optional | default is `true` | -| log_dir | optional | default is `null` | +| Key | Attribute | Description | +| ----------- | --------- | ----------------------------------------------- | +| name | required | Name of your module repository | +| base_url | required | Need to end with `/` | +| website | optional | Name of your website | +| donate | optional | Name of your donation url | +| submission | optional | Link to your submission requests | +| description | optional | Describe your repository | +| support | optional | Link to your support chat | +| max_num | optional | Max num of versions for modules, default is `3` | +| enable_log | optional | default is `true` | +| log_dir | optional | default is `null` | ## track.json diff --git a/requirements.txt b/requirements.txt index 4fa45a8..b1f5e22 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,5 @@ requests>=2.31.0 tabulate>=0.9.0 gitpython>=3.1.37 validators>=0.28.3 -pyyaml>=6.0.2 \ No newline at end of file +pyyaml>=6.0.2 +python-magic>=0.4.27 \ No newline at end of file diff --git a/sync/core/Config.py b/sync/core/Config.py index 884f302..1ba65a2 100644 --- a/sync/core/Config.py +++ b/sync/core/Config.py @@ -1,3 +1,6 @@ +import os +import magic + from pathlib import Path from ..error import ConfigError @@ -9,6 +12,7 @@ class Config(ConfigJson): def __init__(self, root_folder): self._log = Log("Config", enable_log=True) self._root_folder = root_folder + self._mime = magic.Magic(mime=True) json_file = self.json_folder.joinpath(ConfigJson.filename()) if not json_file.exists(): @@ -43,6 +47,7 @@ def _check_values(self): support = self.get("support", default.support) donate = self.get("donate", default.donate) submission = self.get("submission", default.submission) + description = self.get("description", default.description) log_dir = self.get("log_dir", default.log_dir) if log_dir != default.log_dir: @@ -57,16 +62,40 @@ def _check_values(self): support=support, donate=donate, submission=submission, + description=description, + cover=self.get_cover, base_url=base_url, max_num=max_num, enable_log=enable_log, log_dir=log_dir ) + + @property + def get_cover(self): + cover_file = self.assets_folder.joinpath("cover.webp") + cover = None + + if cover_file.exists() and cover_file.suffix.lower() == '.webp': + cover_mime_type = self._mime.from_file(cover_file) + + if cover_mime_type.lower() == 'image/webp': + cover = f"{self.base_url}assets/cover.webp" + else: + self._log.warning(f"get_cover: '{cover_file.name}' is not a valid WebP image.") + else: + self._log.info(f"get_cover: '{cover_file.name}' does not exist or is not a WebP file.") + + return cover + @property def json_folder(self): return self.get_json_folder(self._root_folder) + @property + def assets_folder(self): + return self.get_assets_folder(self._root_folder) + @property def modules_folder(self): return self.get_modules_folder(self._root_folder) @@ -79,6 +108,10 @@ def local_folder(self): def get_json_folder(cls, root_folder): return root_folder.joinpath("json") + @classmethod + def get_assets_folder(cls, root_folder): + return root_folder.joinpath("assets") + @classmethod def get_modules_folder(cls, root_folder): return root_folder.joinpath("modules") diff --git a/sync/core/Config.pyi b/sync/core/Config.pyi index 485fcd9..ad89eef 100644 --- a/sync/core/Config.pyi +++ b/sync/core/Config.pyi @@ -11,14 +11,20 @@ class Config(ConfigJson): def __init__(self, root_folder: Path): ... def _check_values(self): ... @property + def validate_cover(self) -> str: ... + @property def json_folder(self) -> Path: ... @property + def assets_folder(self) -> Path: ... + @property def modules_folder(self) -> Path: ... @property def local_folder(self) -> Path: ... @classmethod def get_json_folder(cls, root_folder: Path) -> Path: ... @classmethod + def get_assets_folder(cls, root_folder: Path) -> Path: ... + @classmethod def get_modules_folder(cls, root_folder: Path) -> Path: ... @classmethod def get_local_folder(cls, root_folder: Path) -> Path: ... diff --git a/sync/core/Index.py b/sync/core/Index.py index 94118f3..842ec05 100644 --- a/sync/core/Index.py +++ b/sync/core/Index.py @@ -59,6 +59,8 @@ def _add_modules_json_1(self, track, update_json, online_module): support=self._config.support, donate=self._config.donate, submission=self._config.submission, + cover=self._config.cover, + description=self._config.description, metadata=AttrDict( version=1, timestamp=datetime.now().timestamp() diff --git a/sync/model/ModulesJson.pyi b/sync/model/ModulesJson.pyi index a5ce6b5..b370145 100644 --- a/sync/model/ModulesJson.pyi +++ b/sync/model/ModulesJson.pyi @@ -37,6 +37,8 @@ class ModulesJson(AttrDict, JsonIO): support: str donate: str submission: str + description: str + cover: str metadata: AttrDict modules: List[OnlineModule]