Compare commits
No commits in common. "c753321eb629c0946cdf1b0582c858195dee79c5" and "34072739598061617459dfceb06c692356a1aaa5" have entirely different histories.
c753321eb6
...
3407273959
Binary file not shown.
Binary file not shown.
@ -82,14 +82,6 @@ def getRecipe(site, payload:tuple, convert=True):
|
|||||||
except (Exception, psycopg2.DatabaseError) as error:
|
except (Exception, psycopg2.DatabaseError) as error:
|
||||||
raise postsqldb.DatabaseError(error, payload, sql)
|
raise postsqldb.DatabaseError(error, payload, sql)
|
||||||
|
|
||||||
def getPicturePath(site:str, payload:tuple, convert:bool=True):
|
|
||||||
database_config = config.config()
|
|
||||||
with psycopg2.connect(**database_config) as conn:
|
|
||||||
with conn.cursor() as cur:
|
|
||||||
cur.execute(f"SELECT picture_path FROM {site}_recipes WHERE id=%s;", payload)
|
|
||||||
rows = cur.fetchone()[0]
|
|
||||||
return rows
|
|
||||||
|
|
||||||
def postRecipe(site:str, payload:tuple, convert=True):
|
def postRecipe(site:str, payload:tuple, convert=True):
|
||||||
database_config = config.config()
|
database_config = config.config()
|
||||||
record = ()
|
record = ()
|
||||||
|
|||||||
@ -5,6 +5,7 @@ from main import unfoldCostLayers
|
|||||||
from user_api import login_required
|
from user_api import login_required
|
||||||
import os
|
import os
|
||||||
import postsqldb, webpush
|
import postsqldb, webpush
|
||||||
|
from flasgger import swag_from
|
||||||
from scripts.recipes import database_recipes
|
from scripts.recipes import database_recipes
|
||||||
from scripts import postsqldb as db
|
from scripts import postsqldb as db
|
||||||
from flask_restx import Api, fields
|
from flask_restx import Api, fields
|
||||||
@ -226,45 +227,27 @@ def postSKUItem():
|
|||||||
return jsonify({'recipe': recipe, 'error': True, 'message': f'method {request.method} is not allowed!'})
|
return jsonify({'recipe': recipe, 'error': True, 'message': f'method {request.method} is not allowed!'})
|
||||||
|
|
||||||
@recipes_api.route('/recipe/postImage/<recipe_id>', methods=["POST"])
|
@recipes_api.route('/recipe/postImage/<recipe_id>', methods=["POST"])
|
||||||
@login_required
|
|
||||||
def uploadImage(recipe_id):
|
def uploadImage(recipe_id):
|
||||||
""" post an image for a recipe into the database and files by passing the recipe_id and picture_path
|
|
||||||
---
|
|
||||||
parameters:
|
|
||||||
- name: recipe_id
|
|
||||||
in: path
|
|
||||||
required: true
|
|
||||||
schema:
|
|
||||||
type: integer
|
|
||||||
responses:
|
|
||||||
200:
|
|
||||||
description: image uploaded succesfully!
|
|
||||||
"""
|
|
||||||
file = request.files['file']
|
file = request.files['file']
|
||||||
file_path = current_app.config['UPLOAD_FOLDER'] + f"/recipes/{file.filename.replace(" ", "_")}"
|
file_path = current_app.config['UPLOAD_FOLDER'] + f"/recipes/{file.filename.replace(" ", "_")}"
|
||||||
file.save(file_path)
|
file.save(file_path)
|
||||||
|
|
||||||
|
database_config = config()
|
||||||
site_name = session['selected_site']
|
site_name = session['selected_site']
|
||||||
database_recipes.postRecipeUpdate(site_name, {'id': recipe_id, 'update': {'picture_path': file.filename.replace(" ", "_")}})
|
with psycopg2.connect(**database_config) as conn:
|
||||||
return jsonify({'error': False, 'message': 'Recipe was updated successfully!'})
|
postsqldb.RecipesTable.updateRecipe(conn, site_name, {'id': recipe_id, 'update': {'picture_path': file.filename.replace(" ", "_")}})
|
||||||
|
|
||||||
|
return jsonify({})
|
||||||
|
|
||||||
@recipes_api.route('/recipe/getImage/<recipe_id>')
|
@recipes_api.route('/recipe/getImage/<recipe_id>')
|
||||||
@login_required
|
|
||||||
def get_image(recipe_id):
|
def get_image(recipe_id):
|
||||||
""" get the picture path for a recipe by passing teh recipe id in the path
|
database_config = config()
|
||||||
---
|
|
||||||
parameters:
|
|
||||||
- name: recipe_id
|
|
||||||
in: path
|
|
||||||
required: true
|
|
||||||
schema:
|
|
||||||
type: integer
|
|
||||||
responses:
|
|
||||||
200:
|
|
||||||
description: image fetched succesfully!
|
|
||||||
"""
|
|
||||||
site_name = session['selected_site']
|
site_name = session['selected_site']
|
||||||
picture_path = database_recipes.getPicturePath(site_name, (recipe_id,))
|
with psycopg2.connect(**database_config) as conn:
|
||||||
return send_from_directory('static/pictures/recipes', picture_path)
|
with conn.cursor() as cur:
|
||||||
|
cur.execute(f"SELECT picture_path FROM {site_name}_recipes WHERE id=%s;", (recipe_id,))
|
||||||
|
rows = cur.fetchone()[0]
|
||||||
|
return send_from_directory('static/pictures/recipes', rows)
|
||||||
|
|
||||||
@recipes_api.route('/recipe/deleteRecipeItem', methods=["POST"])
|
@recipes_api.route('/recipe/deleteRecipeItem', methods=["POST"])
|
||||||
def deleteRecipeItem():
|
def deleteRecipeItem():
|
||||||
|
|||||||
@ -1,16 +0,0 @@
|
|||||||
version: '3.4'
|
|
||||||
services:
|
|
||||||
speedtest-tracker:
|
|
||||||
container_name: speedtest-tracker
|
|
||||||
ports:
|
|
||||||
- 8080:80
|
|
||||||
- 8443:443
|
|
||||||
environment:
|
|
||||||
- PUID=1000
|
|
||||||
- PGID=1000
|
|
||||||
- DB_CONNECTION=sqlite
|
|
||||||
volumes:
|
|
||||||
- ./data:/config
|
|
||||||
- ./keys:/config/keys
|
|
||||||
image: lscr.io/linuxserver/speedtest-tracker:latest
|
|
||||||
restart: unless-stopped
|
|
||||||
Loading…
x
Reference in New Issue
Block a user