uploadbox 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 793534702191f8ac2e654b13f87e970320effc4e
4
- data.tar.gz: 27ebcf04dfdd0e5af5bf96563f6a49cbe5cf6ead
3
+ metadata.gz: f836cae407afd0efd7deeb07384addf19e9b9dce
4
+ data.tar.gz: 53ad4ff8b967f0b9e7d2345ccb70b0e0165a07db
5
5
  SHA512:
6
- metadata.gz: 330cf7e386cf7f18807f9b81170b3bd0efeb7bf0e2b6c6800c353e471d4dfc23ff3e6f718c9b53f3249feb8fcb83ddd75a702637271e584f1f2d8b34c10e02a8
7
- data.tar.gz: c7811bc5e8d1b982f808da97d7742e7cb72843d00bdc7189f60e111d513573dc7623f4508d86a2b8e53d1a9edaee8d536e3a35161833e12143a3974c0caa7eec
6
+ metadata.gz: 92d197f8f76b8d9dd57e436e6ec09eb7d3107aa02666e7e2f80d88c6bc6c824cb54e550f31fca1c4fcf6072bbfbcc89a8c07f4045d7b5b30192e97d4a83634a7
7
+ data.tar.gz: 0c7c864ef01588ca0ccb7722112454d9ac0ef99a936a6c2a1c4d92ee233ac1d69583a848b7006220b9bd580decfe771fb98d2dd1610439467af8d9737fa2aeea
data/README.md CHANGED
@@ -33,14 +33,27 @@ Migrate database
33
33
  rake db:migrate
34
34
  ```
35
35
 
36
- Create a bucket on S3 (US region)
36
+ Create a development bucket on S3
37
37
 
38
38
  Set environmet variables
39
39
  ```
40
40
  S3_KEY=AAAA123BBBB
41
41
  S3_SECRET=abc123ABcEffgee122
42
- S3_REGION=sa-east-1
43
- S3_BUCKET=uploads
42
+ S3_REGION=us-east-1
43
+ S3_BUCKET=uploads-development
44
+ ```
45
+
46
+ Edit CORS config for the bucket
47
+ ```
48
+ <CORSConfiguration>
49
+ <CORSRule>
50
+ <AllowedOrigin>http://localhost:5000</AllowedOrigin>
51
+ <AllowedMethod>GET</AllowedMethod>
52
+ <AllowedMethod>POST</AllowedMethod>
53
+ <AllowedMethod>PUT</AllowedMethod>
54
+ <AllowedHeader>*</AllowedHeader>
55
+ </CORSRule>
56
+ </CORSConfiguration>
44
57
  ```
45
58
 
46
59
  ## Usage
@@ -76,13 +89,32 @@ Post.update_picture_versions!
76
89
 
77
90
 
78
91
  ## Heroku
92
+ Create a production bucket on S3
93
+ Don't use your development bucket
94
+ ```
95
+ <CORSConfiguration>
96
+ <CORSRule>
97
+ <AllowedOrigin>http://yourdomain.com</AllowedOrigin>
98
+ <AllowedMethod>GET</AllowedMethod>
99
+ <AllowedMethod>POST</AllowedMethod>
100
+ <AllowedMethod>PUT</AllowedMethod>
101
+ <AllowedHeader>*</AllowedHeader>
102
+ </CORSRule>
103
+ </CORSConfiguration>
104
+ ```
105
+
79
106
  Set environmet variables
80
107
  ```
81
- HEROKU_API_KEY=ab12acvc12
82
- HEROKU_APP=your-app-name
108
+ heroku config:add
109
+ HEROKU_API_KEY=ab12acvc12 \
110
+ HEROKU_APP=your-app-name \
111
+ S3_KEY=AAAA123BBBB \
112
+ S3_SECRET=abc123ABcEffgee122 \
113
+ S3_REGION=us-east-1 \
114
+ S3_BUCKET=uploads-production \
83
115
  ```
84
116
 
85
- Add Redis to Go addon
117
+ Add Redis
86
118
  ```
87
119
  heroku addons:add rediscloud:20
88
120
  ```
@@ -35,6 +35,8 @@ class @ImageUploader
35
35
  @loader = $('<div class="progress progress-striped active"><div class="bar" style="width: 0%;"></div></div>').hide()
36
36
  @preview.prepend(@loader.fadeIn())
37
37
  data.submit()
38
+ @container.find('.fileupload').removeClass('processing').addClass('uploading')
39
+ @container.closest('form').find('[type=submit]').attr("disabled", true)
38
40
 
39
41
  getFormData: (arg) =>
40
42
  file = @file
@@ -54,6 +56,7 @@ class @ImageUploader
54
56
  @loader.find('.bar').css({width: progress + '%'})
55
57
 
56
58
  done: (e, data) =>
59
+ @container.find('.fileupload').removeClass('uploading').addClass('processing')
57
60
  $.ajax
58
61
  type: 'POST'
59
62
  url: @fileInput.data('callback-url')
@@ -62,8 +65,14 @@ class @ImageUploader
62
65
  'image[imageable_type]': @typeInput.val()
63
66
  'image[upload_name]': @uploadNameInput.val()
64
67
  'image[secure_random]': @fileInput.data('secure-random')
68
+
65
69
  complete: =>
66
70
  @verifyProcessingInterval = setInterval(@verifyProcessing, 5000)
71
+
72
+ error: =>
73
+ @loader.detach()
74
+ @container.find('.fileupload').removeClass('uploading').removeClass('processing')
75
+ @container.closest('form').find('[type=submit]').attr("disabled", false)
67
76
 
68
77
  verifyProcessing: =>
69
78
  arr = @filePath.split('/')
@@ -82,14 +91,22 @@ class @ImageUploader
82
91
  if data.responseJSON.hasOwnProperty('id')
83
92
  clearInterval(@verifyProcessingInterval)
84
93
  @showThumb(data.responseJSON)
85
-
94
+
95
+ error: =>
96
+ @loader.detach()
97
+ @container.find('.fileupload').removeClass('uploading').removeClass('processing')
98
+ @container.closest('form').find('[type=submit]').attr("disabled", false)
99
+
100
+
86
101
  delete: =>
87
102
  @idInput.val('')
88
103
  @container.find('.fileupload-preview.thumbnail img').detach()
89
104
  @container.find('.fileupload').addClass('fileupload-new').removeClass('fileupload-exists')
90
105
 
91
106
  fail: (e, data) =>
92
- console.log('fail')
107
+ @loader.detach()
108
+ @container.find('.fileupload').removeClass('uploading').removeClass('processing')
109
+ @container.closest('form').find('[type=submit]').attr("disabled", false)
93
110
 
94
111
  showThumb: (image) =>
95
112
  @loader.detach()
@@ -102,7 +119,8 @@ class @ImageUploader
102
119
  img.attr('height', @thumbContainer.data('height')).hide()
103
120
  @container.find('.fileupload-preview.thumbnail').append(img.fadeIn())
104
121
  @container.find('.fileupload').removeClass('fileupload-new').addClass('fileupload-exists')
105
-
122
+ @container.find('.fileupload').removeClass('uploading').removeClass('processing')
123
+ @container.closest('form').find('[type=submit]').attr("disabled", false)
106
124
 
107
125
  $ ->
108
126
  $('[data-component="ImageUploader"]').each (i, el) ->
@@ -3,7 +3,11 @@ module Uploadbox
3
3
  layout false
4
4
 
5
5
  def create
6
- Resque.enqueue(ProcessImage, image_params)
6
+ if Uploadbox.background_processing
7
+ Resque.enqueue(ProcessImage, image_params)
8
+ else
9
+ Image.create_upload(image_params)
10
+ end
7
11
  render nothing: true
8
12
  end
9
13
 
@@ -11,7 +15,7 @@ module Uploadbox
11
15
  params[:imageable_type].constantize # load class
12
16
 
13
17
  upload_class_name = params[:imageable_type] + params[:upload_name].camelize
14
- @image = Uploadbox.const_get(upload_class_name).find_by(secure_random: params[:secure_random], file: params[:name])
18
+ @image = Uploadbox.const_get(upload_class_name).find_by(secure_random: params[:secure_random])
15
19
  end
16
20
 
17
21
  def destroy
@@ -1,7 +1,7 @@
1
1
  class CreateImages < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :images do |t|
4
- t.string :file, index: true
4
+ t.string :file
5
5
  t.references :imageable, polymorphic: true, index: true
6
6
  t.integer :width
7
7
  t.integer :height
@@ -4,4 +4,5 @@ module Uploadbox
4
4
  mattr_accessor :retina
5
5
  mattr_accessor :image_quality
6
6
  mattr_accessor :retina_quality
7
+ mattr_accessor :background_processing
7
8
  end
@@ -1,3 +1,3 @@
1
1
  module Uploadbox
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uploadbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julio Protzek