<commit_before>frappe.ui.form.on("File", "refresh", function(frm) {
	if(!frm.doc.is_folder) {
		frm.add_custom_button(__('Download'), function() {
			var file_url = frm.doc.file_url;
			if (frm.doc.file_name) {
				file_url = file_url.replace(/#/g, '%23');
			}
			window.open(file_url);
		}, "fa fa-download");
	}

	var wrapper = frm.get_field("preview_html").$wrapper;
	var is_viewable = frappe.utils.is_image_file(frm.doc.file_url);

	frm.toggle_display("preview", is_viewable);
	frm.toggle_display("preview_html", is_viewable);

	if(is_viewable){
		wrapper.html('<div class="img_preview">\
			<img class="img-responsive" src="'+frm.doc.file_url+'"></img>\
			</div>');
	} else {
		wrapper.empty();
	}

	var is_raster_image = (/\.(gif|jpg|jpeg|tiff|png)$/i).test(frm.doc.file_url);
	var is_optimizable = !frm.doc.is_folder && is_raster_image && frm.doc.file_size > 0;

	if (is_optimizable) {
		frm.add_custom_button(__("Optimize"), function() {
			frappe.show_alert(__("Optimizing image..."));
			frm.call("optimize_file").then(() => {
				frappe.show_alert(__("Image optimized"));
				frappe.set_route("List", "File");
			});
		});
	}

	if(frm.doc.file_name && frm.doc.file_name.split('.').splice(-1)[0]==='zip') {
		frm.add_custom_button(__('Unzip'), function() {
			frappe.call({
				method: "frappe.core.doctype.file.file.unzip_file",
				args: {
					name: frm.doc.name,
				},
				callback: function() {
					frappe.set_route('List', 'File');
				}
			});
		});
	}
});
<commit_msg>refactor: Remove set_route after optimization<commit_after>frappe.ui.form.on("File", "refresh", function(frm) {
	if(!frm.doc.is_folder) {
		frm.add_custom_button(__('Download'), function() {
			var file_url = frm.doc.file_url;
			if (frm.doc.file_name) {
				file_url = file_url.replace(/#/g, '%23');
			}
			window.open(file_url);
		}, "fa fa-download");
	}

	var wrapper = frm.get_field("preview_html").$wrapper;
	var is_viewable = frappe.utils.is_image_file(frm.doc.file_url);

	frm.toggle_display("preview", is_viewable);
	frm.toggle_display("preview_html", is_viewable);

	if(is_viewable){
		wrapper.html('<div class="img_preview">\
			<img class="img-responsive" src="'+frm.doc.file_url+'"></img>\
			</div>');
	} else {
		wrapper.empty();
	}

	var is_raster_image = (/\.(gif|jpg|jpeg|tiff|png)$/i).test(frm.doc.file_url);
	var is_optimizable = !frm.doc.is_folder && is_raster_image && frm.doc.file_size > 0;

	if (is_optimizable) {
		frm.add_custom_button(__("Optimize"), function() {
			frappe.show_alert(__("Optimizing image..."));
			frm.call("optimize_file").then(() => {
				frappe.show_alert(__("Image optimized"));
			});
		});
	}

	if(frm.doc.file_name && frm.doc.file_name.split('.').splice(-1)[0]==='zip') {
		frm.add_custom_button(__('Unzip'), function() {
			frappe.call({
				method: "frappe.core.doctype.file.file.unzip_file",
				args: {
					name: frm.doc.name,
				},
				callback: function() {
					frappe.set_route('List', 'File');
				}
			});
		});
	}
});

{'fraction_non_alphanumeric': 0.2078009414929388, 'fraction_numerical': 0.0033624747814391394, 'mean_word_length': 4.164930555555555, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5302615', 'n_tokens_mistral': 1326, 'n_tokens_neox': 1195, 'n_words': 142}