mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	settings ui: Restrict file type for image file pickers.
Previously, we would allow users to pick any file, even if we didn't support that file type.
This commit is contained in:
		@@ -4,18 +4,18 @@ var upload_widget = (function () {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    var default_max_file_size = 5;
 | 
					    var default_max_file_size = 5;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    var supported_types = [
 | 
				
			||||||
 | 
					        'image/jpeg',
 | 
				
			||||||
 | 
					        'image/png',
 | 
				
			||||||
 | 
					        'image/gif',
 | 
				
			||||||
 | 
					        'image/tiff',
 | 
				
			||||||
 | 
					    ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function is_image_format(file) {
 | 
					    function is_image_format(file) {
 | 
				
			||||||
        var type = file.type;
 | 
					        var type = file.type;
 | 
				
			||||||
        if (!type) {
 | 
					        if (!type) {
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					 | 
				
			||||||
        var supported_types = [
 | 
					 | 
				
			||||||
            'image/jpeg',
 | 
					 | 
				
			||||||
            'image/png',
 | 
					 | 
				
			||||||
            'image/gif',
 | 
					 | 
				
			||||||
            'image/tiff',
 | 
					 | 
				
			||||||
        ];
 | 
					 | 
				
			||||||
        return _.indexOf(supported_types, type) >= 0;
 | 
					        return _.indexOf(supported_types, type) >= 0;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -60,6 +60,7 @@ var upload_widget = (function () {
 | 
				
			|||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        get_file_input().attr('accept', supported_types.toString());
 | 
				
			||||||
        get_file_input().on('change', function (e) {
 | 
					        get_file_input().on('change', function (e) {
 | 
				
			||||||
            if (e.target.files.length === 0) {
 | 
					            if (e.target.files.length === 0) {
 | 
				
			||||||
                input_error.hide();
 | 
					                input_error.hide();
 | 
				
			||||||
@@ -136,6 +137,7 @@ var upload_widget = (function () {
 | 
				
			|||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        get_file_input().attr('accept', supported_types.toString());
 | 
				
			||||||
        get_file_input().on('change', function (e) {
 | 
					        get_file_input().on('change', function (e) {
 | 
				
			||||||
            if (e.target.files.length === 0) {
 | 
					            if (e.target.files.length === 0) {
 | 
				
			||||||
                input_error.hide();
 | 
					                input_error.hide();
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user