From bc595d5cfac4dc2b63ab84354abe8f18a904810c Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Fri, 2 Apr 2021 11:02:01 -0800 Subject: [PATCH] Feature/about api (#253) * fix settings * app info cleanup Co-authored-by: hay-kot --- frontend/src/App.vue | 11 +++++------ frontend/src/api/meta.js | 2 +- frontend/src/components/Admin/AdminSidebar.vue | 12 ++++++------ frontend/src/store/index.js | 13 +++++++++++++ mealie/core/config.py | 6 ++++-- mealie/routes/debug_routes.py | 11 +++-------- mealie/schema/debug.py | 6 ++++++ 7 files changed, 38 insertions(+), 23 deletions(-) create mode 100644 mealie/schema/debug.py diff --git a/frontend/src/App.vue b/frontend/src/App.vue index ecba408819c3..d9de087efdc7 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -53,7 +53,6 @@ import AddRecipeFab from "@/components/UI/AddRecipeFab"; import LanguageMenu from "@/components/UI/LanguageMenu"; import Vuetify from "./plugins/vuetify"; import { user } from "@/mixins/user"; -import { api } from "./api"; export default { name: "App", @@ -76,6 +75,10 @@ export default { isMobile() { return this.$vuetify.breakpoint.name === "xs"; }, + demo() { + const appInfo = this.$store.getters.getAppInfo; + return appInfo.demoStatus; + }, }, created() { @@ -96,14 +99,11 @@ export default { this.$store.dispatch("requestTags"); this.darkModeSystemCheck(); this.darkModeAddEventListener(); - - const api_status = await api.meta.getIsDemo(); - this.demo = api_status.demoStatus; + this.$store.dispatch("requestAppInfo"); }, data: () => ({ search: false, - demo: false, }), methods: { // For Later! @@ -166,7 +166,6 @@ export default { opacity: 0.9 !important; } - *::-webkit-scrollbar { width: 0.25rem; } diff --git a/frontend/src/api/meta.js b/frontend/src/api/meta.js index 88ecd80be208..e1aed1fe1776 100644 --- a/frontend/src/api/meta.js +++ b/frontend/src/api/meta.js @@ -10,7 +10,7 @@ const debugURLs = { }; export const metaAPI = { - async get_version() { + async getAppInfo() { let response = await apiReq.get(debugURLs.version); return response.data; }, diff --git a/frontend/src/components/Admin/AdminSidebar.vue b/frontend/src/components/Admin/AdminSidebar.vue index 5e719307b23d..35876ef41ee0 100644 --- a/frontend/src/components/Admin/AdminSidebar.vue +++ b/frontend/src/components/Admin/AdminSidebar.vue @@ -83,7 +83,7 @@ {{ $t("settings.current") }} - {{ version }} + {{ appVersion }} (a.slug > b.slug ? 1 : -1)), getAllTags: state => state.allTags.sort((a, b) => (a.slug > b.slug ? 1 : -1)), + getAppInfo: state => state.appInfo, }, }); diff --git a/mealie/core/config.py b/mealie/core/config.py index 260768a1b9d2..b349d0337f19 100644 --- a/mealie/core/config.py +++ b/mealie/core/config.py @@ -12,7 +12,7 @@ CWD = Path(__file__).parent BASE_DIR = CWD.parent.parent ENV = BASE_DIR.joinpath(".env") -PRODUCTION = os.environ.get("ENV") +PRODUCTION = os.getenv("ENV", "False").lower() in ["true", "1"] def determine_data_dir(production: bool) -> Path: @@ -111,7 +111,7 @@ class AppSettings(BaseSettings): SQLITE_FILE: Optional[Union[str, Path]] @validator("SQLITE_FILE", pre=True) - def identify_sqlite_file(_cls, v: str) -> Optional[str]: + def identify_sqlite_file(cls, v: str) -> Optional[str]: return app_dirs.SQLITE_DIR.joinpath(f"mealie_{DB_VERSION}.sqlite") DEFAULT_GROUP: str = "Home" @@ -127,3 +127,5 @@ class AppSettings(BaseSettings): settings = AppSettings() + +print(settings.dict()) diff --git a/mealie/routes/debug_routes.py b/mealie/routes/debug_routes.py index 1a0332b7aaad..5b0392ccdf6d 100644 --- a/mealie/routes/debug_routes.py +++ b/mealie/routes/debug_routes.py @@ -3,20 +3,15 @@ import json from fastapi import APIRouter, Depends from mealie.core.config import APP_VERSION, LOGGER_FILE, app_dirs, settings from mealie.routes.deps import get_current_user +from mealie.schema.debug import AppInfo router = APIRouter(prefix="/api/debug", tags=["Debug"]) @router.get("/version") -async def get_mealie_version(current_user=Depends(get_current_user)): +async def get_mealie_version(): """ Returns the current version of mealie""" - return {"version": APP_VERSION} - - -@router.get("/is-demo") -async def get_demo_status(): - print(settings.IS_DEMO) - return {"demoStatus": settings.IS_DEMO} + return AppInfo(version=APP_VERSION, demo_status=settings.IS_DEMO) @router.get("/last-recipe-json") diff --git a/mealie/schema/debug.py b/mealie/schema/debug.py new file mode 100644 index 000000000000..e0b8fccb3b19 --- /dev/null +++ b/mealie/schema/debug.py @@ -0,0 +1,6 @@ +from fastapi_camelcase import CamelModel + + +class AppInfo(CamelModel): + version: str + demo_status: bool