lhj-tools 0.1.97 → 0.1.98

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: 3141a25ce2e0c2b88124dd148417f856317982f1f4da81b9bd43c90ee858b820
4
- data.tar.gz: 70f7ffc027cbcb03cb1c4b613a2e132cd46e57dbd2833d36ff88aacc395ed636
3
+ metadata.gz: e2687cb0ea3db9db8cdf54d080b9b75a642bde044762994af8ee68b4b9117bd6
4
+ data.tar.gz: f6720ad9be8a1cf1406f8940d2a95a718490e84692a048f798b04690edc32a26
5
5
  SHA512:
6
- metadata.gz: ab33b726b8306c881f3ecbced49a801d1d217cb7a340d88b759e82a4d283f2c18f0db89584296edb8e00ca9abb3c8d212ea82d1ee3cf423b56637b507fa9ba14
7
- data.tar.gz: b172f1fbe29b4475b777a30dd646d0e01bf83015406cfeb22a161010edb2f62a299cee0db36a7a3a2ee9e4ab40b3583f2a5317da749ef0d1b96bc826b837ff4b
6
+ metadata.gz: 50666013e9f5d2565f28cb05c040a3b1bf62e838ee5aa5744c275e3ff088e093df15c3b93f75f841adf43821a9410cb7dfd9b0c8b82a19c737e42fc79b0a1e16
7
+ data.tar.gz: 0cfaa91c509467b565af33b0d81b9401f6119c9e2babc17b4f8f993c53899a3bbc363b6f4851d744db2a00c607ecba6832a401800c446748d3b3645346843167
@@ -19,10 +19,19 @@ module Lhj
19
19
  obj_keys << o.key
20
20
  puts "#{i}.#{o.key}".yellow
21
21
  end
22
- idx = @cli.ask('请选择删除的key: '.green).strip.to_i
23
- oss_key = obj_keys[idx]
24
- puts "删除的key为:#{oss_key}".red
25
- Lhj::OSS::Helper.instance.delete(oss_key)
22
+ idx = @cli.ask('请选择删除的key: '.green)
23
+ idx_arr = idx.split(',').map(&:strip).filter { |v| v.length.positive? }
24
+ result_keys = []
25
+ idx_arr.each do |i|
26
+ ma = /(?<begin>[0-9]*)\D*-\D*(?<end>[0-9]*)/.match(i)
27
+ result_keys << obj_keys[ma[:begin].to_i..ma[:end].to_i] if ma
28
+ result_keys << obj_keys[i.to_i] unless ma
29
+ end
30
+ oss_keys = result_keys.flatten
31
+ oss_keys.each do |oss_key|
32
+ puts "删除的key为:#{oss_key}".red
33
+ end
34
+ Lhj::OSS::Helper.instance.batch_delete(oss_keys) if oss_keys.length > 0
26
35
  end
27
36
 
28
37
  end
@@ -21,17 +21,28 @@ module Lhj
21
21
  obj_keys << o.key
22
22
  puts "#{i}.#{o.key}".yellow
23
23
  end
24
- idx = @cli.ask('请选择下载的序号: '.green).strip.to_i
25
- oss_key = obj_keys[idx]
26
- puts "下载的key为:#{oss_key}".yellow
24
+ idx = @cli.ask('请选择下载的序号: '.green)
25
+ idx_arr = idx.split(',').map(&:strip).filter { |v| v.length.positive? }
26
+ result_keys = []
27
+ idx_arr.each do |i|
28
+ ma = /(?<begin>[0-9]*)\D*-\D*(?<end>[0-9]*)/.match(i)
29
+ result_keys << obj_keys[ma[:begin].to_i..ma[:end].to_i] if ma
30
+ result_keys << obj_keys[i.to_i] unless ma
31
+ end
32
+ Dir.chdir(@current_path) do
33
+ result_keys.flatten.each { |k| download_with_key(k) }
34
+ end
35
+ end
27
36
 
37
+ def download_with_key(oss_key)
38
+ puts "下载的key为:#{oss_key}".yellow
28
39
  file_key = oss_key.split('/').last
29
40
  file = File.join(@current_path, file_key)
41
+ File.rename(file_key, "#{file_key}.bak") if File.exist?(file_key)
30
42
  Lhj::OSS::Helper.instance.down_load(oss_key, file)
31
43
  puts "下载文件到目录: #{file}\n".yellow
32
44
  end
33
-
34
45
  end
35
46
  end
36
47
  end
37
- end
48
+ end
@@ -0,0 +1,15 @@
1
+ require 'lhj/helper/oss_helper'
2
+ require 'terminal-table'
3
+
4
+ module Lhj
5
+ class Command
6
+ class OSS < Command
7
+ class Info < OSS
8
+
9
+ def handle
10
+ Lhj::OSS::Helper.instance.info
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -6,11 +6,38 @@ module Lhj
6
6
  class OSS < Command
7
7
  class List < OSS
8
8
 
9
+ def self.options
10
+ [
11
+ %w[--save 保存文件]
12
+ ]
13
+ end
14
+
15
+ def initialize(argv)
16
+ @save = argv.flag?('save', false)
17
+ @clear = argv.flag?('clear', false)
18
+ @current_path = argv.shift_argument || Dir.pwd
19
+ super
20
+ end
21
+
9
22
  def handle
10
23
  objects = Lhj::OSS::Helper.instance.list
24
+ obj_keys = objects.map(&:key)
25
+ save(obj_keys) if @save
26
+ print(obj_keys) unless @clear
27
+ end
28
+
29
+ def save(obj_keys)
30
+ obj_urls = obj_keys.map { |k| "#{Lhj::OSS::Helper.instance.url_path}/#{k}" }
31
+ FileUtils.chdir(@current_path) do
32
+ File.write('oss_key.yml', obj_keys.to_yaml)
33
+ File.write('oss_url.yml', obj_urls.to_yaml)
34
+ end
35
+ end
36
+
37
+ def print(obj_keys)
11
38
  rows = []
12
- objects.each_with_index do |o, i|
13
- path = "#{i}.#{Lhj::OSS::Helper.instance.url_path}/#{o.key}"
39
+ obj_keys.each_with_index do |k, i|
40
+ path = "#{i}.#{Lhj::OSS::Helper.instance.url_path}/#{k}"
14
41
  rows << [path]
15
42
  end
16
43
  table = Terminal::Table.new title: 'OSS List', headings: ['URL'], rows: rows
@@ -0,0 +1,21 @@
1
+ require 'lhj/helper/oss_helper'
2
+
3
+ # lhj oss list-bucket
4
+ module Lhj
5
+ class Command
6
+ class OSS < Command
7
+ class ListBucket < OSS
8
+ def handle
9
+ helper = Lhj::OSS::Helper.instance
10
+ objects = helper.list_bucket
11
+ bucket_list = []
12
+ objects.each do |o|
13
+ bucket_list << { 'name' => o.name, 'location' => o.location, 'creation_time' => o.creation_time }
14
+ end
15
+ print_obj = { 'oss_bucket_list' => bucket_list }
16
+ puts print_obj.to_yaml
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -28,27 +28,36 @@ module Lhj
28
28
 
29
29
  def handle
30
30
  file_list = []
31
- file_name_list = []
32
31
  Dir.glob("#{@current_path}/*").each_with_index do |f, i|
33
- file_base_name = File.basename(f)
34
32
  file_list << f
35
- file_name_list << file_base_name
36
- puts "#{i}.#{file_base_name}".yellow
33
+ puts "#{i}.#{File.basename(f)}".yellow
34
+ end
35
+ idx = @cli.ask('请选择上传文件序号: '.green)
36
+ idx_arr = idx.split(',').map(&:strip).filter { |v| v.length.positive? }
37
+ results = []
38
+ idx_arr.each do |i|
39
+ ma = /(?<begin>[0-9]*)\D*-\D*(?<end>[0-9]*)/.match(i)
40
+ results << file_list[ma[:begin].to_i..ma[:end].to_i] if ma
41
+ results << file_list[i.to_i] unless ma
42
+ end
43
+ results.flatten.each do |f|
44
+ file_name = File.basename(f)
45
+ puts "上传的文件名:#{file_name}".yellow
46
+ upload(f)
37
47
  end
38
- idx = @cli.ask('请选择上传文件序号: '.green).strip.to_i
39
- puts "上传的文件名:#{file_name_list[idx]}".yellow
40
- upload(file_list[idx], file_name_list[idx])
41
48
  end
42
49
 
43
50
  private
44
51
 
45
- def upload(file, file_name)
52
+ def upload(file)
53
+ file_name = File.basename(file)
46
54
  oss_key = file_name
47
55
  oss_key = "#{@tag}/#{file_name}" if @tag
48
56
  Lhj::OSS::Helper.instance.upload(oss_key, file)
49
57
  url = Lhj::OSS::Helper.instance.object_url(oss_key)
50
58
  puts "云端上传成功:#{url}\n".yellow
51
59
  end
60
+
52
61
  end
53
62
  end
54
63
  end
data/lib/lhj/command.rb CHANGED
@@ -17,6 +17,8 @@ module Lhj
17
17
  require 'lhj/command/oss/del'
18
18
  require 'lhj/command/oss/upload'
19
19
  require 'lhj/command/oss/list'
20
+ require 'lhj/command/oss/info'
21
+ require 'lhj/command/oss/list_bucket'
20
22
  require 'lhj/command/oss/download'
21
23
  require 'lhj/command/code/view'
22
24
  require 'lhj/command/code/code_template'
@@ -10,26 +10,26 @@ module Lhj
10
10
  post_message_robot(robot_url, title, message)
11
11
  end
12
12
 
13
- def self.post_message_robot(robot_url, title, message)
14
- http_body = markdown_body_message(title, message)
15
- http_post(robot_url, http_body)
16
- end
17
-
18
13
  def self.post_card_message(title, message, btns)
19
14
  robot_url = Lhj::DingTalkConfig.dingtalk_robot
20
15
  post_card_message_robot(robot_url, title, message, btns)
21
16
  end
22
17
 
23
- def self.post_card_message_robot(robot_url, title, message, btns)
24
- http_body = action_card_body_message(title, message, btns, :vertical)
25
- http_post(robot_url, http_body)
26
- end
27
-
28
18
  def self.post_single_card_message(title, message, single_title, single_url)
29
19
  robot_url = Lhj::DingTalkConfig.dingtalk_robot
30
20
  post_single_card_message_robot(robot_url, title, message, single_title, single_url)
31
21
  end
32
22
 
23
+ def self.post_message_robot(robot_url, title, message)
24
+ http_body = markdown_body_message(title, message)
25
+ http_post(robot_url, http_body)
26
+ end
27
+
28
+ def self.post_card_message_robot(robot_url, title, message, btns)
29
+ http_body = action_card_body_message(title, message, btns, :vertical)
30
+ http_post(robot_url, http_body)
31
+ end
32
+
33
33
  def self.post_single_card_message_robot(robot_url, title, message, single_title, single_url)
34
34
  http_body = single_action_card_body_message(title, message, single_title, single_url)
35
35
  http_post(robot_url, http_body)
@@ -28,5 +28,9 @@ module Lhj
28
28
  def self.oss_bucket
29
29
  config['oss_bucket']
30
30
  end
31
+
32
+ def self.oss_bucket_list
33
+ config['oss_bucket_list']
34
+ end
31
35
  end
32
36
  end
@@ -11,6 +11,10 @@ module Lhj
11
11
  @bucket = @client.get_bucket(Lhj::OSSConfig.oss_bucket)
12
12
  end
13
13
 
14
+ def get_bucket(name)
15
+ @bucket = @client.get_bucket(name)
16
+ end
17
+
14
18
  def url_path
15
19
  "http://#{Lhj::OSSConfig.oss_bucket}.#{Lhj::OSSConfig.oss_endpoint}"
16
20
  end
@@ -41,10 +45,43 @@ module Lhj
41
45
  @bucket.list_objects
42
46
  end
43
47
 
48
+ # {bucket.name} #{bucket.location}
49
+ def list_bucket
50
+ @client.list_buckets
51
+ end
52
+
44
53
  def delete(key)
45
54
  @bucket.delete_object(key)
46
55
  end
47
56
 
57
+ def batch_delete(keys)
58
+ @bucket.batch_delete_objects(keys)
59
+ end
60
+
61
+ def acl=(acl)
62
+ case acl
63
+ when :public_read_write
64
+ @bucket.acl = (Aliyun::OSS::ACL::PUBLIC_READ_WRITE)
65
+ when :public_read
66
+ @bucket.acl = (Aliyun::OSS::ACL::PUBLIC_READ)
67
+ when :private
68
+ @bucket.acl = (Aliyun::OSS::ACL::PRIVATE)
69
+ end
70
+ end
71
+
72
+ def set_object_acl(key, acl)
73
+ @bucket.set_object_acl(key, acl)
74
+ end
75
+
76
+ def info
77
+ puts @bucket.acl
78
+ puts @bucket.logging
79
+ puts @bucket.lifecycle
80
+ puts @bucket.cors
81
+ puts @bucket.website
82
+ puts @bucket.referer
83
+ end
84
+
48
85
  def self.instance
49
86
  @instance ||= new
50
87
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lhj
4
4
  module Tools
5
- VERSION = "0.1.97"
5
+ VERSION = "0.1.98"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhj-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.97
4
+ version: 0.1.98
5
5
  platform: ruby
6
6
  authors:
7
7
  - lihaijian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-15 00:00:00.000000000 Z
11
+ date: 2023-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xcodeproj
@@ -348,7 +348,9 @@ files:
348
348
  - lib/lhj/command/oss.rb
349
349
  - lib/lhj/command/oss/del.rb
350
350
  - lib/lhj/command/oss/download.rb
351
+ - lib/lhj/command/oss/info.rb
351
352
  - lib/lhj/command/oss/list.rb
353
+ - lib/lhj/command/oss/list_bucket.rb
352
354
  - lib/lhj/command/oss/upload.rb
353
355
  - lib/lhj/command/pgyer_upload.rb
354
356
  - lib/lhj/command/refactor_rename.rb