bbs_uploader 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -3
- data/bbs_uploader.gemspec +1 -0
- data/bin/bbs_uploader +13 -5
- data/lib/bbs_uploader/version.rb +1 -1
- data/lib/bbs_uploader.rb +34 -12
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4327524fff1ee26bc9582eee8f31a82bf1a07d29
|
4
|
+
data.tar.gz: 3a9639f3f2b7ffdd8e98ed479baaa148160fc4cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e4f2351bf56b9052a59ffdf692bf6a05fd223191e7c416f20be6e01be707b03be5e29b70b6dc9183e5609fc87c87fe00f9df7b960403bf9d285b4e9049181bc
|
7
|
+
data.tar.gz: 374357354892a1480c96d9919917d39076a6050fc227d8617c421f8d2e0d7f3a779e84a9c2363521be590d751cff13e7853f19e0ae536cc33cfb11d9c5fc44be
|
data/README.md
CHANGED
@@ -54,9 +54,13 @@ markdown 链接: 
|
|
54
54
|
|
55
55
|

|
56
56
|
|
57
|
+
|
58
|
+

|
59
|
+
|
57
60
|
**编程使用:**
|
58
61
|
|
59
62
|
```
|
63
|
+
# 选项传递的 Hash 值可以是任意形态的,实现中利用 hashie 抹平了差异
|
60
64
|
BbsUploader.qiniu = {
|
61
65
|
access_key: 'your access key',
|
62
66
|
secret_key: 'your secret key',
|
@@ -70,12 +74,11 @@ BbsUploader.upload 'http://xiajian.github.io/assets/images/dongxiang.png'
|
|
70
74
|
|
71
75
|
BbsUploader.upload_image '~/Downloads/test.jpg'
|
72
76
|
BbsUploader.upload_file '~/Downloads/install.php'
|
73
|
-
|
74
77
|
```
|
75
78
|
|
76
|
-
|
79
|
+
然后,就祝君安好!!!
|
77
80
|
|
78
|
-
> PS: 思考 网盘以及 CDN 在部署的上区别。 CDN 内容分发,网盘就是云存储。 这就不明白,SB!!
|
81
|
+
> PS: 思考 网盘以及 CDN 在部署的上区别。 CDN 内容分发,网盘就是云存储。 这就不明白,SB!! 上传的 js 以及 css 文件,直接下载获取,不如 专业的 cdn 资源的获取的速度快,所以,专业的 CDN 系统还是有特殊的优化处理的。
|
79
82
|
|
80
83
|
## Development
|
81
84
|
|
data/bbs_uploader.gemspec
CHANGED
data/bin/bbs_uploader
CHANGED
@@ -24,17 +24,25 @@ OptionParser.new do |opts|
|
|
24
24
|
opts.on('-i', '--input-file [file]', 'Input file can be URL, image file or other file') do |file|
|
25
25
|
options[:input_file] = File.absolute_path file
|
26
26
|
end
|
27
|
+
|
28
|
+
opts.on('-d', '--input-directory [directory]', 'Input directory must be a directory') do |dir|
|
29
|
+
options[:input_directory] = File.absolute_path file
|
30
|
+
end
|
27
31
|
end.parse!
|
28
32
|
|
29
|
-
if options[:input_file].nil?
|
33
|
+
if options[:input_file].nil? || options[:input_directory].nil?
|
30
34
|
file = ARGV[0]
|
31
35
|
|
32
36
|
if file.nil?
|
33
|
-
puts "
|
37
|
+
puts "没有选择上传的文件或目录"
|
34
38
|
exit
|
35
39
|
end
|
36
|
-
|
37
|
-
|
40
|
+
|
41
|
+
if File.directory?(File.absolute_path(file))
|
42
|
+
options[:input_directory] = file
|
43
|
+
else
|
44
|
+
options[:input_file] = file
|
45
|
+
end
|
38
46
|
end
|
39
47
|
|
40
|
-
BbsUploader.
|
48
|
+
BbsUploader.command options
|
data/lib/bbs_uploader/version.rb
CHANGED
data/lib/bbs_uploader.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "qiniu"
|
2
2
|
require "open-uri" # 下载文件
|
3
|
+
require 'hashie'
|
3
4
|
require "bbs_uploader/version"
|
4
5
|
require "bbs_uploader/ruby_regex"
|
5
6
|
|
@@ -28,12 +29,14 @@ module BbsUploader
|
|
28
29
|
end
|
29
30
|
|
30
31
|
def default_options(options = {})
|
31
|
-
|
32
|
+
options = Hashie::Mash.new(options)
|
33
|
+
|
34
|
+
Hashie::Mash.new({
|
32
35
|
access_key: "79WvzAxvV-nOEX7m0PERzwR0Lhm-FDHriz2-QdAN",
|
33
36
|
secret_key: "4wwnWNU16n9uVK8DHRW6qO61b2gls3aSduHswkvc",
|
34
37
|
bucket: "bss-image",
|
35
38
|
bucket_domain: "ognvcf5x6.bkt.clouddn.com"
|
36
|
-
}.merge(options)
|
39
|
+
}).merge(options)
|
37
40
|
end
|
38
41
|
|
39
42
|
# 下载文件 - 依赖本地的 tmp 目录, 需要 `open-uri`
|
@@ -130,6 +133,8 @@ module BbsUploader
|
|
130
133
|
|
131
134
|
if file_path =~ IMAGE_FILE_REGEXP
|
132
135
|
upload_image file_path
|
136
|
+
else
|
137
|
+
upload_file file_path
|
133
138
|
end
|
134
139
|
elsif File.exist? resource
|
135
140
|
file_path = File.absolute_path(resource)
|
@@ -143,12 +148,27 @@ module BbsUploader
|
|
143
148
|
puts "输入的文件 #{resource} 不存在,请检查后重试"
|
144
149
|
end
|
145
150
|
end
|
151
|
+
|
152
|
+
def upload_with_directory(dir = '')
|
153
|
+
dir = `cd #{dir}; pwd`.chomp
|
154
|
+
return unless File.exists?(dir) && File.directory?(dir)
|
155
|
+
|
156
|
+
puts "上传目录: #{dir}"
|
157
|
+
|
158
|
+
files = `ls #{dir}`.split("\n").map { |filename| "#{dir}/#{filename}" }
|
159
|
+
|
160
|
+
file_links = files.map { |file| upload(file) }
|
161
|
+
|
162
|
+
puts "生成的图片的链接: #{file_links.join('\n')}"
|
163
|
+
|
164
|
+
file_links
|
165
|
+
end
|
146
166
|
|
147
167
|
def markdown_image_link(image_url)
|
148
168
|
if image_url && image_url.is_a?(String) && IMAGE_URL_REGEXP.match(image_url)
|
149
169
|
""
|
150
170
|
else
|
151
|
-
|
171
|
+
image_url
|
152
172
|
end
|
153
173
|
end
|
154
174
|
|
@@ -156,18 +176,20 @@ module BbsUploader
|
|
156
176
|
#
|
157
177
|
# @note 注意文件需要按照文件目录的自然顺序
|
158
178
|
def generate_markdown_format(dir)
|
159
|
-
content =
|
160
|
-
|
161
|
-
|
162
|
-
`ls #{dir}`.split('\n').map { |filename| files << "#{dir}/#{filename}" }
|
163
|
-
|
164
|
-
files.each do |file|
|
165
|
-
content << markdown_image_link(upload_image(file)) + "\n"
|
166
|
-
end
|
167
|
-
|
179
|
+
content = upload_with_directory(dir).map { |link| markdown_image_link(link) }.join("\n")
|
180
|
+
|
181
|
+
puts "上传链接地址: \n"
|
168
182
|
puts content
|
169
183
|
|
170
184
|
content
|
171
185
|
end
|
186
|
+
|
187
|
+
def command(options = {})
|
188
|
+
if options[:input_file]
|
189
|
+
upload options[:input_file]
|
190
|
+
elsif options[:input_directory]
|
191
|
+
generate_markdown_format options[:input_directory]
|
192
|
+
end
|
193
|
+
end
|
172
194
|
end
|
173
195
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bbs_uploader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xiajian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: qiniu
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: hashie
|
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'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|