phoseum-cli 0.0.2 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/phoseum-cli +19 -7
- data/lib/phoseum/phoseum-cli-lib.rb +49 -3
- 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: e62ec1e1eb6c93dc221c38db811a6c2fd4da16c6a4f1f557c7abb94eb75c4af3
|
4
|
+
data.tar.gz: 01eb24cf20c9c6a9845d83cebea9ef1c584258df42010caf2a13748df489013c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa277283780b5c30e36b43b3184055a4a83d869408915ce20c66e31d894a91a4415ba954c623d1b265ad2677f648cfb8434bd03706c95b71cd49dddd2ff90e48
|
7
|
+
data.tar.gz: 4aaeae62b2875999db462317bfb0af842c4d7933df07a11937784c2e14aafaa9a04141f48e548792e60bec361b3b09a16c038ce215d6101d618dfe9236c262df
|
data/bin/phoseum-cli
CHANGED
@@ -19,6 +19,7 @@ options = option_parser(ARGV)
|
|
19
19
|
BOUNDARY = "AaB03x"
|
20
20
|
$QUIET = options[:quiet] ? true : false
|
21
21
|
$DEBUG = options[:verbose] ? true : false
|
22
|
+
$MULTI = options[:multiple] ? true : false
|
22
23
|
|
23
24
|
client_checks
|
24
25
|
|
@@ -61,16 +62,28 @@ def upload(album)
|
|
61
62
|
end
|
62
63
|
total_size = (total_size + image.size)
|
63
64
|
|
65
|
+
# last resort solution for accents and unrecognizable characters
|
66
|
+
# but then will need to remove extension, pass the filter, then add extension again.
|
67
|
+
# human_name = check_string_sanity(filename)
|
68
|
+
human_name = filename
|
69
|
+
|
70
|
+
somefound = search_image(image.signature)
|
71
|
+
if somefound
|
72
|
+
print "Filename: #{human_name} was found repeated in Phoseum Server :: ".yellow
|
73
|
+
puts somefound.yellow
|
74
|
+
next if !$MULTI
|
75
|
+
end
|
76
|
+
|
64
77
|
uri = URI.parse($config['SERVERURL'])
|
65
78
|
post_body = []
|
66
79
|
post_body << "--#{BOUNDARY}\r\n"
|
67
|
-
post_body << "Content-Disposition: form-data; name=\"datafile\"; filename=\"#{
|
80
|
+
post_body << "Content-Disposition: form-data; name=\"datafile\"; filename=\"#{image.signature}\"\r\n"
|
68
81
|
post_body << "Content-Type: #{image.mime_type}\r\n"
|
69
82
|
post_body << "\r\n"
|
70
83
|
post_body << File.read(filename)
|
71
84
|
post_body << "\r\n--#{BOUNDARY}--\r\n"
|
72
85
|
http = Net::HTTP.new(uri.host, uri.port)
|
73
|
-
headers = headers.merge({ "filename" =>
|
86
|
+
headers = headers.merge({ "filename" => "#{image.signature}.#{image.type}", "album" => "#{album}", "name" => human_name })
|
74
87
|
request = Net::HTTP::Post.new(uri, headers)
|
75
88
|
request.body = post_body.join
|
76
89
|
request["Content-Type"] = "multipart/form-data, boundary=#{BOUNDARY}"
|
@@ -84,7 +97,6 @@ def upload(album)
|
|
84
97
|
end
|
85
98
|
print "Format: #{image.type} | Dim.: W = #{image.width} H = #{image.height} | Size: #{imgSZ} : ".yellow if !$QUIET
|
86
99
|
|
87
|
-
|
88
100
|
begin
|
89
101
|
msg_resp = JSON.parse(response.body)
|
90
102
|
if msg_resp['success']
|
@@ -94,11 +106,11 @@ def upload(album)
|
|
94
106
|
puts "#{msg_resp['warning']}".yellow
|
95
107
|
warn += 1
|
96
108
|
else
|
97
|
-
puts "#{msg_resp['error']}".red
|
109
|
+
puts "\n#{msg_resp['error']}".red
|
98
110
|
error += 1
|
99
111
|
end
|
100
112
|
rescue
|
101
|
-
puts "
|
113
|
+
puts "\nThe server sent out an Error:".red
|
102
114
|
puts clean_html(response.body)
|
103
115
|
exit 1
|
104
116
|
end
|
@@ -176,7 +188,7 @@ def health(what='',name='')
|
|
176
188
|
data=list['success']
|
177
189
|
end
|
178
190
|
rescue
|
179
|
-
puts "
|
191
|
+
puts "\nThe server sent out an Error:".red
|
180
192
|
puts clean_html(response.body)
|
181
193
|
exit 1
|
182
194
|
end
|
@@ -301,7 +313,7 @@ def user_login()
|
|
301
313
|
return list['token']
|
302
314
|
end
|
303
315
|
rescue
|
304
|
-
puts "
|
316
|
+
puts "\nThe server sent out an Error:".red
|
305
317
|
puts clean_html(response.body)
|
306
318
|
return false
|
307
319
|
end
|
@@ -32,6 +32,10 @@ def option_parser(opts)
|
|
32
32
|
options[:login] = l
|
33
33
|
end
|
34
34
|
|
35
|
+
opts.on("-m", "--multiple", "Ignore repeated images, keep multiple") do |m|
|
36
|
+
options[:multiple] = m
|
37
|
+
end
|
38
|
+
|
35
39
|
opts.on("-v", "--verbose", "Run verbosely (DEBUG mode)") do |v|
|
36
40
|
options[:verbose] = v
|
37
41
|
end
|
@@ -96,7 +100,7 @@ def client_checks
|
|
96
100
|
if $config['SERVERURL'] == ''
|
97
101
|
puts "I could not find a valid SERVERURL configuration. CFG is empty.".red
|
98
102
|
exit 1
|
99
|
-
elsif $config['SERVERURL'] !~ /\A#{URI::regexp(['https'])}\z/
|
103
|
+
elsif $config['SERVERURL'] !~ /\A#{URI::regexp(['https', 'http'])}\z/
|
100
104
|
puts "I could not find a valid SERVERURL configuration. Contains: #{$config['SERVERURL']}".red
|
101
105
|
exit 1
|
102
106
|
end
|
@@ -111,15 +115,57 @@ def client_checks
|
|
111
115
|
puts "I could not find the DEFAULT_SECRET from Phoseum config, Variable is empty.".red
|
112
116
|
exit 1
|
113
117
|
end
|
114
|
-
|
115
118
|
if !$config['SERVERURL']
|
116
119
|
puts "I could not find the SERVERURL from Phoseum config, this client is then useless.".red
|
117
120
|
exit 1
|
118
121
|
end
|
119
|
-
|
120
122
|
if !$config['PORT']
|
121
123
|
puts "I could not find the PORT from Phoseum config, this client is then useless.".red
|
122
124
|
exit 1
|
123
125
|
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def clean_html(msg)
|
129
|
+
msg.gsub!(/<\/?[^>]*>/, ' ')
|
130
|
+
msg.gsub!(/\n\n+/, '\n')
|
131
|
+
msg.gsub!(/^\n|\n$/, ' ')
|
132
|
+
return msg
|
133
|
+
end
|
124
134
|
|
135
|
+
def search_image(sign)
|
136
|
+
headers = {}
|
137
|
+
if $config['TOKEN']
|
138
|
+
headers={ "bearer" => "#{$config['TOKEN']}" }
|
139
|
+
else
|
140
|
+
if token = user_login()
|
141
|
+
headers = { "bearer" => token }
|
142
|
+
else
|
143
|
+
puts "Login Failed".red
|
144
|
+
exit 1
|
145
|
+
end
|
146
|
+
end
|
147
|
+
some_uri="?signature=#{sign}"
|
148
|
+
base = URI.parse("#{$config['SERVERURL']}#{some_uri}")
|
149
|
+
request = Net::HTTP::Get.new(base,headers)
|
150
|
+
response = Net::HTTP.start(base.hostname, $config['PORT'],
|
151
|
+
:timeout => $config['CALL_TIMEOUT'],
|
152
|
+
:use_ssl => base.scheme == "https",
|
153
|
+
:verify_mode => OpenSSL::SSL::VERIFY_PEER,
|
154
|
+
:ca_file => $config['CA_TRUST']
|
155
|
+
) do |http|
|
156
|
+
http.request(request)
|
157
|
+
end
|
158
|
+
begin
|
159
|
+
list = JSON.parse(response.body)
|
160
|
+
if list['warning']
|
161
|
+
return list['warning']
|
162
|
+
end
|
163
|
+
if list['success']
|
164
|
+
return false
|
165
|
+
end
|
166
|
+
rescue
|
167
|
+
puts "\nThe server sent out an Error:".red
|
168
|
+
puts clean_html(response.body)
|
169
|
+
exit 1
|
170
|
+
end
|
125
171
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phoseum-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julio C Hegedus
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yaml
|