refile 0.5.5 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/refile.rb +252 -27
- data/lib/refile/app.rb +55 -14
- data/lib/refile/attacher.rb +39 -40
- data/lib/refile/attachment.rb +28 -13
- data/lib/refile/attachment/active_record.rb +90 -1
- data/lib/refile/attachment_definition.rb +47 -0
- data/lib/refile/backend/s3.rb +1 -147
- data/lib/refile/backend_macros.rb +13 -5
- data/lib/refile/custom_logger.rb +3 -1
- data/lib/refile/file.rb +9 -0
- data/lib/refile/image_processing.rb +1 -143
- data/lib/refile/rails.rb +30 -0
- data/lib/refile/rails/attachment_helper.rb +27 -16
- data/lib/refile/signature.rb +5 -0
- data/lib/refile/simple_form.rb +17 -0
- data/lib/refile/version.rb +1 -1
- data/spec/refile/active_record_helper.rb +11 -0
- data/spec/refile/app_spec.rb +197 -20
- data/spec/refile/attachment/active_record_spec.rb +298 -1
- data/spec/refile/attachment_helper_spec.rb +39 -0
- data/spec/refile/attachment_spec.rb +53 -5
- data/spec/refile/backend_examples.rb +13 -2
- data/spec/refile/backend_macros_spec.rb +27 -6
- data/spec/refile/custom_logger_spec.rb +2 -3
- data/spec/refile/features/direct_upload_spec.rb +18 -0
- data/spec/refile/features/multiple_upload_spec.rb +122 -0
- data/spec/refile/features/normal_upload_spec.rb +5 -3
- data/spec/refile/features/presigned_upload_spec.rb +4 -0
- data/spec/refile/features/simple_form_spec.rb +8 -0
- data/spec/refile/fixtures/monkey.txt +1 -0
- data/spec/refile/fixtures/world.txt +1 -0
- data/spec/refile/spec_helper.rb +21 -11
- data/spec/refile_spec.rb +253 -24
- metadata +12 -303
- data/.gitignore +0 -27
- data/.rspec +0 -2
- data/.rubocop.yml +0 -68
- data/.travis.yml +0 -21
- data/.yardopts +0 -1
- data/CONTRIBUTING.md +0 -33
- data/Gemfile +0 -3
- data/History.md +0 -96
- data/LICENSE.txt +0 -22
- data/README.md +0 -651
- data/Rakefile +0 -19
- data/app/assets/javascripts/refile.js +0 -63
- data/config.ru +0 -8
- data/config/locales/en.yml +0 -8
- data/config/routes.rb +0 -5
- data/refile.gemspec +0 -42
- data/spec/refile/backend/s3_spec.rb +0 -11
- data/spec/refile/test_app.rb +0 -65
- data/spec/refile/test_app/app/assets/javascripts/application.js +0 -42
- data/spec/refile/test_app/app/controllers/application_controller.rb +0 -2
- data/spec/refile/test_app/app/controllers/direct_posts_controller.rb +0 -15
- data/spec/refile/test_app/app/controllers/home_controller.rb +0 -4
- data/spec/refile/test_app/app/controllers/normal_posts_controller.rb +0 -48
- data/spec/refile/test_app/app/controllers/presigned_posts_controller.rb +0 -31
- data/spec/refile/test_app/app/models/post.rb +0 -5
- data/spec/refile/test_app/app/views/direct_posts/new.html.erb +0 -20
- data/spec/refile/test_app/app/views/home/index.html.erb +0 -1
- data/spec/refile/test_app/app/views/layouts/application.html.erb +0 -14
- data/spec/refile/test_app/app/views/normal_posts/_form.html.erb +0 -28
- data/spec/refile/test_app/app/views/normal_posts/edit.html.erb +0 -1
- data/spec/refile/test_app/app/views/normal_posts/index.html +0 -5
- data/spec/refile/test_app/app/views/normal_posts/new.html.erb +0 -1
- data/spec/refile/test_app/app/views/normal_posts/show.html.erb +0 -19
- data/spec/refile/test_app/app/views/presigned_posts/new.html.erb +0 -16
- data/spec/refile/test_app/config/database.yml +0 -7
- data/spec/refile/test_app/config/routes.rb +0 -17
- data/spec/refile/test_app/public/favicon.ico +0 -0
data/Rakefile
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.expand_path("spec", File.dirname(__FILE__)))
|
2
|
-
|
3
|
-
require "bundler/gem_tasks"
|
4
|
-
require "refile/test_app"
|
5
|
-
require "rspec/core/rake_task"
|
6
|
-
require "yard"
|
7
|
-
require "rubocop/rake_task"
|
8
|
-
|
9
|
-
YARD::Rake::YardocTask.new do |t|
|
10
|
-
t.files = ["README.md", "lib/**/*.rb"]
|
11
|
-
end
|
12
|
-
|
13
|
-
RSpec::Core::RakeTask.new(:spec)
|
14
|
-
|
15
|
-
RuboCop::RakeTask.new
|
16
|
-
|
17
|
-
task default: [:spec, :rubocop]
|
18
|
-
|
19
|
-
Rails.application.load_tasks
|
@@ -1,63 +0,0 @@
|
|
1
|
-
(function() {
|
2
|
-
"use strict";
|
3
|
-
|
4
|
-
if(!document.addEventListener) { return; } // IE8
|
5
|
-
|
6
|
-
document.addEventListener("change", function(changeEvent) {
|
7
|
-
var input = changeEvent.target;
|
8
|
-
if(input.tagName === "INPUT" && input.type === "file" && input.getAttribute("data-direct")) {
|
9
|
-
if(!input.files) { return; } // IE9, bail out if file API is not supported.
|
10
|
-
|
11
|
-
var file = input.files[0];
|
12
|
-
var metadataField = input.previousSibling;
|
13
|
-
|
14
|
-
var dispatchEvent = function(name, detail) {
|
15
|
-
var ev = document.createEvent('CustomEvent');
|
16
|
-
ev.initCustomEvent(name, true, false, detail);
|
17
|
-
input.dispatchEvent(ev);
|
18
|
-
};
|
19
|
-
|
20
|
-
if(file) {
|
21
|
-
var url = input.getAttribute("data-url");
|
22
|
-
var fields = JSON.parse(input.getAttribute("data-fields") || "null");
|
23
|
-
|
24
|
-
var data = new FormData();
|
25
|
-
|
26
|
-
if(fields) {
|
27
|
-
Object.keys(fields).forEach(function(key) {
|
28
|
-
data.append(key, fields[key]);
|
29
|
-
});
|
30
|
-
}
|
31
|
-
data.append(input.getAttribute("data-as"), file);
|
32
|
-
|
33
|
-
var xhr = new XMLHttpRequest();
|
34
|
-
xhr.addEventListener("load", function() {
|
35
|
-
input.classList.remove("uploading");
|
36
|
-
dispatchEvent("upload:complete", xhr.responseText);
|
37
|
-
if((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304) {
|
38
|
-
var id = input.getAttribute("data-id") || JSON.parse(xhr.responseText).id;
|
39
|
-
if(metadataField) {
|
40
|
-
metadataField.value = JSON.stringify({ id: id, filename: file.name, content_type: file.type, size: file.size });
|
41
|
-
}
|
42
|
-
input.removeAttribute("name");
|
43
|
-
dispatchEvent("upload:success", xhr.responseText);
|
44
|
-
} else {
|
45
|
-
dispatchEvent("upload:failure", xhr.responseText);
|
46
|
-
}
|
47
|
-
});
|
48
|
-
|
49
|
-
xhr.upload.addEventListener("progress", function(progressEvent) {
|
50
|
-
if (progressEvent.lengthComputable) {
|
51
|
-
dispatchEvent("upload:progress", progressEvent);
|
52
|
-
}
|
53
|
-
});
|
54
|
-
|
55
|
-
xhr.open("POST", url, true);
|
56
|
-
xhr.send(data);
|
57
|
-
|
58
|
-
input.classList.add("uploading");
|
59
|
-
dispatchEvent("upload:start", xhr);
|
60
|
-
}
|
61
|
-
}
|
62
|
-
});
|
63
|
-
})();
|
data/config.ru
DELETED
data/config/locales/en.yml
DELETED
data/config/routes.rb
DELETED
data/refile.gemspec
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require "refile/version"
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "refile"
|
8
|
-
spec.version = Refile::VERSION
|
9
|
-
spec.authors = ["Jonas Nicklas"]
|
10
|
-
spec.email = ["jonas.nicklas@gmail.com"]
|
11
|
-
spec.summary = "Simple and powerful file upload library"
|
12
|
-
spec.homepage = ""
|
13
|
-
spec.license = "MIT"
|
14
|
-
|
15
|
-
spec.files = `git ls-files -z`.split("\x0")
|
16
|
-
spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
|
17
|
-
spec.test_files = spec.files.grep(/^(test|spec|features)\//)
|
18
|
-
spec.require_paths = %w[lib spec]
|
19
|
-
|
20
|
-
spec.required_ruby_version = ">= 2.1.0"
|
21
|
-
|
22
|
-
spec.add_dependency "rest-client", "~> 1.8"
|
23
|
-
spec.add_dependency "sinatra", "~> 1.4.5"
|
24
|
-
spec.add_dependency "mime-types"
|
25
|
-
|
26
|
-
spec.add_development_dependency "webmock", "~> 1.20.4"
|
27
|
-
spec.add_development_dependency "bundler", "~> 1.6"
|
28
|
-
spec.add_development_dependency "rake"
|
29
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
-
spec.add_development_dependency "rspec-rails", "~> 3.0"
|
31
|
-
spec.add_development_dependency "jquery-rails"
|
32
|
-
spec.add_development_dependency "capybara"
|
33
|
-
spec.add_development_dependency "pry"
|
34
|
-
spec.add_development_dependency "aws-sdk"
|
35
|
-
spec.add_development_dependency "rack-test", "~> 0.6.2"
|
36
|
-
spec.add_development_dependency "rails", "~> 4.1.8"
|
37
|
-
spec.add_development_dependency "sqlite3"
|
38
|
-
spec.add_development_dependency "selenium-webdriver"
|
39
|
-
spec.add_development_dependency "yard"
|
40
|
-
spec.add_development_dependency "rubocop"
|
41
|
-
spec.add_development_dependency "redcarpet"
|
42
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
if ENV["S3"]
|
2
|
-
require "refile/backend/s3"
|
3
|
-
|
4
|
-
config = YAML.load_file("s3.yml").map { |k, v| [k.to_sym, v] }.to_h
|
5
|
-
|
6
|
-
RSpec.describe Refile::Backend::S3 do
|
7
|
-
let(:backend) { Refile::Backend::S3.new(max_size: 100, **config) }
|
8
|
-
|
9
|
-
it_behaves_like :backend
|
10
|
-
end
|
11
|
-
end
|
data/spec/refile/test_app.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
require "rails/all"
|
2
|
-
|
3
|
-
require "refile"
|
4
|
-
require "refile/rails"
|
5
|
-
require "jquery/rails"
|
6
|
-
|
7
|
-
module Refile
|
8
|
-
class TestApp < Rails::Application
|
9
|
-
config.secret_token = "6805012ab1750f461ef3c531bdce84c0"
|
10
|
-
config.session_store :cookie_store, key: "_refile_session"
|
11
|
-
config.active_support.deprecation = :log
|
12
|
-
config.eager_load = false
|
13
|
-
config.action_dispatch.show_exceptions = false
|
14
|
-
config.consider_all_requests_local = true
|
15
|
-
config.root = ::File.expand_path("test_app", ::File.dirname(__FILE__))
|
16
|
-
end
|
17
|
-
|
18
|
-
Rails.backtrace_cleaner.remove_silencers!
|
19
|
-
TestApp.initialize!
|
20
|
-
end
|
21
|
-
|
22
|
-
require "rspec"
|
23
|
-
require "rspec/rails"
|
24
|
-
require "capybara/rails"
|
25
|
-
require "capybara/rspec"
|
26
|
-
require "refile/spec_helper"
|
27
|
-
require "refile/active_record_helper"
|
28
|
-
|
29
|
-
if ENV["SAUCE_BROWSER"]
|
30
|
-
Capybara.register_driver :selenium do |app|
|
31
|
-
url = "http://#{ENV["SAUCE_USERNAME"]}:#{ENV["SAUCE_ACCESS_KEY"]}@localhost:4445/wd/hub"
|
32
|
-
capabilities = { browserName: ENV["SAUCE_BROWSER"], version: ENV["SAUCE_VERSION"] }
|
33
|
-
driver = Capybara::Selenium::Driver.new(app, browser: :remote, url: url, desired_capabilities: capabilities)
|
34
|
-
driver.browser.file_detector = ->(args) { args.first if File.exist?(args.first) }
|
35
|
-
driver
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
Capybara.configure do |config|
|
40
|
-
config.server_port = 56_120
|
41
|
-
end
|
42
|
-
|
43
|
-
Refile.allow_origin = "*"
|
44
|
-
Refile.host = "//localhost:56120"
|
45
|
-
|
46
|
-
module TestAppHelpers
|
47
|
-
def download_link(text)
|
48
|
-
url = find_link(text)[:href]
|
49
|
-
if Capybara.current_driver == :rack_test
|
50
|
-
using_session :other do
|
51
|
-
visit(url)
|
52
|
-
page.source.chomp
|
53
|
-
end
|
54
|
-
else
|
55
|
-
Net::HTTP.get_response(URI(url)).body.chomp
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
RSpec.configure do |config|
|
61
|
-
config.include TestAppHelpers, type: :feature
|
62
|
-
config.before(:all) do
|
63
|
-
Refile.logger = Rails.logger
|
64
|
-
end
|
65
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
//= require jquery
|
2
|
-
//= require refile
|
3
|
-
|
4
|
-
"use strict";
|
5
|
-
|
6
|
-
if(document.addEventListener) {
|
7
|
-
document.addEventListener("DOMContentLoaded", function() {
|
8
|
-
var form = document.querySelector("form#direct");
|
9
|
-
|
10
|
-
if(form) {
|
11
|
-
var input = document.querySelector("#post_document");
|
12
|
-
|
13
|
-
form.addEventListener("upload:start", function() {
|
14
|
-
var p = document.createElement("p");
|
15
|
-
p.textContent = "Upload started";
|
16
|
-
form.appendChild(p);
|
17
|
-
});
|
18
|
-
|
19
|
-
form.addEventListener("upload:complete", function(e) {
|
20
|
-
var p = document.createElement("p");
|
21
|
-
p.textContent = "Upload complete " + e.detail;
|
22
|
-
form.appendChild(p);
|
23
|
-
});
|
24
|
-
|
25
|
-
form.addEventListener("upload:progress", function(e) {
|
26
|
-
var p = document.createElement("p");
|
27
|
-
p.textContent = "Upload progress " + e.detail.loaded + " " + e.detail.total;
|
28
|
-
form.appendChild(p);
|
29
|
-
});
|
30
|
-
|
31
|
-
form.addEventListener("upload:failure", function(e) {
|
32
|
-
var p = document.createElement("p");
|
33
|
-
p.textContent = "Upload failure " + e.detail
|
34
|
-
form.appendChild(p);
|
35
|
-
});
|
36
|
-
}
|
37
|
-
});
|
38
|
-
|
39
|
-
$(document).on("upload:success", "form#direct", function(e) {
|
40
|
-
$("<p></p>").text("Upload success " + e.originalEvent.detail).appendTo(this);
|
41
|
-
});
|
42
|
-
}
|
@@ -1,15 +0,0 @@
|
|
1
|
-
class DirectPostsController < ApplicationController
|
2
|
-
def new
|
3
|
-
@post = Post.new
|
4
|
-
end
|
5
|
-
|
6
|
-
def create
|
7
|
-
@post = Post.new(params.require(:post).permit(:title, :document, :image))
|
8
|
-
|
9
|
-
if @post.save
|
10
|
-
redirect_to [:normal, @post]
|
11
|
-
else
|
12
|
-
render :new
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
class NormalPostsController < ApplicationController
|
2
|
-
def index
|
3
|
-
@posts = Post.all
|
4
|
-
end
|
5
|
-
|
6
|
-
def show
|
7
|
-
@post = Post.find(params[:id])
|
8
|
-
end
|
9
|
-
|
10
|
-
def new
|
11
|
-
@post = Post.new
|
12
|
-
end
|
13
|
-
|
14
|
-
def edit
|
15
|
-
@post = Post.find(params[:id])
|
16
|
-
end
|
17
|
-
|
18
|
-
def create
|
19
|
-
@post = Post.new(post_params)
|
20
|
-
|
21
|
-
if @post.save
|
22
|
-
redirect_to [:normal, @post]
|
23
|
-
else
|
24
|
-
render :new
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def update
|
29
|
-
@post = Post.find(params[:id])
|
30
|
-
|
31
|
-
if @post.update_attributes(post_params)
|
32
|
-
redirect_to [:normal, @post]
|
33
|
-
else
|
34
|
-
render :edit
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def destroy
|
39
|
-
Post.find(params[:id]).destroy
|
40
|
-
redirect_to :normal_posts
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def post_params
|
46
|
-
params.require(:post).permit(:title, :image, :document, :remove_document, :remote_document_url)
|
47
|
-
end
|
48
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
class PresignedPostsController < ApplicationController
|
2
|
-
def new
|
3
|
-
@post = Post.new
|
4
|
-
end
|
5
|
-
|
6
|
-
def create
|
7
|
-
@post = Post.new(params.require(:post).permit(:title, :document))
|
8
|
-
|
9
|
-
if @post.save
|
10
|
-
redirect_to [:normal, @post]
|
11
|
-
else
|
12
|
-
render :new
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
# rubocop:disable Metrics/AbcSize
|
17
|
-
def upload
|
18
|
-
if params[:token] == "xyz123"
|
19
|
-
if params[:file].size < 100
|
20
|
-
File.open(File.join(Refile.backends["limited_cache"].directory, params[:id]), "wb") do |file|
|
21
|
-
file.write(params[:file].read)
|
22
|
-
end
|
23
|
-
render text: "token accepted"
|
24
|
-
else
|
25
|
-
render text: "too large", status: 413
|
26
|
-
end
|
27
|
-
else
|
28
|
-
render text: "token rejected", status: 403
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
<%= form_for [:direct, @post], html: { id: "direct" } do |form| %>
|
2
|
-
<p>
|
3
|
-
<%= @post.errors.full_messages.to_sentence %>
|
4
|
-
</p>
|
5
|
-
<p>
|
6
|
-
<%= form.label :title %>
|
7
|
-
<%= form.text_field :title %>
|
8
|
-
</p>
|
9
|
-
<p>
|
10
|
-
<%= form.label :document %>
|
11
|
-
<%= form.attachment_field :document, direct: true %>
|
12
|
-
</p>
|
13
|
-
<p>
|
14
|
-
<%= form.label :image %>
|
15
|
-
<%= form.attachment_field :image, direct: true %>
|
16
|
-
</p>
|
17
|
-
<p>
|
18
|
-
<%= form.submit "Create" %>
|
19
|
-
</p>
|
20
|
-
<% end %>
|
@@ -1 +0,0 @@
|
|
1
|
-
<h1>Hello world</h1>
|
@@ -1,28 +0,0 @@
|
|
1
|
-
<%= form_for [:normal, @post] do |form| %>
|
2
|
-
<p>
|
3
|
-
<%= @post.errors.full_messages.to_sentence %>
|
4
|
-
</p>
|
5
|
-
<p>
|
6
|
-
<%= form.label :title %>
|
7
|
-
<%= form.text_field :title %>
|
8
|
-
</p>
|
9
|
-
<p>
|
10
|
-
<%= form.label :image %>
|
11
|
-
<%= form.attachment_field :image %>
|
12
|
-
</p>
|
13
|
-
<p>
|
14
|
-
<%= form.label :document %>
|
15
|
-
<%= form.attachment_field :document %>
|
16
|
-
</p>
|
17
|
-
<p>
|
18
|
-
<%= form.label :remove_document %>
|
19
|
-
<%= form.check_box :remove_document %>
|
20
|
-
</p>
|
21
|
-
<p>
|
22
|
-
<%= form.label :remote_document_url %>
|
23
|
-
<%= form.text_field :remote_document_url %>
|
24
|
-
</p>
|
25
|
-
<p>
|
26
|
-
<%= form.submit %>
|
27
|
-
</p>
|
28
|
-
<% end %>
|