cliz 0.0.8 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/cliz +24 -0
  3. data/lib/functions.rb +29 -0
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf2b89520afac2243cd1502181849fbeb54adad8a74cbe636b1601b63354a28a
4
- data.tar.gz: 45c04731b97d3fdba3909a7899caa6907bd193dc7de51dea54a3a003c1d2e416
3
+ metadata.gz: 298c94e7dc3f9d453ed368ec0bcde14528f2306416c01367dd447a841de0bcd6
4
+ data.tar.gz: 7d1f16b725d776e6a44af89d5aba4be0e8e5958513786780193facca791f7183
5
5
  SHA512:
6
- metadata.gz: 0ff881c6b9dc0ea2492363f9130f28388569a9dc8555c7ce03c9215469ddedf3a121d625dfbb7efd08eb6a958ebcdf16c402644b461917aa5215c52afa109855
7
- data.tar.gz: 64466811659c65d6c381e54b440dcd4cbf2838e342f3998121d9ec5fd1b83e869da267f929c00b2f8a3e9eaa3ad61bb418a6d5f86e0c41381088bfe19230fa08
6
+ metadata.gz: 7b668249b3ae982ebd7a75803a00649c71dbf8876d08f59052b11863fe5f958681708a04fb0a4911853a00416082e89d18cba3ccfd529c3b9b93fc4dc3add18b
7
+ data.tar.gz: e7f58dbb7b006c61e7c8549d2f040b45c80c0925419297b0833861d52eaecc81516ba3dbffcf98a41fd277e6989b678ab068bc6259dd9835d5a8a3db66a565eb
data/bin/cliz CHANGED
@@ -3,12 +3,36 @@
3
3
  require 'securerandom'
4
4
  require 'fileutils'
5
5
  require 'yaml'
6
+ require 'fileutils'
6
7
  require_relative '../lib/functions.rb'
7
8
 
8
9
  include Cliz
9
10
 
11
+ FileUtils.mkdir_p 'reverse-index'
12
+
10
13
  config = YAML.load(File.read('config.yml'))
11
14
  url = ARGV[0]
12
15
  short_suggestion = ARGV[1]
16
+
17
+ unless short_suggestion
18
+ # check for reverse index
19
+ reverse_index_file = File.join 'reverse-index', "#{Digest::SHA2.hexdigest url}"
20
+
21
+ if File.exist? reverse_index_file
22
+ base_domain = config['base_domain']
23
+ paths = File.open(reverse_index_file).readlines
24
+ for path in paths
25
+ puts File.join base_domain, path
26
+ end
27
+ exit
28
+ end
29
+ end
30
+
31
+
13
32
  short_url = short config, url, short_suggestion
33
+
34
+ # do reverse index
35
+
36
+ reverse_index config, short_url
37
+
14
38
  puts short_url
data/lib/functions.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'securerandom'
2
2
  require 'fileutils'
3
+ require 'uri'
4
+ require 'digest'
3
5
 
4
6
  module Cliz
5
7
  ##
@@ -73,4 +75,31 @@ module Cliz
73
75
 
74
76
  File.join base_domain, short_suggestion
75
77
  end
78
+
79
+ ##
80
+ # Gets the path of short_url
81
+ # Say its https://cliz.in/abc/d, it returns abc/d
82
+ def path config, short_url
83
+ base_domain = config['base_domain']
84
+ short_url.gsub base_domain, ""
85
+ end
86
+
87
+ def long_url config, short_url
88
+ output_dir = config['output_dir']
89
+
90
+ path = path config, short_url
91
+ file_contents = File.open(File.join(output_dir, path, 'index.html')).readlines.join '\n'
92
+ URI.extract(file_contents).first
93
+ end
94
+
95
+ def reverse_index config, short_url
96
+ long_url = long_url config, short_url
97
+
98
+ reverse_index_file = File.join 'reverse-index', "#{Digest::SHA2.hexdigest long_url}"
99
+
100
+
101
+ File.open reverse_index_file, "a" do |f|
102
+ f.puts path(config, short_url)
103
+ end
104
+ end
76
105
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cliz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karthikeyan A K
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-15 00:00:00.000000000 Z
11
+ date: 2021-10-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Cliz - The static URL shortner
14
14
  email: mindaslab@protonmail.com
@@ -38,7 +38,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0'
40
40
  requirements: []
41
- rubygems_version: 3.2.15
41
+ rubygems_version: 3.2.22
42
42
  signing_key:
43
43
  specification_version: 4
44
44
  summary: Cliz - The static URL shortner