aliyunoss 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/aliyunoss/bucket.rb +35 -0
- data/lib/aliyunoss/version.rb +1 -1
- data/spec/aliyunoss/bucket_spec.rb +20 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1ab6499245a17d4022343848dea9974e95309a5748eb230ed4e576cf9239e96
|
4
|
+
data.tar.gz: 6d353d67e14ebab41f7465961b02984280aa1cac08d89a2a422decd6aadfac65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d89365a0762d01cadbee4fea9e9aca18674d49d8bd4c76bc9597dff91415f0b22a4967fae8f4f1b82f9021d543671612a007e648763ed4293689ca38f4a98fc4
|
7
|
+
data.tar.gz: 77d5136397e45db437cfecd604e0dc2208ced0d178c1e81f17d0072796881ab7639673ca53ca5465874c753773ce3630ab61ef4b3876dbba086eb95d80fcf67a
|
data/lib/aliyunoss/bucket.rb
CHANGED
@@ -50,6 +50,34 @@ module Aliyun
|
|
50
50
|
.body
|
51
51
|
end
|
52
52
|
|
53
|
+
#
|
54
|
+
# Get file info
|
55
|
+
#
|
56
|
+
def get_file_info(path)
|
57
|
+
hash = Hash.new
|
58
|
+
Aliyun::Oss::API.head_object(self, path).raise_unless(Net::HTTPOK).each_header do |k,v|
|
59
|
+
hash[k] = v
|
60
|
+
end
|
61
|
+
hash
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# Test if a file exist
|
66
|
+
# return true/false
|
67
|
+
#
|
68
|
+
def exist?(path)
|
69
|
+
begin
|
70
|
+
Aliyun::Oss::API.head_object(self, path).raise_unless(Net::HTTPOK)
|
71
|
+
true
|
72
|
+
rescue OssException => ex
|
73
|
+
if (ex.message.include? 'Net::HTTPNotFound')
|
74
|
+
false
|
75
|
+
else
|
76
|
+
raise ex
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
53
81
|
#
|
54
82
|
# Generate a url that can be shared to others
|
55
83
|
#
|
@@ -57,6 +85,13 @@ module Aliyun
|
|
57
85
|
Aliyun::Oss::API.generate_share_url(self, path, expires_in)
|
58
86
|
end
|
59
87
|
|
88
|
+
#
|
89
|
+
# Generate public url for path
|
90
|
+
#
|
91
|
+
def public_url(path)
|
92
|
+
"https://#{name}.#{location}.aliyuncs.com#{path}"
|
93
|
+
end
|
94
|
+
|
60
95
|
#
|
61
96
|
# Delete remote file
|
62
97
|
#
|
data/lib/aliyunoss/version.rb
CHANGED
@@ -72,6 +72,26 @@ describe Aliyun::Oss::Bucket do
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
+
it 'get file info from server' do
|
76
|
+
path = '/test-1.png'
|
77
|
+
file_info = @bucket.get_file_info(path)
|
78
|
+
expect(file_info['server']).to eq('AliyunOSS')
|
79
|
+
expect(file_info['content-length']).to eq('127759')
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'cannot get file info if file not existed' do
|
83
|
+
path = '/test-8.png'
|
84
|
+
expect(@bucket.exist?(path)).to be false
|
85
|
+
|
86
|
+
path = '/test-3.png'
|
87
|
+
expect(@bucket.exist?(path)).to be true
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'get public url for file' do
|
91
|
+
path = '/test-3.png'
|
92
|
+
expect(@bucket.public_url(path)).to eq("https://#{@bucket_name}.oss-cn-beijing.aliyuncs.com/test-3.png")
|
93
|
+
end
|
94
|
+
|
75
95
|
it 'should delete file on server' do
|
76
96
|
['/test-1.png','/test-2.png','/test-3.png', '/multi-part-test.dat', '/multi-part-copy.dat'].each do |path|
|
77
97
|
@bucket.delete(path)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aliyunoss
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yijiecc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|