-
-
Notifications
You must be signed in to change notification settings - Fork 595
/
admin_about.py
81 lines (64 loc) · 2.95 KB
/
admin_about.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import asyncio
import random
import shutil
import string
from fastapi import APIRouter, BackgroundTasks
from recipe_scrapers import __version__ as recipe_scraper_version
from mealie.core.release_checker import get_latest_version
from mealie.core.settings.static import APP_VERSION
from mealie.routes._base import BaseAdminController, controller
from mealie.schema.admin.about import AdminAboutInfo, AppStatistics, CheckAppConfig, DockerVolumeText
router = APIRouter(prefix="/about")
@controller(router)
class AdminAboutController(BaseAdminController):
@router.get("", response_model=AdminAboutInfo)
def get_app_info(self):
"""Get general application information"""
settings = self.settings
return AdminAboutInfo(
production=settings.PRODUCTION,
version=APP_VERSION,
versionLatest=get_latest_version(),
demo_status=settings.IS_DEMO,
api_port=settings.API_PORT,
api_docs=settings.API_DOCS,
db_type=settings.DB_ENGINE,
db_url=settings.DB_URL_PUBLIC,
default_group=settings.DEFAULT_GROUP,
allow_signup=settings.ALLOW_SIGNUP,
build_id=settings.GIT_COMMIT_HASH,
recipe_scraper_version=recipe_scraper_version.__version__,
)
@router.get("/statistics", response_model=AppStatistics)
def get_app_statistics(self):
return AppStatistics(
total_recipes=self.repos.recipes.count_all(),
uncategorized_recipes=self.repos.recipes.count_uncategorized(), # type: ignore
untagged_recipes=self.repos.recipes.count_untagged(), # type: ignore
total_users=self.repos.users.count_all(),
total_groups=self.repos.groups.count_all(),
)
@router.get("/check", response_model=CheckAppConfig)
def check_app_config(self):
settings = self.settings
return CheckAppConfig(
email_ready=settings.SMTP_ENABLE,
ldap_ready=settings.LDAP_ENABLED,
base_url_set=settings.BASE_URL != "http://localhost:8080",
is_up_to_date=APP_VERSION == "develop" or APP_VERSION == "nightly" or get_latest_version() == APP_VERSION,
)
@router.get("/docker/validate", response_model=DockerVolumeText)
def validate_docker_volume(self, bg: BackgroundTasks):
validation_dir = self.folders.DATA_DIR / "docker-validation"
validation_dir.mkdir(exist_ok=True)
random_string = "".join(random.choice(string.ascii_uppercase + string.digits) for _ in range(100))
with validation_dir.joinpath("validate.txt").open("w") as f:
f.write(random_string)
async def cleanup():
await asyncio.sleep(60)
try:
shutil.rmtree(validation_dir)
except Exception as e:
self.logger.error(f"Failed to remove docker validation directory: {e}")
bg.add_task(cleanup)
return DockerVolumeText(text=random_string)