Skip to content

Commit 4fa75df

Browse files
committed
fixed handling of local prints where url is an file:// path
1 parent 540aa4a commit 4fa75df

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

tools_3mf.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,15 @@ def download3mfFromFTP(filename, destFile):
6969
ftp_host = PRINTER_IP
7070
ftp_user = "bblp"
7171
ftp_pass = PRINTER_CODE
72-
remote_path = "/cache/" + filename
72+
parsed = urlparse(filename)
73+
if parsed.scheme in ("ftp", "ftps"):
74+
remote_path = parsed.path or "/"
75+
else:
76+
remote_path = filename
77+
78+
if not remote_path.startswith("/"):
79+
remote_path = "/cache/" + remote_path
80+
7381
local_path = destFile.name # 🔹 Download into the current directory
7482
encoded_remote_path = urllib.parse.quote(remote_path)
7583
with open(local_path, "wb") as f:
@@ -93,11 +101,20 @@ def download3mfFromFTP(filename, destFile):
93101

94102
log("[DEBUG] Starting file download...")
95103

96-
try:
104+
max_attempts = 3
105+
for attempt in range(1, max_attempts + 1):
106+
try:
107+
f.seek(0)
108+
f.truncate()
97109
c.perform()
98110
log("[DEBUG] File successfully downloaded!")
99-
except pycurl.error as e:
100-
log(f"[ERROR] cURL error: {e}")
111+
break
112+
except pycurl.error as e:
113+
log(f"[ERROR] cURL error on attempt {attempt}/{max_attempts}: {e}")
114+
if attempt < max_attempts:
115+
time.sleep(10)
116+
else:
117+
log("[ERROR] Giving up after repeated cURL failures.")
101118

102119
c.close()
103120

@@ -126,6 +143,10 @@ def getMetaDataFrom3mf(url):
126143
download3mfFromCloud(url, temp_file)
127144
elif url.startswith("local:"):
128145
download3mfFromLocalFilesystem(url.replace("local:", ""), temp_file)
146+
elif url.startswith("file://"):
147+
# Handle file:// URLs from MQTT by fetching the path over FTP.
148+
file_path = urlparse(url).path
149+
download3mfFromFTP(file_path, temp_file)
129150
else:
130151
download3mfFromFTP(url.replace("ftp://", "").replace(".gcode",""), temp_file)
131152

0 commit comments

Comments
 (0)