Skip to content

Commit

Permalink
Fix upload invalid SVG file
Browse files Browse the repository at this point in the history
  • Loading branch information
safaariman committed Dec 19, 2021
1 parent c71e4d3 commit ec886f1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion filer/templates/admin/filer/folder/directory_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
{{ file.owner|default:"n/a" }}
</td>
<td class="column-size">
<span class="tiny"> ({{ file.size|filesize:"auto1000long" }}{% ifequal file.file_type "Image" %}, {{ file.width|floatformat }}x{{ file.height|floatformat }} px{% endifequal %})</span>
<span class="tiny"> ({{ file.size|filesize:"auto1000long" }}{% if file.file_type == "Image" and file.width > 0.0 and file.height > 0.0 %}, {{ file.width|floatformat }}x{{ file.height|floatformat }} px{% endif %})</span>
</td>
<td class="column-action">
<a href="{{ file.canonical_url }}"
Expand Down
26 changes: 16 additions & 10 deletions filer/templatetags/filer_admin_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,23 @@ def file_icon_context(file, detail, width, height):
context['download_url'] = file.url
if isinstance(file, BaseImage):
thumbnailer = get_thumbnailer(file)
if detail:
width, height = 210, ceil(210 / file.width * file.height)
context['sidebar_image_ratio'] = file.width / 210
opts = {'size': (width, height), 'upscale': True}

# SVG files may contain multiple vector graphics, and width and height are not available for them. If file does
# not have width or height just ignore the thumbnail icon. Otherwise, continue with the standard procedure.
if file.width == 0.0 or file.height == 0.0:
icon_url = staticfiles_storage.url('filer/icons/file-unknown.svg')
else:
opts = {'size': (width, height), 'crop': True}
icon_url = thumbnailer.get_thumbnail(opts).url
context['alt_text'] = file.default_alt_text
if mime_subtype != 'svg+xml':
opts['size'] = 2 * width, 2 * height
context['highres_url'] = thumbnailer.get_thumbnail(opts).url
if detail:
width, height = 210, ceil(210 / file.width * file.height)
context['sidebar_image_ratio'] = file.width / 210
opts = {'size': (width, height), 'upscale': True}
else:
opts = {'size': (width, height), 'crop': True}
icon_url = thumbnailer.get_thumbnail(opts).url
context['alt_text'] = file.default_alt_text
if mime_subtype != 'svg+xml':
opts['size'] = 2 * width, 2 * height
context['highres_url'] = thumbnailer.get_thumbnail(opts).url
elif mime_maintype in ['audio', 'font', 'video']:
icon_url = staticfiles_storage.url('filer/icons/file-{}.svg'.format(mime_maintype))
elif mime_maintype == 'application' and mime_subtype in ['zip', 'pdf']:
Expand Down

0 comments on commit ec886f1

Please sign in to comment.