mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-02 01:10:42 +08:00
Merge pull request #19898 from Ultimaker/CURA-12282-url-schemes-df
Make urls schemes more robust against changes
This commit is contained in:
commit
f60090d005
@ -1895,23 +1895,20 @@ class CuraApplication(QtApplication):
|
|||||||
def on_finish(response):
|
def on_finish(response):
|
||||||
content_disposition_header_key = QByteArray("content-disposition".encode())
|
content_disposition_header_key = QByteArray("content-disposition".encode())
|
||||||
|
|
||||||
if not response.hasRawHeader(content_disposition_header_key):
|
filename = model_url.path().split("/")[-1] + ".stl"
|
||||||
Logger.log("w", "Could not find Content-Disposition header in response from {0}".format(
|
|
||||||
model_url.url()))
|
if response.hasRawHeader(content_disposition_header_key):
|
||||||
# Use the last part of the url as the filename, and assume it is an STL file
|
|
||||||
filename = model_url.path().split("/")[-1] + ".stl"
|
|
||||||
else:
|
|
||||||
# content_disposition is in the format
|
# content_disposition is in the format
|
||||||
# ```
|
# ```
|
||||||
# content_disposition attachment; "filename=[FILENAME]"
|
# content_disposition attachment; filename="[FILENAME]"
|
||||||
# ```
|
# ```
|
||||||
# Use a regex to extract the filename
|
# Use a regex to extract the filename
|
||||||
content_disposition = str(response.rawHeader(content_disposition_header_key).data(),
|
content_disposition = str(response.rawHeader(content_disposition_header_key).data(),
|
||||||
encoding='utf-8')
|
encoding='utf-8')
|
||||||
content_disposition_match = re.match(r'attachment; filename="(?P<filename>.*)"',
|
content_disposition_match = re.match(r'attachment; filename=(?P<filename>.*)',
|
||||||
content_disposition)
|
content_disposition)
|
||||||
assert content_disposition_match is not None
|
if content_disposition_match is not None:
|
||||||
filename = content_disposition_match.group("filename")
|
filename = content_disposition_match.group("filename").strip("\"")
|
||||||
|
|
||||||
tmp = tempfile.NamedTemporaryFile(suffix=filename, delete=False)
|
tmp = tempfile.NamedTemporaryFile(suffix=filename, delete=False)
|
||||||
with open(tmp.name, "wb") as f:
|
with open(tmp.name, "wb") as f:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user