From 95213fa41b6402e08764f7968d40e58fb92826ba Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Fri, 2 Apr 2021 21:54:46 -0800 Subject: [PATCH] Feature/image minify (#256) * fix settings * app info cleanup * bottom-bar experiment * remove dup key * type hints * add dependency * updated image with query parameters * read image options * add image minification * add image minification step * alt image routes * add image minification * set mobile bar to top Co-authored-by: hay-kot --- dev/data/templates/recipes.md | 2 +- frontend/src/App.vue | 53 +------- frontend/src/api/category.js | 14 +-- frontend/src/api/recipe.js | 14 ++- .../src/components/MealPlan/MealPlanCard.vue | 4 +- .../src/components/MealPlan/MealPlanNew.vue | 2 +- .../components/Recipe/MobileRecipeCard.vue | 11 +- frontend/src/components/Recipe/RecipeCard.vue | 4 +- .../src/components/Recipe/RecipePrint.vue | 3 +- .../src/components/UI/Search/SearchBar.vue | 6 +- .../src/components/UI/Search/SearchDialog.vue | 49 +++++++- frontend/src/components/UI/TheAppBar.vue | 114 ++++++++++++++++++ frontend/src/mixins/utilMixins.js | 7 ++ frontend/src/pages/MealPlan/Planner.vue | 2 +- frontend/src/pages/MealPlan/ThisWeek.vue | 3 +- frontend/src/pages/Recipe/ViewRecipe.vue | 5 +- frontend/src/store/modules/userSettings.js | 2 +- frontend/src/utils/index.js | 2 +- makefile | 1 + mealie/core/config.py | 26 ++-- mealie/routes/recipe/recipe_crud_routes.py | 25 +++- mealie/services/backups/exports.py | 3 +- mealie/services/backups/imports.py | 9 +- .../services/image/__init__.py | 0 mealie/services/image/image.py | 101 ++++++++++++++++ mealie/services/image/minify.py | 84 +++++++++++++ mealie/services/image_services.py | 63 ---------- mealie/services/meal_services.py | 2 +- mealie/services/scraper/scraper.py | 2 +- poetry.lock | 45 ++++++- pyproject.toml | 1 + 31 files changed, 487 insertions(+), 172 deletions(-) create mode 100644 frontend/src/components/UI/TheAppBar.vue create mode 100644 frontend/src/mixins/utilMixins.js rename dev/data/img/.gitkeep => mealie/services/image/__init__.py (100%) create mode 100644 mealie/services/image/image.py create mode 100644 mealie/services/image/minify.py delete mode 100644 mealie/services/image_services.py diff --git a/dev/data/templates/recipes.md b/dev/data/templates/recipes.md index 84a404798444..6ee2d4bb6972 100644 --- a/dev/data/templates/recipes.md +++ b/dev/data/templates/recipes.md @@ -1,6 +1,6 @@ -![Recipe Image](../../images/{{ recipe.image }}) +![Recipe Image](../../images/{{ recipe.slug }}/original.jpg) # {{ recipe.name }} {{ recipe.description }} diff --git a/frontend/src/App.vue b/frontend/src/App.vue index d9de087efdc7..bb545577b9a9 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -1,35 +1,6 @@ diff --git a/frontend/src/api/category.js b/frontend/src/api/category.js index ef582c580478..0f8ecd3fd65c 100644 --- a/frontend/src/api/category.js +++ b/frontend/src/api/category.js @@ -5,27 +5,27 @@ import { store } from "@/store"; const prefix = baseURL + "categories"; const categoryURLs = { - get_all: `${prefix}`, - get_category: category => `${prefix}/${category}`, - delete_category: category => `${prefix}/${category}`, + getAll: `${prefix}`, + getCategory: category => `${prefix}/${category}`, + deleteCategory: category => `${prefix}/${category}`, }; export const categoryAPI = { async getAll() { - let response = await apiReq.get(categoryURLs.get_all); + let response = await apiReq.get(categoryURLs.getAll); return response.data; }, async create(name) { - let response = await apiReq.post(categoryURLs.get_all, { name: name }); + let response = await apiReq.post(categoryURLs.getAll, { name: name }); store.dispatch("requestCategories"); return response.data; }, async getRecipesInCategory(category) { - let response = await apiReq.get(categoryURLs.get_category(category)); + let response = await apiReq.get(categoryURLs.getCategory(category)); return response.data; }, async delete(category) { - let response = await apiReq.delete(categoryURLs.delete_category(category)); + let response = await apiReq.delete(categoryURLs.deleteCategory(category)); store.dispatch("requestCategories"); return response.data; }, diff --git a/frontend/src/api/recipe.js b/frontend/src/api/recipe.js index 97a4b08c4713..5eef791acf8f 100644 --- a/frontend/src/api/recipe.js +++ b/frontend/src/api/recipe.js @@ -56,9 +56,7 @@ export const recipeAPI = { const fd = new FormData(); fd.append("image", fileObject); fd.append("extension", fileObject.name.split(".").pop()); - let response = apiReq.put(recipeURLs.updateImage(recipeSlug), fd); - return response; }, @@ -87,4 +85,16 @@ export const recipeAPI = { return response.data; }, + + recipeImage(recipeSlug) { + return `/api/recipes/${recipeSlug}/image?image_type=original`; + }, + + recipeSmallImage(recipeSlug) { + return `/api/recipes/${recipeSlug}/image?image_type=small`; + }, + + recipeTinyImage(recipeSlug) { + return `/api/recipes/${recipeSlug}/image?image_type=tiny`; + }, }; diff --git a/frontend/src/components/MealPlan/MealPlanCard.vue b/frontend/src/components/MealPlan/MealPlanCard.vue index f88e27c177ca..985f039aa48f 100644 --- a/frontend/src/components/MealPlan/MealPlanCard.vue +++ b/frontend/src/components/MealPlan/MealPlanCard.vue @@ -28,8 +28,8 @@ \ No newline at end of file diff --git a/frontend/src/components/UI/TheAppBar.vue b/frontend/src/components/UI/TheAppBar.vue new file mode 100644 index 000000000000..1c556feb6a00 --- /dev/null +++ b/frontend/src/components/UI/TheAppBar.vue @@ -0,0 +1,114 @@ + + + + + \ No newline at end of file diff --git a/frontend/src/mixins/utilMixins.js b/frontend/src/mixins/utilMixins.js new file mode 100644 index 000000000000..2b9bf8504264 --- /dev/null +++ b/frontend/src/mixins/utilMixins.js @@ -0,0 +1,7 @@ +export const utilMixins = { + commputed: { + isMobile() { + return this.$vuetify.breakpoint.name === "xs"; + }, + }, +}; diff --git a/frontend/src/pages/MealPlan/Planner.vue b/frontend/src/pages/MealPlan/Planner.vue index 57df248a3835..2d472216d244 100644 --- a/frontend/src/pages/MealPlan/Planner.vue +++ b/frontend/src/pages/MealPlan/Planner.vue @@ -117,7 +117,7 @@ export default { return utils.getDateAsTextAlt(dateObject); }, getImage(image) { - return utils.getImageURL(image); + return api.recipes.recipeTinyImage(image); }, editPlan(id) { diff --git a/frontend/src/pages/MealPlan/ThisWeek.vue b/frontend/src/pages/MealPlan/ThisWeek.vue index a361ba0e16e1..e8279d319f80 100644 --- a/frontend/src/pages/MealPlan/ThisWeek.vue +++ b/frontend/src/pages/MealPlan/ThisWeek.vue @@ -52,7 +52,6 @@