Skip to content

Commit

Permalink
add cover and description support
Browse files Browse the repository at this point in the history
  • Loading branch information
DerGoogler committed Jan 1, 2025
1 parent 5fadf3d commit 12b7585
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 12 deletions.
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,26 @@ 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,
"log_dir": "log"
}
```

| 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

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ requests>=2.31.0
tabulate>=0.9.0
gitpython>=3.1.37
validators>=0.28.3
pyyaml>=6.0.2
pyyaml>=6.0.2
python-magic>=0.4.27
33 changes: 33 additions & 0 deletions sync/core/Config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os
import magic

from pathlib import Path

from ..error import ConfigError
Expand All @@ -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():
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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")
Expand Down
6 changes: 6 additions & 0 deletions sync/core/Config.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
2 changes: 2 additions & 0 deletions sync/core/Index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions sync/model/ModulesJson.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class ModulesJson(AttrDict, JsonIO):
support: str
donate: str
submission: str
description: str
cover: str
metadata: AttrDict
modules: List[OnlineModule]

Expand Down

0 comments on commit 12b7585

Please sign in to comment.