fix: upload images to Spiele/<year>/ directory on publish
This commit is contained in:
+4
-1
@@ -1220,9 +1220,12 @@ h1{color:#c0392b;}p{color:#888;}</style></head>
|
||||
".gif": "image/gif"}
|
||||
mime_type = mime_map.get(ext, "image/jpeg")
|
||||
with open(image_path, "rb") as img_f:
|
||||
from datetime import datetime as dt
|
||||
year = dt.now().strftime("%Y")
|
||||
img_resp = requests.post(
|
||||
"https://www.brettspiel-news.de/api/index.php/v1/media",
|
||||
headers={"X-Joomla-Token": JOOMLA_TOKEN},
|
||||
data={"path": f"Spiele/{year}/"},
|
||||
files={"file": (img_filename, img_f, mime_type)},
|
||||
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"]:
|
||||
j_img_path = img_data["data"]["attributes"].get("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"] = {
|
||||
"image_intro": j_img_path,
|
||||
"image_intro_alt": title,
|
||||
|
||||
Reference in New Issue
Block a user