phoseum-cli 0.0.11 → 0.0.16

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: 54d4c2caa638507e748ded48b8bd2f399118f4c0575d63c79605a30404c52266
4
- data.tar.gz: 96769e821a7a65173ade5e8f1590243844b0f24cdaf5dac3e72018366e99448c
3
+ metadata.gz: b9b6d70c029b61bd0b79fa9b273127031722834e15ce61e3c9af70c4df351257
4
+ data.tar.gz: 785291e7e82d36150ec29aafcdcc965af92f2fed9e2fad501ed16c49961922b4
5
5
  SHA512:
6
- metadata.gz: 036dfce8b227c96a9dacb497e4e99935fbb4a08187af54e6b886aa29d729773e36a881f6055a1991421e11aadbabb252bbd2035875f1e914ab751f62c5d36b6c
7
- data.tar.gz: ffcc052629a6b59a3eecec0a9563e8d1248587f039736ef796325acce034aedc2926a553ca971026e0dfd0916ea63d768ae14d4c84c0cf0825cd4f1bbeb3b603
6
+ metadata.gz: 50c263d913f571b9c55a31e6aab978568067105fb663c3ed2c41a244942e2e06b9c7fa16a3933e53a25f735ec3cefb1a63598fdc000f1d4fe38771b8090ec7e9
7
+ data.tar.gz: ba3c420ac178f153baef9815486cd902cb3f42906bf66bc038bdff0478ea0c52092926e41cf704a5b7e5939cc9bedc88b65872dab94c4182153d89ca0ea5a9df
@@ -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}"
@@ -468,16 +475,50 @@ case options
468
475
  exit 1
469
476
  else
470
477
  album_clean=check_string_sanity(options[:album])
471
- puts "Using Album destination: #{album_clean}".light_blue if !$QUIET
472
- upload(album_clean)
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)
473
499
  end
474
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
475
508
  puts "Start login process".green if !$QUIET
476
509
  if user_login
477
510
  puts "Login successful".green
478
511
  else
479
512
  puts "Login failed".red
480
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
481
522
  when -> (t) { t[:test] }
482
523
  puts "Making local analysis of files on directory".green if !$QUIET
483
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.16"
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.11
4
+ version: 0.0.16
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