Module: S3Browser::Store::StorePlugins::Images::InstanceMethods

Defined in:
lib/s3browser/plugins/images.rb

Instance Method Summary collapse

Instance Method Details

#handle?(object) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
# File 'lib/s3browser/plugins/images.rb', line 25

def handle?(object)
  return (object[:content_type] =~ /^image\/.*/) unless (object[:content_type].nil? || object[:content_type] == '')
  return (object[:type] =~ /^image\/.*/) unless (object[:type].nil? || object[:type] == '')
  object[:key] =~ /(jpg|jpeg|png|gif|bmp)$/
end

#object(bucket, key) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/s3browser/plugins/images.rb', line 16

def object(bucket, key)
  object = super(bucket, key)
  object[:thumbnail] = {
    url: "#{thumbnail_url}/#{bucket}/#{object[:key]}",
    width: 200
  } if handle?(object)
  object
end

#objects(bucket, options) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/s3browser/plugins/images.rb', line 6

def objects(bucket, options)
  super(bucket, options).map do |object|
    object[:thumbnail] = {
      url: "#{thumbnail_url}/#{bucket}/#{object[:key]}",
      width: 200
    } if handle?(object)
    object
  end
end

#thumbnail_urlObject



31
32
33
34
35
36
# File 'lib/s3browser/plugins/images.rb', line 31

def thumbnail_url
  @thumbnail_url ||= begin
    return ENV['S3BROWSER_THUMBNAIL_URL'] if ENV['S3BROWSER_THUMBNAIL_URL']
    "http://s3-#{ENV['AWS_REGION']}.amazonaws.com"
  end
end