mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-12-28 13:05:26 -05:00
feat: docker volume validation (#1125)
* feat: add api endpoints for volume check * feat: add docker icon * add size prop * feat: add frontend UI for checking docker-volume * update caddy to server validation file * add more extensive documentation around setup req * fix: wrong type on user id #1123 * spelling * refactor: cleanup excessive function calls
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
from fastapi import APIRouter
|
||||
import asyncio
|
||||
import random
|
||||
import shutil
|
||||
import string
|
||||
|
||||
from fastapi import APIRouter, BackgroundTasks
|
||||
|
||||
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
|
||||
from mealie.schema.admin.about import AdminAboutInfo, AppStatistics, CheckAppConfig, DockerVolumeText
|
||||
|
||||
router = APIRouter(prefix="/about")
|
||||
|
||||
@@ -11,7 +16,7 @@ router = APIRouter(prefix="/about")
|
||||
@controller(router)
|
||||
class AdminAboutController(BaseAdminController):
|
||||
@router.get("", response_model=AdminAboutInfo)
|
||||
async def get_app_info(self):
|
||||
def get_app_info(self):
|
||||
"""Get general application information"""
|
||||
settings = self.deps.settings
|
||||
|
||||
@@ -30,18 +35,18 @@ class AdminAboutController(BaseAdminController):
|
||||
)
|
||||
|
||||
@router.get("/statistics", response_model=AppStatistics)
|
||||
async def get_app_statistics(self):
|
||||
def get_app_statistics(self):
|
||||
|
||||
return AppStatistics(
|
||||
total_recipes=self.repos.recipes.count_all(),
|
||||
uncategorized_recipes=self.repos.recipes.count_uncategorized(),
|
||||
untagged_recipes=self.repos.recipes.count_untagged(),
|
||||
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)
|
||||
async def check_app_config(self):
|
||||
def check_app_config(self):
|
||||
settings = self.deps.settings
|
||||
url_set = settings.BASE_URL != "http://localhost:8080"
|
||||
|
||||
@@ -51,3 +56,25 @@ class AdminAboutController(BaseAdminController):
|
||||
base_url_set=url_set,
|
||||
is_up_to_date=get_latest_version() == APP_VERSION,
|
||||
)
|
||||
|
||||
@router.get("/docker/validate", response_model=DockerVolumeText)
|
||||
def validate_docker_volume(self, bg: BackgroundTasks):
|
||||
validation_dir = self.deps.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.deps.logger.error(f"Failed to remove docker validation directory: {e}")
|
||||
|
||||
bg.add_task(cleanup)
|
||||
|
||||
return DockerVolumeText(text=random_string)
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
from fastapi import APIRouter
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi.responses import FileResponse
|
||||
|
||||
from mealie.core.config import get_app_dirs
|
||||
|
||||
from . import media_recipe, media_user
|
||||
|
||||
@@ -6,3 +9,15 @@ media_router = APIRouter(prefix="/api/media", tags=["Recipe: Images and Assets"]
|
||||
|
||||
media_router.include_router(media_recipe.router)
|
||||
media_router.include_router(media_user.router)
|
||||
|
||||
|
||||
@media_router.get("/docker/validate.txt", response_class=FileResponse)
|
||||
async def get_validation_text():
|
||||
folders = get_app_dirs()
|
||||
|
||||
file = folders.DATA_DIR / "docker-validation" / "validate.txt"
|
||||
|
||||
if file.exists():
|
||||
return file
|
||||
else:
|
||||
raise HTTPException(status_code=404, detail="File not found")
|
||||
|
||||
Reference in New Issue
Block a user