qiniu_form 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +70 -0
- data/Rakefile +2 -0
- data/lib/qiniu_form/rails/engine.rb +7 -0
- data/lib/qiniu_form/rails.rb +7 -0
- data/lib/qiniu_form/version.rb +3 -0
- data/lib/qiniu_form/view_helpers/form_helper.rb +36 -0
- data/lib/qiniu_form/view_helpers/tags/qiniu_upload_field.rb +55 -0
- data/lib/qiniu_form.rb +34 -0
- data/qiniu_form.gemspec +26 -0
- data/vendor/assets/javascripts/jquery.file-upload.js +1427 -0
- data/vendor/assets/javascripts/jquery.iframe-transport.js +214 -0
- data/vendor/assets/javascripts/jquery.ui.sortable.js +2251 -0
- data/vendor/assets/javascripts/qiniu_form.js +267 -0
- data/vendor/assets/stylesheets/qiniu_from.scss +284 -0
- data/vendor/views/_qiniu_upload_field.slim +32 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4cac70708d7b1431b078cde05f74417a161d3331
|
4
|
+
data.tar.gz: b2fc041574201f58e9b9e7760b5888a368435bea
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f8bddca19c15dc3bd476e483fb688c555fc925f1e74f4d952dabcb5ba6402c270cd9b5e7ce528805e4eb589423a73fabbba67ebd5ba077dc3c8a0c99a1b1d070
|
7
|
+
data.tar.gz: 168ca4649e3528ab819b71f7ca10b25433e2d157db7e4fb9d84d34ec4519b7170461de7a091374f032d6356c594c735ad3314aa6d7afcc0644d49e1f2556e7b3
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 jiangzhi.xie
|
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/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
jj# QiniuForm
|
2
|
+
|
3
|
+
Rails Qiniu Upload form
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'qiniu_form'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install qiniu_form
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Init
|
22
|
+
|
23
|
+
Update file: `config/initialize/qiniu_from.rb`
|
24
|
+
|
25
|
+
```
|
26
|
+
QiniuForm.upload_url = 'http://up.qiniu.com'
|
27
|
+
QiniuForm.key_prefix = 'play'
|
28
|
+
QiniuForm.bucket = 'my_bucket'
|
29
|
+
QiniuForm.download_host = 'http://my_bucket.qiniu.download.com'
|
30
|
+
QiniuForm.use_url_value = true # field value: (host + key) or (only key)
|
31
|
+
|
32
|
+
```
|
33
|
+
|
34
|
+
|
35
|
+
Update file `app/assets/javascripts/application.js`
|
36
|
+
|
37
|
+
```
|
38
|
+
# = require 'qiniu_form'
|
39
|
+
```
|
40
|
+
|
41
|
+
Update file `app/assets/stylesheets/application.scss`, (require scss)
|
42
|
+
|
43
|
+
```
|
44
|
+
/*
|
45
|
+
* = require 'qiniu_form'
|
46
|
+
*/
|
47
|
+
```
|
48
|
+
|
49
|
+
copy `qiniu_from/vendoc/views/_qiniu_upload_field.html.slim` to `app/views/application/_qiniu_upload_field`
|
50
|
+
|
51
|
+
|
52
|
+
### Rails views
|
53
|
+
|
54
|
+
```
|
55
|
+
- form_for @user do |f|
|
56
|
+
= f.qiniu_upload_field :name
|
57
|
+
= f.qiniu_upload_field :name, value: 'url'
|
58
|
+
= f.qiniu_upload_field :name, value: 'url', type: :image || :audio || :video || :file
|
59
|
+
|
60
|
+
= qiniu_upload_tag :name, 'value url'
|
61
|
+
= qiniu_upload_tag :name, 'value url', type: :image
|
62
|
+
```
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
1. Fork it ( https://github.com/[my-github-username]/qiniu_form/fork )
|
67
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
68
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
69
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
70
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module ActionView::Helpers
|
2
|
+
module Tags
|
3
|
+
autoload :QiniuUploadField, File.expand_path('../tags/qiniu_upload_field', __FILE__)
|
4
|
+
end
|
5
|
+
|
6
|
+
module FormHelper
|
7
|
+
# Example
|
8
|
+
# qiniu_upload_field(:object_name, method, html_attr => 'my attr')
|
9
|
+
# qiniu_upload_field(:user, :avatar, 'data-id' => 'id')
|
10
|
+
#
|
11
|
+
def qiniu_upload_field(object_name, method, options = {})
|
12
|
+
Tags::QiniuUploadField.new(object_name, method, self, options).render
|
13
|
+
end
|
14
|
+
|
15
|
+
def qiniu_upload_tag(name, value = nil, options = {})
|
16
|
+
qiniu_upload_field(nil, nil, options.merge({
|
17
|
+
:name => name,
|
18
|
+
:value => value
|
19
|
+
}))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class FormBuilder
|
24
|
+
self.field_helpers << :qiniu_upload_field
|
25
|
+
|
26
|
+
# Example
|
27
|
+
# f.qiniu_upload_field(:field, :html_attr => 'my data')
|
28
|
+
# f.qiniu_upload_field(:avatar)
|
29
|
+
# f.qiniu_upload_field(:avatar, 'data-id' => 'id')
|
30
|
+
#
|
31
|
+
def qiniu_upload_field(method, options = {})
|
32
|
+
@template.qiniu_upload_field(@object_name, method, objectify_options(options))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module ActionView
|
2
|
+
module Helpers
|
3
|
+
module Tags
|
4
|
+
class QiniuUploadField < Base
|
5
|
+
|
6
|
+
def render
|
7
|
+
options = @options.stringify_keys
|
8
|
+
add_default_name_and_id(options)
|
9
|
+
options['value'] ||= value(object)
|
10
|
+
options['type'] ||= 'image'
|
11
|
+
|
12
|
+
form_data = qiniu_upload_params(options).to_json
|
13
|
+
|
14
|
+
@template_object.render({
|
15
|
+
:partial => 'qiniu_upload_field',
|
16
|
+
:locals => {
|
17
|
+
form_data: form_data,
|
18
|
+
url: QiniuForm.upload_url,
|
19
|
+
uuid: UUID.generate,
|
20
|
+
name: options['name'],
|
21
|
+
title: options['title'],
|
22
|
+
value: options['value'],
|
23
|
+
type: options['type'],
|
24
|
+
mime_limit: options['mime_limit'],
|
25
|
+
download_host: QiniuForm.download_host,
|
26
|
+
url_value: QiniuForm.use_url_value ? 'true' : nil
|
27
|
+
}
|
28
|
+
})
|
29
|
+
end
|
30
|
+
|
31
|
+
class << self
|
32
|
+
def field_type
|
33
|
+
@field_type ||= self.name.split("::").last.sub("Field", "").downcase
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def field_type
|
40
|
+
self.class.field_type
|
41
|
+
end
|
42
|
+
|
43
|
+
def qiniu_upload_params(opts)
|
44
|
+
upload_params = opts.slice('fsize_limit', 'mime_limit', 'deadlime')
|
45
|
+
key = QiniuForm.generate_upload_key
|
46
|
+
# persistent_ops = ConnettTools::Qiniu.persistent_cmd(key, opts['type'])
|
47
|
+
# upload_params['persistent_ops'] ||= persistent_ops if persistent_ops
|
48
|
+
|
49
|
+
QiniuForm.generate_uptoken(key, upload_params)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
data/lib/qiniu_form.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "qiniu_form/version"
|
2
|
+
|
3
|
+
require 'uuid'
|
4
|
+
|
5
|
+
require 'qiniu_form/rails'
|
6
|
+
require 'qiniu_form/view_helpers/form_helper'
|
7
|
+
require 'active_support/core_ext/hash'
|
8
|
+
|
9
|
+
module QiniuForm
|
10
|
+
class << self
|
11
|
+
attr_accessor :upload_url, :key_prefix, :bucket, :download_host, :use_url_value
|
12
|
+
|
13
|
+
def generate_uptoken(key, options)
|
14
|
+
opts = options.symbolize_keys
|
15
|
+
key ||= generate_upload_key
|
16
|
+
scope = "#{bucket}:#{key}"
|
17
|
+
opts[:deadline] ||= Time.now + 30.minutes
|
18
|
+
# callback_body = BASE_CALLBACK_BODY.map {|k, v| "#{k}=#{v}"}.join('&')
|
19
|
+
|
20
|
+
# if opts[:persistent_ops]
|
21
|
+
# opts[:persistent_notify_url] ||= PERSISTENT_CALLBACK_URL
|
22
|
+
# end
|
23
|
+
|
24
|
+
token = Qiniu.generate_upload_token({scope: scope}.merge!(opts.compact))
|
25
|
+
|
26
|
+
{:token => token, :key => key}
|
27
|
+
end
|
28
|
+
|
29
|
+
def generate_upload_key
|
30
|
+
[key_prefix, UUID.generate].join('/')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
data/qiniu_form.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'qiniu_form/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "qiniu_form"
|
8
|
+
spec.version = QiniuForm::VERSION
|
9
|
+
spec.authors = ["jiangzhi.xie"]
|
10
|
+
spec.email = ["xiejiangzhi@gmail.com"]
|
11
|
+
spec.summary = %q{Qiniu upload from}
|
12
|
+
spec.description = %q{Qiniu upload from}
|
13
|
+
spec.homepage = ""
|
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_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency "rails", '~> 4.0'
|
25
|
+
spec.add_dependency "uuid"
|
26
|
+
end
|