phoseum-cli 0.0.3 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 972b9572dcaedc922fd21dce2b2e01d6e88f2d0e56d5c783f7a6dc649caaba0c
4
- data.tar.gz: e6982fa62e3c73782969733342c5d6a9286d213bc5bec73ffeddf38b7a72bf91
3
+ metadata.gz: 64322b7d05911b8e332b53a9c71e802ba0328a3f566f510a4c987eaab30447ad
4
+ data.tar.gz: 7f44480404aa5d42533deef77414997b9cf459d215726ce4723aeb37055ed9b9
5
5
  SHA512:
6
- metadata.gz: 7ee2be8d7e2955031aad2a11ab69accb4099a923da96d8b8a2af06654f12c237451eba79084af65e89bdc708f3129c74107ff377b9d2a8352395b2c9d074e4df
7
- data.tar.gz: 52b8c5260934de17dd80c5451471ec2f100052be84ca24a0a1cd3e1d5f52910cc1e49e31fb11589d2f12a70a0a238cf19f5ef84b1b51b6c0de183104ea989a4f
6
+ metadata.gz: eb7348f7bbac6a5f225be5e19a633fb46a57eb33122392dcbff9735eeca51c154acb4a2a7a269642c4145e8c26843620c6f9e3a7483db15fa3dc68ad650cd0fb
7
+ data.tar.gz: 27739486308f80512d929123d46a46b809e1ec930c5b63ff1f227654e9bf42aba183b823646b8a71eddc7f392b8b231e9a84a39b7b66f46ccf773b9529054d3e
@@ -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
 
@@ -66,6 +67,13 @@ def upload(album)
66
67
  # human_name = check_string_sanity(filename)
67
68
  human_name = filename
68
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
+
69
77
  uri = URI.parse($config['SERVERURL'])
70
78
  post_body = []
71
79
  post_body << "--#{BOUNDARY}\r\n"
@@ -342,6 +350,7 @@ def delete(what='',path='')
342
350
  http.request(request)
343
351
  end
344
352
  list = JSON.parse(response.body)
353
+ # missing begin test result
345
354
  puts list
346
355
  else
347
356
  puts "Deleting cancelled.".green
@@ -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.3
4
+ version: 0.0.8
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-03 00:00:00.000000000 Z
11
+ date: 2020-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yaml