2cdn 0.1.7 → 0.1.8
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 +17 -4
- data/bin/2cdn +8 -11
- data/lib/auto-ali-cdn/oss.rb +16 -82
- data/lib/auto-ali-cdn/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c691285e178f968741303fa060a4c2a327d8557f
|
4
|
+
data.tar.gz: 3b138f756a8d101de74fbab6c51d886c7de63d9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 538b3f25fc313e7635de598ef4db24039996e248770bb2957ee839bb7eb1016683127d5b72c3045bac8714a1b4382a50714ca2de99a33d3aef8a41456222382c
|
7
|
+
data.tar.gz: 2911819ec352e3cdf660a28a1d9f506424d20a545ad7370361f3a945a9239f0e9a61d555c0366575dbd3dac0769ad18defe2c5963eb5c42cdc6520c0f90cb664
|
data/README.md
CHANGED
@@ -9,7 +9,7 @@ TODO: Delete this and the text above, and describe your gem
|
|
9
9
|
Add this line to your application's Gemfile:
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
gem '
|
12
|
+
gem '2cdn'
|
13
13
|
```
|
14
14
|
|
15
15
|
And then execute:
|
@@ -18,11 +18,25 @@ And then execute:
|
|
18
18
|
|
19
19
|
Or install it yourself as:
|
20
20
|
|
21
|
-
$ gem install
|
21
|
+
$ gem install 2cdn
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
### Setup
|
26
|
+
|
27
|
+
$ 2cdn setup
|
28
|
+
|
29
|
+
### Edit config
|
30
|
+
|
31
|
+
$ vim config/2cdn.yml
|
32
|
+
|
33
|
+
### Upload
|
34
|
+
|
35
|
+
$ 2cdn upload my_path/my.zip remote_path
|
36
|
+
|
37
|
+
### Download
|
38
|
+
|
39
|
+
$ 2cdn download remote_path/2018.1.zip my_path/2018.1.zip
|
26
40
|
|
27
41
|
## Development
|
28
42
|
|
@@ -38,4 +52,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERN
|
|
38
52
|
## License
|
39
53
|
|
40
54
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
-
|
data/bin/2cdn
CHANGED
@@ -11,10 +11,10 @@ Options:
|
|
11
11
|
-V, --version Show program version
|
12
12
|
|
13
13
|
Basic usage:
|
14
|
-
2cdn help
|
15
|
-
2cdn setup
|
16
|
-
2cdn upload
|
17
|
-
2cdn
|
14
|
+
2cdn help # Show help
|
15
|
+
2cdn setup # Init oss file paths
|
16
|
+
2cdn upload # Upload resources to Aliyun Oss `2cdn upload $local_file $remote_file $is_delete`
|
17
|
+
2cdn download # Download resources path to local path
|
18
18
|
EOB
|
19
19
|
end
|
20
20
|
|
@@ -39,9 +39,6 @@ end
|
|
39
39
|
|
40
40
|
if ARGV[0] =~ /^setup$/
|
41
41
|
(system "mkdir #{app_path}/config") unless File.directory?("#{app_path}/config")
|
42
|
-
(system "mkdir #{app_path}/images") unless File.directory?("#{app_path}/images")
|
43
|
-
(system "mkdir #{app_path}/javascripts") unless File.directory?("#{app_path}/javascripts")
|
44
|
-
(system "mkdir #{app_path}/css") unless File.directory?("#{app_path}/css")
|
45
42
|
system "touch #{config_file}"
|
46
43
|
if File.read(config_file).length<=0
|
47
44
|
File.open(config_file, 'w') do |f|
|
@@ -66,9 +63,9 @@ if ARGV[0] =~ /^upload$/
|
|
66
63
|
exit
|
67
64
|
end
|
68
65
|
|
69
|
-
AutoAliCDN::Oss.oss_upload(config_file, app_path)
|
66
|
+
AutoAliCDN::Oss.oss_upload(config_file, app_path, ARGV[1], ARGV[2], ARGV[3])
|
70
67
|
end
|
71
68
|
|
72
|
-
if ARGV[0] =~ /^
|
73
|
-
AutoAliCDN::Oss.
|
74
|
-
end
|
69
|
+
if ARGV[0] =~ /^download$/
|
70
|
+
AutoAliCDN::Oss.oss_download(config_file, app_path, ARGV[1] , ARGV[2])
|
71
|
+
end
|
data/lib/auto-ali-cdn/oss.rb
CHANGED
@@ -30,103 +30,37 @@ module AutoAliCDN
|
|
30
30
|
|
31
31
|
puts bucket.name
|
32
32
|
bucket.put_object(config.site_resource_path+"/.start.txt") { |stream| stream << '2cdn setup ok' }
|
33
|
-
bucket.put_object(config.site_resource_path+"/images/.start.png") { |stream| stream << '2cdn setup ok' }
|
34
|
-
bucket.put_object(config.site_resource_path+"/javascripts/.start.js") { |stream| stream << "console.log('start from here')" }
|
35
|
-
bucket.put_object(config.site_resource_path+"/css/.start.css") { |stream| stream << "body{padding:0;}" }
|
36
33
|
end
|
37
34
|
|
38
|
-
|
39
|
-
def self.oss_upload(config_path, app_path,rename=false)
|
35
|
+
def self.oss_upload(config_path, app_path, local_file, remote_file, delete='false')
|
40
36
|
config = oss_config(config_path)
|
41
|
-
|
42
|
-
images_path = app_path+'/images'
|
43
|
-
javascripts_path = app_path+'/javascripts'
|
44
|
-
css_path = app_path+'/css'
|
45
|
-
|
46
37
|
bucket = bucket(config)
|
47
38
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
f2.puts file_content
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
#upload image javascripts css etc.
|
65
|
-
upload_c = ->(res_path) do
|
66
|
-
Dir.foreach(res_path) do |name|
|
67
|
-
next if name =~ /^(\.)|(\.\.)$/
|
68
|
-
file_path = res_path+"/#{name}"
|
69
|
-
file_md5 = Digest::MD5.hexdigest(File.read(file_path))
|
70
|
-
res_type = res_path.gsub(/^.*\//, '')
|
71
|
-
suffix = "."+name.split(/\./).last
|
72
|
-
new_name = rename ? name.gsub(/#{suffix}$/, "-#{file_md5}#{suffix}"): name
|
73
|
-
object_key = config.site_resource_path+"/#{Time.now.strftime("%F %H:%M")}/#{new_name}"
|
74
|
-
if bucket.object_exists?(object_key)
|
75
|
-
puts "#{name} --> #{object_key}".color(:dimgray)
|
76
|
-
replace_res_path.call(res_type+'/'+name, config.domain_name+'/'+object_key)
|
77
|
-
else
|
78
|
-
bucket.put_object(object_key, :file => file_path)
|
79
|
-
puts "#{name} --> #{object_key}".color(:green)
|
80
|
-
replace_res_path.call(res_type+'/'+name, config.domain_name+'/'+object_key)
|
81
|
-
end
|
39
|
+
object_key = config.site_resource_path+"/#{remote_file}"
|
40
|
+
if bucket.object_exists?(object_key)
|
41
|
+
puts "#{name} --> #{object_key}".color(:dimgray)
|
42
|
+
else
|
43
|
+
begin
|
44
|
+
bucket.put_object(object_key, :file => "#{app_path}/#{local_file}")
|
45
|
+
puts "#{name} --> #{object_key}".color(:green)
|
46
|
+
File.delete("#{app_path}/#{local_file}") if delete == 'true'
|
47
|
+
rescue Aliyun::OSS::CallbackError => e
|
48
|
+
puts "Callback failed: #{e.message}"
|
82
49
|
end
|
83
50
|
end
|
84
|
-
|
85
|
-
upload_c.call(images_path)
|
86
|
-
upload_c.call(javascripts_path)
|
87
|
-
upload_c.call(css_path)
|
88
51
|
end
|
89
52
|
|
90
|
-
def self.
|
53
|
+
def self.oss_download(config_path, app_path, remote_file, local_file)
|
91
54
|
config = oss_config(config_path)
|
92
55
|
|
93
|
-
images_path = app_path+'/images'
|
94
|
-
javascripts_path = app_path+'/javascripts'
|
95
|
-
css_path = app_path+'/css'
|
96
|
-
|
97
56
|
bucket = bucket(config)
|
98
57
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
file_content = File.read("#{app_path}/#{f}").gsub(remote_path, local_path)
|
104
|
-
|
105
|
-
File.open("#{app_path}/#{f}", "w") do |f2|
|
106
|
-
f2.puts file_content
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
debug_c = ->(res_path) do
|
113
|
-
Dir.foreach(res_path) do |name|
|
114
|
-
next if name =~ /^(\.)|(\.\.)$/
|
115
|
-
file_path = res_path+"/#{name}"
|
116
|
-
file_md5 = Digest::MD5.hexdigest(File.read(file_path))
|
117
|
-
res_type = res_path.gsub(/^.*\//, '')
|
118
|
-
suffix = "."+name.split(/\./).last
|
119
|
-
object_key = config.site_resource_path+"/#{res_type}/#{name.gsub(/#{suffix}$/, "-#{file_md5}#{suffix}")}"
|
120
|
-
if bucket.object_exists?(object_key)
|
121
|
-
replace_res_path.call(config.domain_name+'/'+object_key, res_type+'/'+name)
|
122
|
-
puts "#{object_key.color(:red)} --> #{"#{res_type}/#{name}".color(:cyan)}"
|
123
|
-
end
|
124
|
-
end
|
58
|
+
object_key = config.site_resource_path+"/#{remote_file}"
|
59
|
+
if bucket.object_exists?(object_key)
|
60
|
+
bucket.get_object(object_key, :file => "#{app_path}/#{local_file}")
|
61
|
+
puts "#{object_key} --> #{app_path}/#{local_file}".color(:cyan)
|
125
62
|
end
|
126
63
|
|
127
|
-
debug_c.call(images_path)
|
128
|
-
debug_c.call(javascripts_path)
|
129
|
-
debug_c.call(css_path)
|
130
64
|
end
|
131
65
|
|
132
66
|
end
|
data/lib/auto-ali-cdn/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: 2cdn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- liuxi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|