phoseum-cli 0.0.12 → 0.0.17

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7421fbbac2cf512f6be93770f895e789840cb887864d8b2d45839726cc65204f
4
- data.tar.gz: f0fac7c15624a6652ec739c44e3af2fd6c64980da1cf5eceb41f188aa4734255
3
+ metadata.gz: 55fcf795cbe7c7fe868d31a947711b3f2efc17e748246d3f5373c86f5e7991a4
4
+ data.tar.gz: 5cf61e614209e2416120e36a1ae948aacbea0195d0da6d4782764f6acc0bbd88
5
5
  SHA512:
6
- metadata.gz: '0779e4712800a3a8312128db722b25b99a2084b1a7eb1faa1f609ba83b27d423dd3f7174f1f787618452ffbd0617f722c0db9758356fc94d4f1b7d3daaaf7d69'
7
- data.tar.gz: b299ad615f973916909dcb52f7ef1e4dc9b52a5c6d80d773a2985db5400394036cc8e0802ccaffcc74d35f04eab139079ac9d89bc01b704bd826af80549d22a2
6
+ metadata.gz: ff835b71a62a453a75495a205ec99650e452db565919dd980b6956d7c84fe59af001bdfbbebfcaff1c9d43bfd57607ff2baa29ffac156655e2f4c9e882fd3862
7
+ data.tar.gz: a6a227719b09b49ced47780bc704e7c67610eea30665d763325092e3ede1da0c692c347a7ce7c52ccff6a026bf7efff65f8b8be11b6191ebac6c0329fe9809f7
@@ -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.gsub!(/(.*)\.JPG|JPEG|PNG|GIF$/i,'\1')
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}"
@@ -270,6 +277,15 @@ def user_mgmt(action,user,pass='',role='')
270
277
  end
271
278
 
272
279
  def user_login(puser='',ppass='')
280
+
281
+ server_value = cross_versions()
282
+ if server_value['version'] != VERSION_SIGN
283
+ puts "Server and Client version won't match, please make them match to continue.".red
284
+ puts "Remote version: #{server_value['version']}"
285
+ puts "Local version: #{VERSION_SIGN}"
286
+ exit 1
287
+ end
288
+
273
289
  post_body={}
274
290
  user= !puser ? '' : puser
275
291
  pass= !ppass ? '' : ppass
@@ -468,8 +484,27 @@ case options
468
484
  exit 1
469
485
  else
470
486
  album_clean=check_string_sanity(options[:album])
471
- puts "Using Album destination: #{album_clean}".light_blue if !$QUIET
472
- upload(album_clean)
487
+ usable_name= options[:name] ? options[:name].dup : ''
488
+ usable_desc= options[:description] ? options[:description].dup : ''
489
+ if usable_name.length > 255 || usable_desc.length > 255
490
+ if usable_name.length > 255
491
+ puts "Synthetic name has #{usable_name.length} characters!!".red
492
+ end
493
+ if usable_desc.length > 255
494
+ puts "SHORT Description has #{usable_desc.length} characters!!".red
495
+ end
496
+ puts "This is a huge-ass string mate, what are you doing?".red
497
+ puts "We should limit this to 255 chars. Keep it short. Aborting.".red
498
+ exit 1
499
+ end
500
+ if options[:name]
501
+ usable_name = clean_name(options[:name])
502
+ usable_desc = clean_name(options[:description])
503
+ puts "Using Album destination: #{album_clean} --> Named as '#{usable_name}'".light_blue if !$QUIET
504
+ else
505
+ puts "Using Album destination: #{album_clean}".light_blue if !$QUIET
506
+ end
507
+ upload(album_clean,usable_name,usable_desc)
473
508
  end
474
509
  when -> (l) { l[:login] }
475
510
  puts "Start login process".green if !$QUIET
@@ -478,6 +513,14 @@ case options
478
513
  else
479
514
  puts "Login failed".red
480
515
  end
516
+ when -> (vs) { vs[:version] }
517
+ local_version
518
+ exit 0
519
+ when -> (x) { x[:crossv] }
520
+ server_value = cross_versions()
521
+ puts "Remote version: #{server_value['version']}"
522
+ puts "Local version: #{VERSION_SIGN}"
523
+ exit 0
481
524
  when -> (t) { t[:test] }
482
525
  puts "Making local analysis of files on directory".green if !$QUIET
483
526
  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.17"
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.12
4
+ version: 0.0.17
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-20 00:00:00.000000000 Z
11
+ date: 2020-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yaml