From 5b33ebca6b6e6c29b8070ef7fd2728db34a9690e Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Mon, 17 Nov 2014 23:16:07 -0800 Subject: [PATCH] fixes and a bit of cleanup for store_file --- models/site.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/models/site.rb b/models/site.rb index 14cf5b3d..3d18f6c0 100644 --- a/models/site.rb +++ b/models/site.rb @@ -484,6 +484,7 @@ class Site < Sequel::Model def store_file(path, uploaded, opts={}) relative_path = scrubbed_path path path = files_path path + pathname = Pathname(path) site_file = site_files_dataset.where(path: relative_path).first @@ -493,7 +494,7 @@ class Site < Sequel::Model return false end - if File.extname(relative_path).match /\.#{EDITABLE_FILE_EXT}/ + if pathname.extname.match EDITABLE_FILE_EXT open(uploaded.path) {|f| matches = f.grep SPAM_MATCH_REGEX @@ -515,8 +516,6 @@ class Site < Sequel::Model } end - pathname = Pathname(path) - if pathname.basename.to_s == 'index.html' && opts[:new_install] != true begin new_title = Nokogiri::HTML(File.read(uploaded.path)).css('title').first.text @@ -560,11 +559,9 @@ class Site < Sequel::Model purge_cache path - ext = File.extname(path).gsub(/^./, '') - - if ext.match HTML_REGEX + if pathname.extname.match HTML_REGEX ScreenshotWorker.perform_async values[:username], relative_path - elsif ext.match IMAGE_REGEX + elsif pathname.extname.match IMAGE_REGEX ThumbnailWorker.perform_async values[:username], relative_path end