Skip to content

Commit 7ac611f

Browse files
committed
Update static-libs-download.py
1 parent 1a4994e commit 7ac611f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

django_auto_static_libs/management/commands/static-libs-download.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,22 @@ def handle(self, *args, **kwargs):
6767
for rfile in r:
6868
z = None
6969

70+
# some work on the url to detect the correct filetype later:
71+
if isinstance(rfile,requests.Response) and hasattr(rfile.headers,"Content-Disposition") and "filename" in getattr(rfile.headers,"Content-Disposition"):
72+
url=getattr(rfile.headers,"Content-Disposition").split("filename=")[1]
73+
else:
74+
url=rfile.url
75+
7076
# when zip extract it directly
71-
if isinstance(rfile,requests.Response) and rfile.headers.get('content-type') == "application/zip":
77+
if isinstance(rfile,requests.Response) and (rfile.headers.get('content-type') == "application/zip" or '.zip' in url):
7278
z = zipfile.ZipFile(io.BytesIO(rfile.content))
7379
elif isinstance(rfile,requests.Response):
7480
#create empty temporary zip file if z not yet exists
7581
if z is None:
7682
bytes_zip_buffer = io.BytesIO(b'PK\x05\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
7783
z = zipfile.ZipFile(bytes_zip_buffer, "a", zipfile.ZIP_DEFLATED, False)
7884

79-
z.writestr(os.path.basename(rfile.url),rfile.content)
85+
z.writestr(os.path.basename(url),rfile.content)
8086
else:
8187
print("Currently the files or method to download is not supported yet",rfile)
8288
if z is not None:

0 commit comments

Comments
 (0)