jobmensa_assets 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 15057b5098dc275d50c8b3c9ecc24c520af11709
4
+ data.tar.gz: ffbf510953e3f0eeba3a15955c56c9e740eae67b
5
+ SHA512:
6
+ metadata.gz: 7db8acffb9dcc6d9ce53e044395b806fe3ee5a4a47493c34090296fc54ee6ad4c9655b95a84d608e5525b72898a0b67f4a802d8000836940b61cfa525be8c2b3
7
+ data.tar.gz: 5ed16fe81bd6297cb1552f526c434707b2f8eb6844556d7aab5ae383598c8ce262f1a20def639df83f4b63e6f2bfd17dc3a31ad562abb40c3607a92de08ad6ce
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /log/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .powenv
16
+ .ruby-version
17
+ .ruby-gemset
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ ruby '2.2.1'
4
+
5
+ # Specify your gem's dependencies in jobmensa_assets.gemspec
6
+ gemspec
7
+ gem 'refile', git: 'https://github.com/refile/refile.git', ref: '6a25a2405964e6c8ad7eb1761a365ccdf7987961'
8
+ gem 'rake'
9
+ gem 'rspec'
10
+ gem 'newrelic_rpm', require: false
11
+ gem 'puma', require: false
12
+ gem 'unicorn', require: false
13
+ gem 'rollbar', require: false
data/Gemfile.lock ADDED
@@ -0,0 +1,104 @@
1
+ GIT
2
+ remote: https://github.com/refile/refile.git
3
+ revision: 6a25a2405964e6c8ad7eb1761a365ccdf7987961
4
+ ref: 6a25a2405964e6c8ad7eb1761a365ccdf7987961
5
+ specs:
6
+ refile (0.5.3)
7
+ mime-types
8
+ sinatra (~> 1.4.5)
9
+
10
+ PATH
11
+ remote: .
12
+ specs:
13
+ jobmensa_assets (0.1.0)
14
+ aws-sdk (>= 1.55, < 2)
15
+ degu
16
+ mini_magick
17
+ rack
18
+ refile
19
+ sinatra
20
+
21
+ GEM
22
+ remote: https://rubygems.org/
23
+ specs:
24
+ activemodel (4.2.1)
25
+ activesupport (= 4.2.1)
26
+ builder (~> 3.1)
27
+ activerecord (4.2.1)
28
+ activemodel (= 4.2.1)
29
+ activesupport (= 4.2.1)
30
+ arel (~> 6.0)
31
+ activesupport (4.2.1)
32
+ i18n (~> 0.7)
33
+ json (~> 1.7, >= 1.7.7)
34
+ minitest (~> 5.1)
35
+ thread_safe (~> 0.3, >= 0.3.4)
36
+ tzinfo (~> 1.1)
37
+ arel (6.0.0)
38
+ aws-sdk (1.64.0)
39
+ aws-sdk-v1 (= 1.64.0)
40
+ aws-sdk-v1 (1.64.0)
41
+ json (~> 1.4)
42
+ nokogiri (>= 1.4.4)
43
+ builder (3.2.2)
44
+ degu (0.5.0)
45
+ activerecord (>= 3.0, < 5.0)
46
+ diff-lcs (1.2.5)
47
+ i18n (0.7.0)
48
+ json (1.8.2)
49
+ kgio (2.9.3)
50
+ mime-types (2.4.3)
51
+ mini_magick (4.2.1)
52
+ mini_portile (0.6.2)
53
+ minitest (5.5.1)
54
+ multi_json (1.11.0)
55
+ newrelic_rpm (3.10.0.279)
56
+ nokogiri (1.6.6.2)
57
+ mini_portile (~> 0.6.0)
58
+ puma (2.11.1)
59
+ rack (>= 1.1, < 2.0)
60
+ rack (1.6.0)
61
+ rack-protection (1.5.3)
62
+ rack
63
+ raindrops (0.13.0)
64
+ rake (10.4.2)
65
+ rollbar (1.4.4)
66
+ multi_json (~> 1.3)
67
+ rspec (3.1.0)
68
+ rspec-core (~> 3.1.0)
69
+ rspec-expectations (~> 3.1.0)
70
+ rspec-mocks (~> 3.1.0)
71
+ rspec-core (3.1.7)
72
+ rspec-support (~> 3.1.0)
73
+ rspec-expectations (3.1.2)
74
+ diff-lcs (>= 1.2.0, < 2.0)
75
+ rspec-support (~> 3.1.0)
76
+ rspec-mocks (3.1.3)
77
+ rspec-support (~> 3.1.0)
78
+ rspec-support (3.1.2)
79
+ sinatra (1.4.6)
80
+ rack (~> 1.4)
81
+ rack-protection (~> 1.4)
82
+ tilt (>= 1.3, < 3)
83
+ thread_safe (0.3.5)
84
+ tilt (2.0.1)
85
+ tzinfo (1.2.2)
86
+ thread_safe (~> 0.1)
87
+ unicorn (4.8.3)
88
+ kgio (~> 2.6)
89
+ rack
90
+ raindrops (~> 0.7)
91
+
92
+ PLATFORMS
93
+ ruby
94
+
95
+ DEPENDENCIES
96
+ bundler (~> 1.7)
97
+ jobmensa_assets!
98
+ newrelic_rpm
99
+ puma
100
+ rake
101
+ refile!
102
+ rollbar
103
+ rspec
104
+ unicorn
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Andreas Riemer
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Procfile ADDED
@@ -0,0 +1 @@
1
+ web: bundle exec unicorn -c ./config/unicorn.rb
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # jobmensa_assets
2
+ Refile app for out images
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
data/config.ru ADDED
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.require
4
+
5
+ require 'sinatra'
6
+
7
+ set :app_file, __FILE__
8
+ set :environments, %w(test development staging production)
9
+ set :show_exceptions, settings.environment != :production
10
+
11
+ $: << File.expand_path('lib')
12
+ require 'jobmensa_assets'
13
+ require 'jobmensa_assets/config'
14
+ require 'refile/app'
15
+
16
+ # init logger, not needed if inside of a rails app
17
+ require 'logger'
18
+ Refile.logger = if [:test, :development].include? settings.environment
19
+ logger = Logger.new("log/#{settings.environment}.log")
20
+ logger.level = Logger::DEBUG
21
+ logger
22
+ else
23
+ logger = Logger.new(STDOUT)
24
+ logger.level = Logger::INFO
25
+ logger
26
+ end
27
+
28
+ # configure rollbar
29
+ require 'rollbar'
30
+ if rollbar_key = ENV['ROLLBAR_ACCESS_TOKEN']
31
+ Rollbar.configure do |config|
32
+ config.access_token = rollbar_key
33
+ end
34
+ end
35
+
36
+ # configure newrelic
37
+ configure :staging, :production do
38
+ require 'newrelic_rpm'
39
+ end
40
+
41
+ jobmensa_assets_app = Rack::Builder.new do
42
+ map '/attachments' do
43
+ run Refile::App
44
+ end
45
+ end
46
+
47
+ run jobmensa_assets_app
@@ -0,0 +1,227 @@
1
+ #
2
+ # This file configures the New Relic Agent. New Relic monitors
3
+ # Ruby, Java, .NET, PHP, and Python applications with deep visibility and low overhead.
4
+ # For more information, visit www.newrelic.com.
5
+ #
6
+ # Generated June 03, 2013
7
+ #
8
+ # This configuration file is custom generated for Barsoom
9
+
10
+
11
+ # Here are the settings that are common to all environments
12
+ common: &default_settings
13
+ # ============================== LICENSE KEY ===============================
14
+
15
+ # You must specify the license key associated with your New Relic
16
+ # account. This key binds your Agent's data to your account in the
17
+ # New Relic service.
18
+ license_key: '<%= ENV["NEW_RELIC_LICENSE_KEY"] %>'
19
+
20
+ # Agent Enabled (Ruby/Rails Only)
21
+ # Use this setting to force the agent to run or not run.
22
+ # Default is 'auto' which means the agent will install and run only
23
+ # if a valid dispatcher such as Mongrel is running. This prevents
24
+ # it from running with Rake or the console. Set to false to
25
+ # completely turn the agent off regardless of the other settings.
26
+ # Valid values are true, false and auto.
27
+ #
28
+ # agent_enabled: auto
29
+
30
+ # Application Name Set this to be the name of your application as
31
+ # you'd like it show up in New Relic. The service will then auto-map
32
+ # instances of your application into an "application" on your
33
+ # dashboard page. If you want to map this instance into multiple
34
+ # apps, like "AJAX Requests" and "All UI" then specify a semicolon
35
+ # separated list of up to three distinct names, or a yaml list.
36
+ # Defaults to the capitalized RAILS_ENV or RACK_ENV (i.e.,
37
+ # Production, Staging, etc)
38
+ #
39
+ # Example:
40
+ #
41
+ # app_name:
42
+ # - Ajax Service
43
+ # - All Services
44
+ #
45
+ app_name: <%= ENV["NEW_RELIC_APP_NAME"] %>
46
+
47
+ # When "true", the agent collects performance data about your
48
+ # application and reports this data to the New Relic service at
49
+ # newrelic.com. This global switch is normally overridden for each
50
+ # environment below. (formerly called 'enabled')
51
+ monitor_mode: true
52
+
53
+ # Developer mode should be off in every environment but
54
+ # development as it has very high overhead in memory.
55
+ developer_mode: false
56
+
57
+ # The newrelic agent generates its own log file to keep its logging
58
+ # information separate from that of your application. Specify its
59
+ # log level here.
60
+ log_level: info
61
+
62
+ # Optionally set the path to the log file This is expanded from the
63
+ # root directory (may be relative or absolute, e.g. 'log/' or
64
+ # '/var/log/') The agent will attempt to create this directory if it
65
+ # does not exist.
66
+ # log_file_path: 'log'
67
+
68
+ # Optionally set the name of the log file, defaults to 'newrelic_agent.log'
69
+ # log_file_name: 'newrelic_agent.log'
70
+
71
+ # The newrelic agent communicates with the service via https by default. This
72
+ # prevents eavesdropping on the performance metrics transmitted by the agent.
73
+ # The encryption required by SSL introduces a nominal amount of CPU overhead,
74
+ # which is performed asynchronously in a background thread. If you'd prefer
75
+ # to send your metrics over http uncomment the following line.
76
+ # ssl: false
77
+
78
+ #============================== Browser Monitoring ===============================
79
+ # New Relic Real User Monitoring gives you insight into the performance real users are
80
+ # experiencing with your website. This is accomplished by measuring the time it takes for
81
+ # your users' browsers to download and render your web pages by injecting a small amount
82
+ # of JavaScript code into the header and footer of each page.
83
+ browser_monitoring:
84
+ # By default the agent automatically injects the monitoring JavaScript
85
+ # into web pages. Set this attribute to false to turn off this behavior.
86
+ auto_instrument: true
87
+
88
+ # Proxy settings for connecting to the New Relic server.
89
+ #
90
+ # If a proxy is used, the host setting is required. Other settings
91
+ # are optional. Default port is 8080.
92
+ #
93
+ # proxy_host: hostname
94
+ # proxy_port: 8080
95
+ # proxy_user:
96
+ # proxy_pass:
97
+
98
+ # The agent can optionally log all data it sends to New Relic servers to a
99
+ # separate log file for human inspection and auditing purposes. To enable this
100
+ # feature, change 'enabled' below to true.
101
+ # See: https://newrelic.com/docs/ruby/audit-log
102
+ audit_log:
103
+ enabled: false
104
+
105
+ # Tells transaction tracer and error collector (when enabled)
106
+ # whether or not to capture HTTP params. When true, frameworks can
107
+ # exclude HTTP parameters from being captured.
108
+ # Rails: the RoR filter_parameter_logging excludes parameters
109
+ # Java: create a config setting called "ignored_params" and set it to
110
+ # a comma separated list of HTTP parameter names.
111
+ # ex: ignored_params: credit_card, ssn, password
112
+ capture_params: false
113
+
114
+ # Transaction tracer captures deep information about slow
115
+ # transactions and sends this to the New Relic service once a
116
+ # minute. Included in the transaction is the exact call sequence of
117
+ # the transactions including any SQL statements issued.
118
+ transaction_tracer:
119
+
120
+ # Transaction tracer is enabled by default. Set this to false to
121
+ # turn it off. This feature is only available at the Professional
122
+ # and above product levels.
123
+ enabled: true
124
+
125
+ # Threshold in seconds for when to collect a transaction
126
+ # trace. When the response time of a controller action exceeds
127
+ # this threshold, a transaction trace will be recorded and sent to
128
+ # New Relic. Valid values are any float value, or (default) "apdex_f",
129
+ # which will use the threshold for an dissatisfying Apdex
130
+ # controller action - four times the Apdex T value.
131
+ transaction_threshold: apdex_f
132
+
133
+ # When transaction tracer is on, SQL statements can optionally be
134
+ # recorded. The recorder has three modes, "off" which sends no
135
+ # SQL, "raw" which sends the SQL statement in its original form,
136
+ # and "obfuscated", which strips out numeric and string literals.
137
+ record_sql: obfuscated
138
+
139
+ # Threshold in seconds for when to collect stack trace for a SQL
140
+ # call. In other words, when SQL statements exceed this threshold,
141
+ # then capture and send to New Relic the current stack trace. This is
142
+ # helpful for pinpointing where long SQL calls originate from.
143
+ stack_trace_threshold: 0.500
144
+
145
+ # Determines whether the agent will capture query plans for slow
146
+ # SQL queries. Only supported in mysql and postgres. Should be
147
+ # set to false when using other adapters.
148
+ # explain_enabled: true
149
+
150
+ # Threshold for query execution time below which query plans will
151
+ # not be captured. Relevant only when `explain_enabled` is true.
152
+ # explain_threshold: 0.5
153
+
154
+ # Error collector captures information about uncaught exceptions and
155
+ # sends them to New Relic for viewing
156
+ error_collector:
157
+
158
+ # Error collector is enabled by default. Set this to false to turn
159
+ # it off. This feature is only available at the Professional and above
160
+ # product levels.
161
+ enabled: true
162
+
163
+ # Rails Only - tells error collector whether or not to capture a
164
+ # source snippet around the place of the error when errors are View
165
+ # related.
166
+ capture_source: true
167
+
168
+ # To stop specific errors from reporting to New Relic, set this property
169
+ # to comma-separated values. Default is to ignore routing errors,
170
+ # which are how 404's get triggered.
171
+ ignore_errors: "ActionController::RoutingError,Sinatra::NotFound"
172
+
173
+ # If you're interested in capturing memcache keys as though they
174
+ # were SQL uncomment this flag. Note that this does increase
175
+ # overhead slightly on every memcached call, and can have security
176
+ # implications if your memcached keys are sensitive
177
+ # capture_memcache_keys: true
178
+
179
+ # Application Environments
180
+ # ------------------------------------------
181
+ # Environment-specific settings are in this section.
182
+ # For Rails applications, RAILS_ENV is used to determine the environment.
183
+ # For Java applications, pass -Dnewrelic.environment <environment> to set
184
+ # the environment.
185
+
186
+ # NOTE if your application has other named environments, you should
187
+ # provide newrelic configuration settings for these environments here.
188
+
189
+ development:
190
+ <<: *default_settings
191
+ # Turn off communication to New Relic service in development mode (also
192
+ # 'enabled').
193
+ # NOTE: for initial evaluation purposes, you may want to temporarily
194
+ # turn the agent on in development mode.
195
+ monitor_mode: false
196
+
197
+ # Rails Only - when running in Developer Mode, the New Relic Agent will
198
+ # present performance information on the last 100 transactions you have
199
+ # executed since starting the mongrel.
200
+ # NOTE: There is substantial overhead when running in developer mode.
201
+ # Do not use for production or load testing.
202
+ developer_mode: true
203
+
204
+ # Enable textmate links
205
+ # textmate: true
206
+
207
+ test:
208
+ <<: *default_settings
209
+ # It almost never makes sense to turn on the agent when running
210
+ # unit, functional or integration tests or the like.
211
+ monitor_mode: false
212
+
213
+ # Turn on the agent in production for 24x7 monitoring. NewRelic
214
+ # testing shows an average performance impact of < 5 ms per
215
+ # transaction, you can leave this on all the time without
216
+ # incurring any user-visible performance degradation.
217
+ production:
218
+ <<: *default_settings
219
+ monitor_mode: true
220
+
221
+ # Many applications have a staging environment which behaves
222
+ # identically to production. Support for that environment is provided
223
+ # here. By default, the staging environment has the agent turned on.
224
+ staging:
225
+ <<: *default_settings
226
+ monitor_mode: true
227
+ app_name: <%= ENV["NEW_RELIC_APP_NAME"] %> (Staging)
data/config/puma.rb ADDED
@@ -0,0 +1,8 @@
1
+ workers Integer(ENV['WEB_CONCURRENCY'] || 2)
2
+ threads 0, Integer(ENV['WORKER_CONCURRENCY'] || 4)
3
+
4
+ rackup DefaultRackup
5
+ port ENV['PORT'] || 3000
6
+ environment ENV['RACK_ENV'] || 'development'
7
+
8
+ preload_app!
data/config/unicorn.rb ADDED
@@ -0,0 +1,19 @@
1
+ worker_processes Integer(ENV["WEB_CONCURRENCY"] || 4)
2
+ timeout 28
3
+
4
+ preload_app true
5
+
6
+ listen ENV['PORT'], :backlog => Integer(ENV['UNICORN_BACKLOG'] || 200)
7
+
8
+ before_fork do |server, worker|
9
+ Signal.trap 'TERM' do
10
+ puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
11
+ Process.kill 'QUIT', Process.pid
12
+ end
13
+ end
14
+
15
+ after_fork do |server, worker|
16
+ Signal.trap 'TERM' do
17
+ puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
18
+ end
19
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jobmensa_assets/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jobmensa_assets"
8
+ spec.version = JobmensaAssets::VERSION
9
+ spec.authors = ["Jobmensa dev team"]
10
+ spec.email = ["produkt@studitemps.de"]
11
+ spec.summary = %q{Our image resize and delivery app.}
12
+ spec.description = %q{Resizes and delivers images using the refile gem.}
13
+ spec.homepage = "https://studitemps.de/"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'sinatra'
22
+ spec.add_dependency 'refile'
23
+ spec.add_dependency 'mini_magick'
24
+ spec.add_dependency 'rack'
25
+ spec.add_dependency 'aws-sdk', '>= 1.55', '< 2'
26
+ spec.add_dependency 'degu'
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.7"
29
+ end
@@ -0,0 +1,16 @@
1
+ require 'jobmensa_assets/version'
2
+ require 'refile'
3
+ require 'jobmensa_assets/xt/refile/type'
4
+ require 'jobmensa_assets/xt/refile/attacher'
5
+ require 'jobmensa_assets/xt/refile/backend/s3'
6
+ require 'jobmensa_assets/image_processor'
7
+ require 'jobmensa_assets/attachment_type'
8
+
9
+ if defined?(Rails)
10
+ ENV['RAILS_ENV'] ||= Rails.env
11
+ require 'jobmensa_assets/railtie'
12
+ require 'refile/rails'
13
+ end
14
+
15
+ module JobmensaAssets
16
+ end
@@ -0,0 +1,74 @@
1
+ require 'degu'
2
+
3
+ module JobmensaAssets
4
+ enum :AttachmentType do
5
+ field :content_type
6
+
7
+ Image(
8
+ content_type: ['image/jpeg', 'image/gif', 'image/png']
9
+ )
10
+
11
+ Spreadsheet(
12
+ content_type: [
13
+ 'application/vnd.ms-excel', 'application/excel', # xls
14
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', # xlsx
15
+ 'application/vnd.oasis.opendocument.spreadsheet' # ods
16
+ ]
17
+ )
18
+
19
+ PDF(
20
+ content_type: ['application/pdf']
21
+ )
22
+
23
+ Document(
24
+ content_type: [
25
+ 'application/msword', 'application/word', 'application/x-msword', 'application/x-word', # doc
26
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', # docx
27
+ 'application/vnd.oasis.opendocument.text', # odt
28
+ 'application/rtf', 'application/x-rtf', 'text/rtf', 'text/x-rtf' # rtf
29
+ ]
30
+ )
31
+
32
+ def self.content_type(type)
33
+ types_from(type).flat_map(&:content_type)
34
+ end
35
+
36
+ def self.file_extensions(type)
37
+ types_from(type).flat_map(&:file_extensions)
38
+ end
39
+
40
+ def file_extensions
41
+ @extensions ||= Hashie::Mash.new
42
+ @extensions[underscored_name] ||= begin
43
+ content_type.each_with_object([]) { |type, memo| memo << MIME::Types[type].flat_map(&:extensions) }.flatten.uniq
44
+ end
45
+ end
46
+
47
+ def self.max_filesize(_type)
48
+ Refile.cache.max_size
49
+ end
50
+
51
+ private
52
+
53
+ def self.types_from(type)
54
+ case type
55
+ when Symbol, String
56
+ Array(AttachmentType[type])
57
+ when AttachmentType
58
+ Array(type)
59
+ when Refile::Type
60
+ AttachmentType.for_refile_type(type)
61
+ end
62
+ end
63
+
64
+ def self.for_refile_type(type)
65
+ case type.name
66
+ when :image
67
+ Array(AttachmentType::Image)
68
+ else
69
+ AttachmentType.all
70
+ end
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,49 @@
1
+ environment = ENV['RAILS_ENV'] || ENV['RACK_ENV']
2
+
3
+ Refile.configure do |config|
4
+
5
+ max_size = Integer(ENV['MAX_ATTACHMENT_SIZE'] || 10485760) # 10 megabytes
6
+
7
+ if environment == 'test'
8
+ config.cache = Refile::Backend::FileSystem.new('tmp/refile/cache', max_size: max_size)
9
+ config.store = Refile::Backend::FileSystem.new('tmp/refile/store', max_size: max_size)
10
+ else
11
+ aws = {
12
+ access_key_id: ENV['AWS_ACCESS_KEY'],
13
+ secret_access_key: ENV['AWS_SECRET_KEY'],
14
+ bucket: ENV['AWS_S3_BUCKET'] || "jobmensa2-#{environment}",
15
+ region: ENV['AWS_S3_REGION'] || 'eu-west-1',
16
+ max_size: max_size
17
+ }
18
+
19
+ config.cache = Refile::Backend::S3.new(prefix: 'cache', **aws)
20
+ config.store = Refile::Backend::S3.new(prefix: 'store', **aws)
21
+ end
22
+
23
+ # Secretkey for signing urls
24
+ config.secret_key = ENV['REFILE_SECRET_KEY']
25
+
26
+ # Configure the request origin
27
+ config.allow_origin = '*'
28
+
29
+ # Do not mount as refile_app for rails
30
+ config.automount = false
31
+
32
+ unless environment == 'test' # go to the app server
33
+ host = ENV['REFILE_HOST'] || ENV['HOST_NAME']
34
+ # cloudfront or our server
35
+ config.host = "//#{host}"
36
+ end
37
+
38
+ # Delete default processors and use our own processors defined below
39
+ config.instance_variable_set :@processors, nil
40
+ end
41
+
42
+ [:default, :convert, :limit, :fit, :fill, :pad, ].each do |name|
43
+ Refile.processor(name, JobmensaAssets::ImageProcessor.new(name))
44
+ end
45
+
46
+ [:image, :attachment].each do |type|
47
+ Refile.types[type] = Refile::Type.new(type)
48
+ Refile.types[type].content_type = JobmensaAssets::AttachmentType.content_type(Refile.types[type])
49
+ end
@@ -0,0 +1,38 @@
1
+ require 'refile'
2
+ require 'refile/image_processing'
3
+
4
+ module JobmensaAssets
5
+ ##
6
+ # Processors for Refile
7
+ class ImageProcessor < Refile::ImageProcessor
8
+
9
+ ## do nothing
10
+ def default(img)
11
+ end
12
+
13
+ ##
14
+ # Overwrite refile call method to supress format warnings and do post-processing
15
+ def call(file, *args, format: nil)
16
+ img = ::MiniMagick::Image.new(file.path)
17
+ img.quiet
18
+ img.format(format.to_s.downcase, nil) if format
19
+ send(@method, img, *args)
20
+ post_processing(img)
21
+
22
+ ::File.open(img.path, "rb")
23
+ end
24
+
25
+ private
26
+
27
+ ##
28
+ # Should be called for every jobmensa processor
29
+ def post_processing(img)
30
+ img.combine_options do |cmd|
31
+ cmd.strip # Deletes metatags
32
+ cmd.colorspace 'sRGB' # Change colorspace
33
+ cmd.auto_orient # Reset rotation
34
+ cmd.quiet # Suppress warnings
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,9 @@
1
+ module JobmensaAssets
2
+ class Railtie < Rails::Railtie
3
+
4
+ initializer 'jobmensa_assets.configure' do
5
+ require 'jobmensa_assets/config'
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module JobmensaAssets
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,32 @@
1
+ require 'refile'
2
+ require 'refile/attacher'
3
+
4
+ # Migration Content-Type (JM1) fix
5
+ module Refile
6
+ class Attacher
7
+ def download(url)
8
+ unless url.to_s.empty?
9
+ file = open(url)
10
+ content_type = file.meta["content-type"]
11
+ if content_type.blank?
12
+ content_type = MIME::Types.type_for(::File.extname(file.base_uri.path).gsub('.', '')).first.content_type
13
+ end
14
+ @metadata = {
15
+ size: file.meta["content-length"].to_i,
16
+ filename: ::File.basename(file.base_uri.path),
17
+ content_type: content_type
18
+ }
19
+ if valid?
20
+ @metadata[:id] = cache.upload(file).id
21
+ write_metadata
22
+ elsif @raise_errors
23
+ raise Refile::Invalid, @errors.join(", ")
24
+ end
25
+ end
26
+ rescue OpenURI::HTTPError, RuntimeError => error
27
+ raise if error.is_a?(RuntimeError) and error.message !~ /redirection loop/
28
+ @errors = [:download_failed]
29
+ raise if @raise_errors
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,16 @@
1
+ require 'refile'
2
+ require 'refile/backend/s3'
3
+
4
+ # MokeyPatch to fix signature content_length format
5
+ module Refile
6
+ module Backend
7
+ class S3
8
+ def presign
9
+ id = RandomHasher.new.hash
10
+ signature = @bucket.presigned_post(key: [*@prefix, id].join('/'))
11
+ signature = signature.where(:content_length).in(0..@max_size) if @max_size
12
+ Signature.new(as: 'file', id: id, url: signature.url.to_s, fields: signature.fields)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ require 'refile'
2
+ require 'refile/type'
3
+
4
+ # # Monkey Patch to add file extensions to type (derived from content type)
5
+ module Refile
6
+ class Type
7
+ attr_reader :name
8
+ end
9
+ end
data/log/.git-keep ADDED
File without changes
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe JobmensaAssets do
4
+ it 'has a version number' do
5
+ expect(JobmensaAssets::VERSION).not_to be nil
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'jobmensa_assets'
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jobmensa_assets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jobmensa dev team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: refile
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mini_magick
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: aws-sdk
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '1.55'
76
+ - - "<"
77
+ - !ruby/object:Gem::Version
78
+ version: '2'
79
+ type: :runtime
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '1.55'
86
+ - - "<"
87
+ - !ruby/object:Gem::Version
88
+ version: '2'
89
+ - !ruby/object:Gem::Dependency
90
+ name: degu
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: bundler
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '1.7'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '1.7'
117
+ description: Resizes and delivers images using the refile gem.
118
+ email:
119
+ - produkt@studitemps.de
120
+ executables: []
121
+ extensions: []
122
+ extra_rdoc_files: []
123
+ files:
124
+ - ".gitignore"
125
+ - ".rspec"
126
+ - Gemfile
127
+ - Gemfile.lock
128
+ - LICENSE.txt
129
+ - Procfile
130
+ - README.md
131
+ - Rakefile
132
+ - config.ru
133
+ - config/newrelic.yml
134
+ - config/puma.rb
135
+ - config/unicorn.rb
136
+ - jobmensa_assets.gemspec
137
+ - lib/jobmensa_assets.rb
138
+ - lib/jobmensa_assets/attachment_type.rb
139
+ - lib/jobmensa_assets/config.rb
140
+ - lib/jobmensa_assets/image_processor.rb
141
+ - lib/jobmensa_assets/railtie.rb
142
+ - lib/jobmensa_assets/version.rb
143
+ - lib/jobmensa_assets/xt/refile/attacher.rb
144
+ - lib/jobmensa_assets/xt/refile/backend/s3.rb
145
+ - lib/jobmensa_assets/xt/refile/type.rb
146
+ - log/.git-keep
147
+ - spec/jobmensa_assets_spec.rb
148
+ - spec/spec_helper.rb
149
+ homepage: https://studitemps.de/
150
+ licenses:
151
+ - MIT
152
+ metadata: {}
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 2.4.6
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: Our image resize and delivery app.
173
+ test_files:
174
+ - spec/jobmensa_assets_spec.rb
175
+ - spec/spec_helper.rb