feat: add /info command (#1)

Reviewed-on: #1
Co-authored-by: mctaylors <cantsendmails@mctaylors.ru>
Co-committed-by: mctaylors <cantsendmails@mctaylors.ru>
This commit is contained in:
Macintxsh 2025-05-20 18:15:12 +03:00 committed by Forgejo
parent c70d7fe3be
commit 6141d674a9
Signed by untrusted user who does not match committer: Forgejo
GPG key ID: F2B3CB736682B201
4 changed files with 115 additions and 7 deletions

View file

@ -1,4 +1,8 @@
import re
import requests
from typing import Any
from config import app
def humanize_tags_from_json(value: str, default: str) -> str:
@ -7,6 +11,14 @@ def humanize_tags_from_json(value: str, default: str) -> str:
return default
def humanize_filesize(value: int) -> str:
for unit in ['B', 'KiB', 'MiB', 'GiB']:
if value < 1024 or unit == 'GiB':
break
value /= 1024
return f"{value:.2f} {unit}"
def format_rating(value: str) -> str | None:
match value:
case "g":
@ -22,3 +34,32 @@ def format_rating(value: str) -> str | None:
# Negative Squared Latin Capital Letter E
return "🅴"
return None
def format_status(data) -> str:
is_active = True
is_pending = data['is_pending']
is_flagged = data['is_flagged']
is_deleted = data['is_deleted']
is_banned = data['is_banned']
if is_pending | is_flagged | is_deleted:
is_active = False
status = []
if is_active:
status.append("Active")
if is_pending:
status.append("Pending")
if is_flagged:
status.append("Flagged")
if is_banned:
status.append("Banned")
return " ".join(status)
def get_json(pathname: str) -> Any | None:
r = requests.get(f"http://{app.host}/{pathname}.json")
if r.status_code != 200:
return None
return r.json()