phoseum-cli 0.0.1 → 0.0.6
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/bin/phoseum-cli +25 -14
- data/lib/phoseum/phoseum-cli-lib.rb +49 -3
- metadata +2 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a62dd7a4317315a806e9e0c47fda71440cd5cfe18f8acc14576cb1fc84b2fee4
|
4
|
+
data.tar.gz: 02561a9d90764ed24baf53432d0871d5db73ff2e93026da32a6d4f2f59098386
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1543277b2a80405e9bd65fa7803dc6c57b8ad1e2b10e887448e820d317f95e209a8c6a26f7f62963474e491ab5755e6b506eab577547612b9242eb01e52344cb
|
7
|
+
data.tar.gz: f2533161dcc360ecc7f4a792604f739a472dc54ac023fae45dd20a2dcce1d670e081b28d4683e36a2392c074b6ae87ff57411e5cb24e69ef3b95b6c0b87fc2d2
|
data/bin/phoseum-cli
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
|
+
# encoding: UTF-8
|
2
3
|
|
3
4
|
require "phoseum/phoseum-common-lib"
|
4
5
|
$config = load_config('cli')
|
@@ -7,7 +8,6 @@ require "phoseum/phoseum-cli-lib"
|
|
7
8
|
load_gem('uri')
|
8
9
|
load_gem('json')
|
9
10
|
load_gem('date')
|
10
|
-
load_gem('nokogiri')
|
11
11
|
load_gem('mini_magick')
|
12
12
|
|
13
13
|
require 'optparse'
|
@@ -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,12 +106,12 @@ 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 "
|
102
|
-
puts
|
113
|
+
puts "\nThe server sent out an Error:".red
|
114
|
+
puts clean_html(response.body)
|
103
115
|
exit 1
|
104
116
|
end
|
105
117
|
|
@@ -168,7 +180,6 @@ def health(what='',name='')
|
|
168
180
|
end
|
169
181
|
begin
|
170
182
|
list = JSON.parse(response.body)
|
171
|
-
# puts list
|
172
183
|
if list['error']
|
173
184
|
puts list['error'].red
|
174
185
|
exit 1
|
@@ -177,8 +188,8 @@ def health(what='',name='')
|
|
177
188
|
data=list['success']
|
178
189
|
end
|
179
190
|
rescue
|
180
|
-
puts "
|
181
|
-
puts
|
191
|
+
puts "\nThe server sent out an Error:".red
|
192
|
+
puts clean_html(response.body)
|
182
193
|
exit 1
|
183
194
|
end
|
184
195
|
|
@@ -237,7 +248,6 @@ def user_mgmt(action,user,pass='',role='')
|
|
237
248
|
end
|
238
249
|
begin
|
239
250
|
list = JSON.parse(response.body)
|
240
|
-
# puts list
|
241
251
|
if list['error']
|
242
252
|
puts list['error'].red
|
243
253
|
exit 1
|
@@ -247,8 +257,8 @@ def user_mgmt(action,user,pass='',role='')
|
|
247
257
|
puts data
|
248
258
|
end
|
249
259
|
rescue
|
250
|
-
puts "Error on Login".red
|
251
|
-
puts
|
260
|
+
puts "Error on Login".red
|
261
|
+
puts clean_html(response.body)
|
252
262
|
end
|
253
263
|
exit 0
|
254
264
|
end
|
@@ -303,7 +313,8 @@ def user_login()
|
|
303
313
|
return list['token']
|
304
314
|
end
|
305
315
|
rescue
|
306
|
-
puts
|
316
|
+
puts "\nThe server sent out an Error:".red
|
317
|
+
puts clean_html(response.body)
|
307
318
|
return false
|
308
319
|
end
|
309
320
|
return false
|
@@ -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.6
|
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-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yaml
|
@@ -90,26 +90,6 @@ dependencies:
|
|
90
90
|
- - ">="
|
91
91
|
- !ruby/object:Gem::Version
|
92
92
|
version: 3.0.0
|
93
|
-
- !ruby/object:Gem::Dependency
|
94
|
-
name: nokogiri
|
95
|
-
requirement: !ruby/object:Gem::Requirement
|
96
|
-
requirements:
|
97
|
-
- - "~>"
|
98
|
-
- !ruby/object:Gem::Version
|
99
|
-
version: '1.10'
|
100
|
-
- - ">="
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
version: 1.10.10
|
103
|
-
type: :runtime
|
104
|
-
prerelease: false
|
105
|
-
version_requirements: !ruby/object:Gem::Requirement
|
106
|
-
requirements:
|
107
|
-
- - "~>"
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: '1.10'
|
110
|
-
- - ">="
|
111
|
-
- !ruby/object:Gem::Version
|
112
|
-
version: 1.10.10
|
113
93
|
- !ruby/object:Gem::Dependency
|
114
94
|
name: mini_magick
|
115
95
|
requirement: !ruby/object:Gem::Requirement
|