fix(routes): correct handling of embed files
Enhanced logic for handling file embeds to ensure proper processing of both downloadable and embedded files. Fixed issues related to condition checks and image embedding. This improves reliability and correctness when rendering different types of content attachments. Fixes issue with inconsistent file embed handling.
This commit is contained in:
parent
20c03bb4e0
commit
e845caff0e
1 changed files with 42 additions and 37 deletions
|
@ -158,49 +158,54 @@ def init_main_routes(app):
|
|||
for file in step["files"]:
|
||||
if file["image"] and "embedType" not in "file":
|
||||
step_imgs.append(
|
||||
{"src": proxy(file["downloadUrl"], file["name"]), "alt": file["name"]}
|
||||
{
|
||||
"src": proxy(file["downloadUrl"], file["name"]),
|
||||
"alt": file["name"],
|
||||
}
|
||||
)
|
||||
|
||||
elif not file["image"]:
|
||||
step_downloads.append(
|
||||
{
|
||||
"src": proxy(file["downloadUrl"], file["name"]),
|
||||
"name": file["name"],
|
||||
}
|
||||
)
|
||||
|
||||
else: # Leaves us with embeds
|
||||
embed_code = file["embedHtmlCode"]
|
||||
soup = BeautifulSoup(embed_code, "html.parser")
|
||||
|
||||
iframe = soup.select("iframe")[0]
|
||||
|
||||
src = iframe.get("src")
|
||||
|
||||
if src.startswith("https://content.instructables.com"):
|
||||
src = src.replace(
|
||||
"https://content.instructables.com",
|
||||
f"/proxy/?url={src}",
|
||||
if "downloadUrl" in file.keys():
|
||||
step_downloads.append(
|
||||
{
|
||||
"src": proxy(file["downloadUrl"], file["name"]),
|
||||
"name": file["name"],
|
||||
}
|
||||
)
|
||||
|
||||
elif app.config["INVIDIOUS"] and src.startswith(
|
||||
"https://www.youtube.com"
|
||||
):
|
||||
src = src.replace(
|
||||
"https://www.youtube.com", app.config["INVIDIOUS"]
|
||||
else: # Leaves us with embeds
|
||||
embed_code = file["embedHtmlCode"]
|
||||
soup = BeautifulSoup(embed_code, "html.parser")
|
||||
|
||||
iframe = soup.select("iframe")[0]
|
||||
|
||||
src = iframe.get("src")
|
||||
|
||||
if src.startswith("https://content.instructables.com"):
|
||||
src = src.replace(
|
||||
"https://content.instructables.com",
|
||||
f"/proxy/?url={src}",
|
||||
)
|
||||
|
||||
elif app.config["INVIDIOUS"] and src.startswith(
|
||||
"https://www.youtube.com"
|
||||
):
|
||||
src = src.replace(
|
||||
"https://www.youtube.com",
|
||||
app.config["INVIDIOUS"],
|
||||
)
|
||||
|
||||
elif not app.config["UNSAFE"]:
|
||||
src = "/iframe/?url=" + quote(src)
|
||||
|
||||
step_iframes.append(
|
||||
{
|
||||
"src": src,
|
||||
"width": file.get("width"),
|
||||
"height": file.get("height"),
|
||||
}
|
||||
)
|
||||
|
||||
elif not app.config["UNSAFE"]:
|
||||
src = "/iframe/?url=" + quote(src)
|
||||
|
||||
step_iframes.append(
|
||||
{
|
||||
"src": src,
|
||||
"width": file.get("width"),
|
||||
"height": file.get("height"),
|
||||
}
|
||||
)
|
||||
|
||||
step_text = step["body"]
|
||||
step_text = step_text.replace(
|
||||
"https://content.instructables.com",
|
||||
|
|
Loading…
Reference in a new issue