phoseum-cli 0.0.10 → 0.0.15
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 +51 -5
- data/lib/phoseum/phoseum-cli-lib.rb +65 -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: af257807e723ba9bd048a4aa3b443b60e94614c32d944b3ea63b35f5e1c7cbff
|
4
|
+
data.tar.gz: de51ee8815a3b7f41356756ab6d58e4f7e1da472a195a2481a06119fa25ed368
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be9c074abcd17b62d9ad734b7ba3f768c0bec3d7bfc762ea08a4e15ef7f0a731b27c1a5674dabd2361baa5ebbc3b207fa62b16a85cc443af63274086b1b45afa
|
7
|
+
data.tar.gz: 214ab50c971d4799c27edf7c08ca16a1202f01c03873980f4e506c2f34e0fc53b950ce73f0df25da70ef9b080b0cfa4e9c6576e89b379c118854063fffc38e4e
|
data/bin/phoseum-cli
CHANGED
@@ -23,7 +23,7 @@ $MULTI = options[:multiple] ? true : false
|
|
23
23
|
|
24
24
|
client_checks
|
25
25
|
|
26
|
-
def upload(album)
|
26
|
+
def upload(album,syn_name='',description='')
|
27
27
|
headers = {}
|
28
28
|
if !validate_token($config['TOKEN'])
|
29
29
|
if token = user_login()
|
@@ -65,7 +65,8 @@ def upload(album)
|
|
65
65
|
# last resort solution for accents and unrecognizable characters
|
66
66
|
# but then will need to remove extension, pass the filter, then add extension again.
|
67
67
|
# human_name = check_string_sanity(filename)
|
68
|
-
human_name = filename
|
68
|
+
human_name = filename.dup
|
69
|
+
human_name = human_name.gsub!(/(.*)\.JPG|JPEG|PNG|GIF$/i,'\1')
|
69
70
|
|
70
71
|
somefound = search_image(image.signature)
|
71
72
|
if somefound
|
@@ -84,6 +85,12 @@ def upload(album)
|
|
84
85
|
post_body << "\r\n--#{BOUNDARY}--\r\n"
|
85
86
|
http = Net::HTTP.new(uri.host, uri.port)
|
86
87
|
headers = headers.merge({ "filename" => "#{image.signature}.#{image.type}", "album" => "#{album}", "name" => human_name })
|
88
|
+
if ! syn_name.nil?
|
89
|
+
headers = headers.merge({ "album_name" => syn_name })
|
90
|
+
end
|
91
|
+
if ! description.nil?
|
92
|
+
headers = headers.merge({ "description" => description })
|
93
|
+
end
|
87
94
|
request = Net::HTTP::Post.new(uri, headers)
|
88
95
|
request.body = post_body.join
|
89
96
|
request["Content-Type"] = "multipart/form-data, boundary=#{BOUNDARY}"
|
@@ -154,7 +161,8 @@ end
|
|
154
161
|
|
155
162
|
def health(what='',name='')
|
156
163
|
headers = {}
|
157
|
-
|
164
|
+
|
165
|
+
if !validate_token($config['TOKEN']) || !$config['TOKEN']
|
158
166
|
if token = user_login()
|
159
167
|
headers = { "bearer" => token }
|
160
168
|
else
|
@@ -233,6 +241,10 @@ def user_mgmt(action,user,pass='',role='')
|
|
233
241
|
post_body={}
|
234
242
|
if action == "add_user"
|
235
243
|
post_body=JSON.generate({"action" => "create-user", "user" => "#{user}", "password" => "#{pass}", "role" => "#{role}"})
|
244
|
+
if !$config['DEFAULT_SECRET']
|
245
|
+
puts "You must have a DEFAULT_SECRET setting to be able to create a user".red
|
246
|
+
exit 1
|
247
|
+
end
|
236
248
|
end
|
237
249
|
base = URI.parse("#{$config['SERVERURL']}")
|
238
250
|
puts "\nConnecting to: #{$config['SERVERURL']}".yellow if !$QUIET
|
@@ -463,16 +475,50 @@ case options
|
|
463
475
|
exit 1
|
464
476
|
else
|
465
477
|
album_clean=check_string_sanity(options[:album])
|
466
|
-
|
467
|
-
|
478
|
+
usable_name= options[:name] ? options[:name].dup : ''
|
479
|
+
usable_desc= options[:description] ? options[:description].dup : ''
|
480
|
+
if usable_name.length > 255 || usable_desc.length > 255
|
481
|
+
if usable_name.length > 255
|
482
|
+
puts "Synthetic name has #{usable_name.length} characters!!".red
|
483
|
+
end
|
484
|
+
if usable_desc.length > 255
|
485
|
+
puts "SHORT Description has #{usable_desc.length} characters!!".red
|
486
|
+
end
|
487
|
+
puts "This is a huge-ass string mate, what are you doing?".red
|
488
|
+
puts "We should limit this to 255 chars. Keep it short. Aborting.".red
|
489
|
+
exit 1
|
490
|
+
end
|
491
|
+
if options[:name]
|
492
|
+
usable_name = clean_name(options[:name])
|
493
|
+
usable_desc = clean_name(options[:description])
|
494
|
+
puts "Using Album destination: #{album_clean} --> Named as '#{usable_name}'".light_blue if !$QUIET
|
495
|
+
else
|
496
|
+
puts "Using Album destination: #{album_clean}".light_blue if !$QUIET
|
497
|
+
end
|
498
|
+
upload(album_clean,usable_name,usable_desc)
|
468
499
|
end
|
469
500
|
when -> (l) { l[:login] }
|
501
|
+
server_value = cross_versions()
|
502
|
+
if server_value['version'] != VERSION_SIGN
|
503
|
+
puts "Server and Client version won't match, please make them match to continue.".red
|
504
|
+
puts "Remote version: #{server_value['version']}"
|
505
|
+
puts "Local version: #{VERSION_SIGN}"
|
506
|
+
exit 1
|
507
|
+
end
|
470
508
|
puts "Start login process".green if !$QUIET
|
471
509
|
if user_login
|
472
510
|
puts "Login successful".green
|
473
511
|
else
|
474
512
|
puts "Login failed".red
|
475
513
|
end
|
514
|
+
when -> (vs) { vs[:version] }
|
515
|
+
local_version
|
516
|
+
exit 0
|
517
|
+
when -> (x) { x[:crossv] }
|
518
|
+
server_value = cross_versions()
|
519
|
+
puts "Remote version: #{server_value['version']}"
|
520
|
+
puts "Local version: #{VERSION_SIGN}"
|
521
|
+
exit 0
|
476
522
|
when -> (t) { t[:test] }
|
477
523
|
puts "Making local analysis of files on directory".green if !$QUIET
|
478
524
|
test
|
@@ -20,6 +20,10 @@ def option_parser(opts)
|
|
20
20
|
options[:delete] = d
|
21
21
|
end
|
22
22
|
|
23
|
+
opts.on("-D", "--description 'SHORTDESC'", "Add album description (up to 255 chars). Use with: [album-path]") do |ds|
|
24
|
+
options[:description] = ds
|
25
|
+
end
|
26
|
+
|
23
27
|
opts.on("-f", "--file-cfg FILENAME", "Use alternative configuration file") do |f|
|
24
28
|
options[:filecfg] = f
|
25
29
|
end
|
@@ -36,10 +40,22 @@ def option_parser(opts)
|
|
36
40
|
options[:multiple] = m
|
37
41
|
end
|
38
42
|
|
43
|
+
opts.on("-N", "--name 'REALNAME'", "Set Album's synthetic name. Use with: [album-path]") do |n|
|
44
|
+
options[:name] = n
|
45
|
+
end
|
46
|
+
|
39
47
|
opts.on("-v", "--verbose", "Run verbosely (DEBUG mode)") do |v|
|
40
48
|
options[:verbose] = v
|
41
49
|
end
|
42
50
|
|
51
|
+
opts.on("-V", "--version", "What version we are") do |vs|
|
52
|
+
options[:version] = vs
|
53
|
+
end
|
54
|
+
|
55
|
+
opts.on("-x", "--cross-versions", "Check version match between Client and API") do |x|
|
56
|
+
options[:crossv] = x
|
57
|
+
end
|
58
|
+
|
43
59
|
opts.on("-r", "--role ROLE", "Role for user: [User, Super]. Use with 'create-user'") do |r|
|
44
60
|
options[:role] = r
|
45
61
|
end
|
@@ -149,6 +165,17 @@ def clean_html(msg)
|
|
149
165
|
return msg
|
150
166
|
end
|
151
167
|
|
168
|
+
def clean_name(nameval)
|
169
|
+
name_words = nameval.split(' ')
|
170
|
+
name = ''
|
171
|
+
name_words.each do |word|
|
172
|
+
cword = check_string_sanity(word)
|
173
|
+
name = name.nil? ? cword : [name,cword].join(' ')
|
174
|
+
end
|
175
|
+
name.gsub!(/^\ /,'')
|
176
|
+
return name
|
177
|
+
end
|
178
|
+
|
152
179
|
def check_image_exists(fpath)
|
153
180
|
flocal = fpath.split('/')
|
154
181
|
filename = flocal.last
|
@@ -234,6 +261,37 @@ def validate_token(token)
|
|
234
261
|
end
|
235
262
|
end
|
236
263
|
|
264
|
+
def cross_versions
|
265
|
+
headers = {}
|
266
|
+
base = URI.parse("#{$config['SERVERURL']}")
|
267
|
+
request = Net::HTTP::Post.new(base,headers)
|
268
|
+
request.basic_auth("cli", "loginNOauth")
|
269
|
+
request.body = JSON.generate({"action" => "version-check" })
|
270
|
+
response = Net::HTTP.start(base.hostname, $config['PORT'],
|
271
|
+
:timeout => $config['CALL_TIMEOUT'],
|
272
|
+
:use_ssl => base.scheme == "https",
|
273
|
+
:verify_mode => OpenSSL::SSL::VERIFY_PEER,
|
274
|
+
:ca_file => $config['CA_TRUST']
|
275
|
+
) do |http|
|
276
|
+
http.request(request)
|
277
|
+
end
|
278
|
+
begin
|
279
|
+
list = JSON.parse(response.body)
|
280
|
+
return list
|
281
|
+
# if list['error']
|
282
|
+
# return false
|
283
|
+
# end
|
284
|
+
# if list['success']
|
285
|
+
# return true
|
286
|
+
# end
|
287
|
+
rescue
|
288
|
+
puts "\nThe server sent out an Error:".red
|
289
|
+
puts clean_html(response.body)
|
290
|
+
exit 1
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
|
237
295
|
def delete_user(username)
|
238
296
|
headers = {}
|
239
297
|
if $config['TOKEN']
|
@@ -266,3 +324,10 @@ def delete_user(username)
|
|
266
324
|
exit 1
|
267
325
|
end
|
268
326
|
end
|
327
|
+
|
328
|
+
def local_version
|
329
|
+
puts "This CLI library is running version: #{VERSION_SIGN}"
|
330
|
+
return
|
331
|
+
end
|
332
|
+
|
333
|
+
VERSION_SIGN="0.0.14"
|
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.15
|
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-
|
11
|
+
date: 2020-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yaml
|