From ac09c088ebb9833eb565b472aac7c9cb1a94c9a9 Mon Sep 17 00:00:00 2001 From: Cobblestone Date: Fri, 5 Jan 2024 13:21:13 -0500 Subject: [PATCH] this wont fix the api but might fix bugs --- pyproject.toml | 2 +- utilities/files.py | 7 +++---- utilities/util.py | 20 -------------------- 3 files changed, 4 insertions(+), 25 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e17cc1f..4227c43 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.ruff] # Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default. -select = ["E", "F", "PERF", "RUF", "B", "N", "PTH", "TCH", "UP"] +select = ["E", "F", "PERF", "RUF", "B", "N", "PTH", "TCH", "UP", "FURB", "ERA"] ignore = ["E501", "E722"] # Allow autofix for all enabled rules (when `--fix`) is provided. diff --git a/utilities/files.py b/utilities/files.py index c8524d9..92eb311 100644 --- a/utilities/files.py +++ b/utilities/files.py @@ -83,11 +83,10 @@ def upload_file(file: str, file_name: str, uploader: str, is_icon: bool = False) decoded = base64.b64decode(file.split(",")[1].encode("unicode_escape")) path = Path(config.DATA + "tempfile") - path.touch() - - if path.stat().st_size > 255999: + if len(decoded) > 255999: return "File too big." - + + path.touch() path.write_bytes(decoded) if is_icon: diff --git a/utilities/util.py b/utilities/util.py index 04f4301..5ea1260 100644 --- a/utilities/util.py +++ b/utilities/util.py @@ -116,26 +116,6 @@ def send_notif(conn: Connection, title: str, msg: str, receiver: int): ) -# Custom sorting function for semver -def semver_key(version: str) -> tuple[int, int, int]: - # Replace 'x' in the version with a high number for comparison - version = version.replace("x", "999999") - # Use regex to match major, minor, and patch numbers - match = re.match(r"(\d+)(?:\.(\d+))?(?:\.(\d+))?", version) - - if match: - # If there is a match, extract major, minor, and patch numbers - groups = map(int, match.groups()) - return ( - groups[0], - groups[1] if len(groups) >= 2 else 0, - groups[2] if len(groups) == 3 else 0, - ) - else: - # If no match is found, return a tuple of zeros - return 0, 0, 0 - - if __name__ == "__main__": weblogs.approval( "Silabear",