fix(api): 修复 location 没有正确设置的问题
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Ching 2024-03-02 18:37:12 +08:00
parent 928d9685f2
commit 44bcd9f145
3 changed files with 13 additions and 7 deletions

5
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"conventionalCommits.scopes": [
"api"
]
}

11
app.py
View File

@ -26,7 +26,6 @@ GROCY_API_KEY = os.environ.get("GROCY_API_KEY")
GROCY_PORT = os.environ.get("GROCY_PORT") GROCY_PORT = os.environ.get("GROCY_PORT")
GROCY_DEFAULT_QUANTITY_UNIT_ID = os.environ.get("GROCY_DEFAULT_QUANTITY_UNIT_ID") GROCY_DEFAULT_QUANTITY_UNIT_ID = os.environ.get("GROCY_DEFAULT_QUANTITY_UNIT_ID")
GROCY_DEFAULT_BEST_BEFORE_DAYS = os.environ.get("GROCY_DEFAULT_BEST_BEFORE_DAYS") GROCY_DEFAULT_BEST_BEFORE_DAYS = os.environ.get("GROCY_DEFAULT_BEST_BEFORE_DAYS")
GROCY_LOCATION = []
X_RapidAPI_Key = os.environ.get("X_RapidAPI_Key") X_RapidAPI_Key = os.environ.get("X_RapidAPI_Key")
app = Flask(__name__) app = Flask(__name__)
@ -46,7 +45,12 @@ def add_product(dict_good, location):
good_name = dict_good["description_cn"] good_name = dict_good["description_cn"]
if not good_name: if not good_name:
return False return False
location_map = {item['name']: item['id'] for item in GROCY_LOCATION}
locations = get_locations()
if not location:
location = locations[0]['name']
location_map = {item['name']: item['id'] for item in locations}
data_grocy = { data_grocy = {
"name": good_name, "name": good_name,
"description": "", "description": "",
@ -178,9 +182,6 @@ def add():
data = request.json data = request.json
location = data.get("location", "") location = data.get("location", "")
barcode = data.get("barcode", "") barcode = data.get("barcode", "")
GROCY_LOCATION = get_locations()
if not location:
location = GROCY_LOCATION[0]['name']
try: try:
grocy.product_by_barcode(barcode) grocy.product_by_barcode(barcode)

View File

@ -6,8 +6,8 @@ services:
restart: always restart: always
environment: environment:
- GROCY_API_KEY=your-api-key - GROCY_API_KEY=your-api-key
- GROCY_BASE_URL=https://grocy.tunpok.com - GROCY_URL=https://grocy.tunpok.com
- GROCY_BARCODE_HELPER_PORT=443 - GROCY_PORT=443
- GROCY_DEFAULT_QUANTITY_UNIT_ID=1 - GROCY_DEFAULT_QUANTITY_UNIT_ID=1
- GROCY_DEFAULT_BEST_BEFORE_DAYS=365 - GROCY_DEFAULT_BEST_BEFORE_DAYS=365
ports: ports: