httpimagestore 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
data/bin/httpimagestore CHANGED
@@ -105,13 +105,15 @@ sinatra.get '/' do
105
105
  "hello"
106
106
  end
107
107
 
108
- sinatra.put %r{/thumbnail/([^/]*)/(.*)} do |classes, image_path|
109
- raise BadRequestError, "Path is empty" if image_path.empty?
110
- image_path = Pathname.new(image_path)
108
+ sinatra.put %r{/thumbnail/([^/]*)/?(.*)} do |classes, image_path|
109
+ if image_path.empty?
110
+ image_path = Pathname.new(image_path).extend(Pathname::AutoPath)
111
+ else
112
+ image_path = Pathname.new(image_path).extend(Pathname::CustomPath)
113
+ end
111
114
 
112
115
  classes = classes.split(',').map{|tc| settings.thumbnail_classes[tc]}
113
116
  image = request.body.read
114
- image_hash = digest(image)
115
117
 
116
118
  thumbs = $thumbnailer.thumbnail(image) do
117
119
  classes.each do |tc|
@@ -126,11 +128,13 @@ sinatra.put %r{/thumbnail/([^/]*)/(.*)} do |classes, image_path|
126
128
 
127
129
  urls = []
128
130
 
131
+ image_hash = digest(image)
132
+
129
133
  # store all images
130
- urls << $s3.put_image(image_path.original_image(image_hash).to_s, thumbs.input_mime_type, image)
134
+ urls << $s3.put_image(image_path.original_image(image_hash, thumbs.input_mime_type).to_s, thumbs.input_mime_type, image)
131
135
 
132
136
  thumbs.zip(classes).each do |thumb, thumbnail_class|
133
- urls << $s3.put_image(image_path.thumbnail_image(image_hash, thumbnail_class.name, thumb.mime_type).to_s, thumb.mime_type, thumb.data)
137
+ urls << $s3.put_image(image_path.thumbnail_image(image_hash, thumb.mime_type, thumbnail_class.name).to_s, thumb.mime_type, thumb.data)
134
138
  end
135
139
 
136
140
  status 200
@@ -22,6 +22,24 @@ Feature: Storing of original image and specified classes of its thumbnails on S3
22
22
  Given issthumbtest S3 bucket with key AKIAJMUYVYOSACNXLPTQ and secret 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
23
23
 
24
24
  Scenario: Putting original and its thumbnails to S3 bucket
25
+ Given there is no 4006450256177f4a.jpg file in S3 bucket
26
+ And there is no 4006450256177f4a/small.jpg file in S3 bucket
27
+ And there is no 4006450256177f4a/tiny.jpg file in S3 bucket
28
+ Given test.jpg file content as request body
29
+ When I do PUT request http://localhost:3000/thumbnail/small,tiny
30
+ Then response status will be 200
31
+ And response content type will be text/uri-list
32
+ And response body will be CRLF ended lines
33
+ """
34
+ http://issthumbtest.s3.amazonaws.com/4006450256177f4a.jpg
35
+ http://issthumbtest.s3.amazonaws.com/4006450256177f4a/small.jpg
36
+ http://issthumbtest.s3.amazonaws.com/4006450256177f4a/tiny.jpg
37
+ """
38
+ And http://issthumbtest.s3.amazonaws.com/4006450256177f4a.jpg will contain JPEG image of size 509x719
39
+ And http://issthumbtest.s3.amazonaws.com/4006450256177f4a/small.jpg will contain JPEG image of size 128x128
40
+ And http://issthumbtest.s3.amazonaws.com/4006450256177f4a/tiny.jpg will contain JPEG image of size 32x32
41
+
42
+ Scenario: Putting original and its thumbnails to S3 bucket under custom path
25
43
  Given there is no test/image/4006450256177f4a/test.jpg file in S3 bucket
26
44
  And there is no test/image/4006450256177f4a/test-small.jpg file in S3 bucket
27
45
  And there is no test/image/4006450256177f4a/test-tiny.jpg file in S3 bucket
@@ -39,7 +57,7 @@ Feature: Storing of original image and specified classes of its thumbnails on S3
39
57
  And http://issthumbtest.s3.amazonaws.com/test/image/4006450256177f4a/test-small.jpg will contain JPEG image of size 128x128
40
58
  And http://issthumbtest.s3.amazonaws.com/test/image/4006450256177f4a/test-tiny.jpg will contain JPEG image of size 32x32
41
59
 
42
- Scenario: Putting original and its thumbnails to S3 bucket with UTF characters (encoded) in the path and name
60
+ Scenario: Putting original and its thumbnails to S3 bucket under custom path with UTF characters (encoded) in the path and name
43
61
  Given there is no test/图像/4006450256177f4a/测试.jpg file in S3 bucket
44
62
  And there is no test/图像/4006450256177f4a/测试-small.jpg file in S3 bucket
45
63
  Given test.jpg file content as request body
@@ -136,16 +154,6 @@ Feature: Storing of original image and specified classes of its thumbnails on S3
136
154
  Error: Configuration::ThumbnailClassDoesNotExistError: Class 'bogous' does not exist
137
155
  """
138
156
 
139
- Scenario: Handling of bad path
140
- Given test.jpg file content as request body
141
- When I do PUT request http://localhost:3000/thumbnail/small/
142
- Then response status will be 400
143
- And response content type will be text/plain
144
- And response body will be CRLF ended lines like
145
- """
146
- Error: BadRequestError: Path is empty
147
- """
148
-
149
157
  Scenario: Too large image - uploaded image too big to fit in memory limit
150
158
  Given test-large.jpg file content as request body
151
159
  When I do PUT request http://localhost:3000/thumbnail/large_png/test/image/test.jpg
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "httpimagestore"
8
- s.version = "0.1.1"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jakub Pastuszek"]
12
- s.date = "2012-01-05"
12
+ s.date = "2012-01-10"
13
13
  s.description = "Thumbnails images using httpthumbnailer and stored data on HTTP server (S3)"
14
14
  s.email = "jpastuszek@gmail.com"
15
15
  s.executables = ["httpimagestore"]
@@ -1,19 +1,33 @@
1
1
  require 'mime/types'
2
2
 
3
3
  class Pathname
4
- def original_image(id)
5
- dirname + id.to_s + basename
4
+ def mime_extension(mime_type)
5
+ mime = MIME::Types[mime_type].first or return extname
6
+ '.' + (mime.extensions.select{|e| e.length == 3}.first or mime.extensions.first)
6
7
  end
7
8
 
8
- def thumbnail_image(id, thumbnail_class, mime_type)
9
- dirname + id.to_s + "#{basename(extname)}-#{thumbnail_class}#{mime_extension(mime_type) or extname}"
9
+ module AutoPath
10
+ # <id>.<ext>
11
+ def original_image(id, mime_type)
12
+ "#{id.to_s}#{mime_extension(mime_type)}"
13
+ end
14
+
15
+ # <id>/<class>.<ext>
16
+ def thumbnail_image(id, mime_type, thumbnail_class)
17
+ "#{id.to_s}/#{thumbnail_class}#{mime_extension(mime_type)}"
18
+ end
10
19
  end
11
20
 
12
- private
21
+ module CustomPath
22
+ # abc/xyz.jpg => abc/<id>/xyz.jpg
23
+ def original_image(id, mime_type)
24
+ dirname + id.to_s + basename
25
+ end
13
26
 
14
- def mime_extension(mime_type)
15
- mime = MIME::Types[mime_type].first or return nil
16
- '.' + (mime.extensions.select{|e| e.length == 3}.first or mime.extensions.first)
27
+ # abc/xyz.jpg => abc/<id>/xyz-<class>.jpg
28
+ def thumbnail_image(id, mime_type, thumbnail_class)
29
+ dirname + id.to_s + "#{basename(extname)}-#{thumbnail_class}#{mime_extension(mime_type)}"
30
+ end
17
31
  end
18
32
  end
19
33
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httpimagestore
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jakub Pastuszek
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-05 00:00:00 Z
18
+ date: 2012-01-10 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  type: :runtime