Skip to content
Snippets Groups Projects
Unverified Commit 9f973f52 authored by Nicola Tarocco's avatar Nicola Tarocco
Browse files

csv: re-add max filesize check

parent 00ae43e2
No related branches found
No related tags found
No related merge requests found
......@@ -21,7 +21,7 @@ PREVIEWER_CHARDET_CONFIDENCE = 0.9
"""Confidence threshold for character encoding detection by `cchardet`."""
PREVIEWER_MAX_FILE_SIZE_BYTES = 1 * 1024 * 1024
"""Maximum file size in bytes for JSON/XML files."""
"""Maximum file size in bytes for JSON/XML/CSV files."""
PREVIEWER_MAX_IMAGE_SIZE_BYTES = 0.5 * 1024 * 1024
"""Maximum file size in bytes for image files."""
......
......@@ -15,11 +15,20 @@ from ..proxies import current_previewer
previewable_extensions = ["csv", "dsv"]
def validate_csv(file):
"""Return dialect information about given csv file."""
max_file_size = current_app.config.get(
"PREVIEWER_MAX_FILE_SIZE_BYTES", 10 * 1024 * 1024
)
is_size_valid = file.size <= max_file_size
return is_size_valid
def can_preview(file):
"""Determine if the given file can be previewed."""
if file.is_local() and file.has_extensions(".csv", ".dsv"):
return True
return False
return (
file.is_local() and file.has_extensions(".csv", ".dsv") and validate_csv(file)
)
def preview(file):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment