fix: upload images to Spiele/<year>/ directory on publish

This commit is contained in:
Hermes Agent
2026-06-19 00:50:43 +02:00
parent 7629eecc24
commit 0f787589fe
+4 -1
View File
@@ -1220,9 +1220,12 @@ h1{color:#c0392b;}p{color:#888;}</style></head>
".gif": "image/gif"} ".gif": "image/gif"}
mime_type = mime_map.get(ext, "image/jpeg") mime_type = mime_map.get(ext, "image/jpeg")
with open(image_path, "rb") as img_f: with open(image_path, "rb") as img_f:
from datetime import datetime as dt
year = dt.now().strftime("%Y")
img_resp = requests.post( img_resp = requests.post(
"https://www.brettspiel-news.de/api/index.php/v1/media", "https://www.brettspiel-news.de/api/index.php/v1/media",
headers={"X-Joomla-Token": JOOMLA_TOKEN}, headers={"X-Joomla-Token": JOOMLA_TOKEN},
data={"path": f"Spiele/{year}/"},
files={"file": (img_filename, img_f, mime_type)}, files={"file": (img_filename, img_f, mime_type)},
timeout=30 timeout=30
) )
@@ -1233,7 +1236,7 @@ h1{color:#c0392b;}p{color:#888;}</style></head>
if "data" in img_data and "attributes" in img_data["data"]: if "data" in img_data and "attributes" in img_data["data"]:
j_img_path = img_data["data"]["attributes"].get("path", "") j_img_path = img_data["data"]["attributes"].get("path", "")
if not j_img_path: if not j_img_path:
j_img_path = f"images/{datetime.now().strftime('%Y/%m')}/{img_filename}" j_img_path = f"Spiele/{year}/{img_filename}"
article_payload["images"] = { article_payload["images"] = {
"image_intro": j_img_path, "image_intro": j_img_path,
"image_intro_alt": title, "image_intro_alt": title,