Kaynağa Gözat

Added support for images

Andrew Kane 8 yıl önce
ebeveyn
işleme
6dcc5cf347

+ 5 - 0
app/assets/stylesheets/blazer/application.css

@@ -24,6 +24,11 @@ body {
   background-color: #fff;
 }
 
+.results-table img {
+  max-width: 200px;
+  max-height: 200px;
+}
+
 input.search {
   border: none;
   box-shadow: none;

+ 9 - 1
app/helpers/blazer/base_helper.rb

@@ -9,12 +9,20 @@ module Blazer
     end
 
     BLAZER_URL_REGEX = /\Ahttps?:\/\/[\S]+\z/
+    BLAZER_IMAGE_EXT = %w[png jpg jpeg gif]
 
     def blazer_format_value(key, value)
       if value.is_a?(Integer) && !key.to_s.end_with?("id")
         number_with_delimiter(value)
       elsif value =~ BLAZER_URL_REGEX
-        link_to value, value, target: "_blank"
+        # see if image or link
+        if Blazer.images && BLAZER_IMAGE_EXT.include?(value.split(".").last.split("?").first.try(:downcase))
+          link_to value, target: "_blank" do
+            image_tag value, referrerpolicy: "no-referrer"
+          end
+        else
+          link_to value, value, target: "_blank"
+        end
       else
         value
       end

+ 2 - 0
lib/blazer.rb

@@ -24,12 +24,14 @@ module Blazer
     attr_accessor :check_schedules
     attr_accessor :anomaly_checks
     attr_accessor :async
+    attr_accessor :images
   end
   self.audit = true
   self.user_name = :name
   self.check_schedules = ["5 minutes", "1 hour", "1 day"]
   self.anomaly_checks = false
   self.async = false
+  self.images = false
 
   TIMEOUT_MESSAGE = "Query timed out :("
   TIMEOUT_ERRORS = [

+ 2 - 0
lib/blazer/engine.rb

@@ -35,6 +35,8 @@ module Blazer
       if Blazer.async
         require "blazer/run_statement_job"
       end
+
+      Blazer.images = Blazer.settings["images"] || false
     end
   end
 end