cliz 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/cliz +8 -20
- data/lib/functions.rb +34 -0
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3703184d1cd9de97801b00a83b47f88f8128f08faeeda1af9f9e26df6d34cc94
|
4
|
+
data.tar.gz: 8cd9a19cd0082b23d82ee881e887203d761eb1cbeb485433869d45b8f1df1213
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b10004b4751bacccfce8ecd80209ce96d8e3e4da17e2f07db65e75533a13e2a96ecda27d8b4ddc5c8a80efd1bab0fe48c67bdbadba51039960011c2f2131a659
|
7
|
+
data.tar.gz: 0f938d76de017cd9507701b293c88e9f2ce0154f5fc59bd30d8a89ca9890f693cb7ef23bb90b1595e30514f212391a12bacfa4ca864991f3602649a49daa69fc
|
data/bin/cliz
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
require 'securerandom'
|
4
4
|
require 'fileutils'
|
5
5
|
require 'yaml'
|
6
|
+
require_relative '../lib/functions.rb'
|
7
|
+
|
6
8
|
|
7
9
|
config = YAML.load(File.read('config.yml'))
|
8
10
|
|
@@ -27,26 +29,12 @@ HTML = %Q{
|
|
27
29
|
}
|
28
30
|
|
29
31
|
url = ARGV[0]
|
32
|
+
short_suggestion = ARGV[1]
|
30
33
|
redirect_content = HTML.gsub 'https://cliz.in', url
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
unless ARGV[1]
|
36
|
-
loop do
|
37
|
-
random_string = SecureRandom.alphanumeric[..counter]
|
38
|
-
folder_path = "#{OUTPUT_DIR}/#{random_string}/"
|
39
|
-
break unless File.directory?(folder_path)
|
40
|
-
counter += 1
|
41
|
-
end
|
42
|
-
else
|
43
|
-
folder_path = "#{OUTPUT_DIR}/#{ARGV[1]}/"
|
44
|
-
random_string = ARGV[1]
|
45
|
-
if File.directory?(folder_path)
|
46
|
-
puts("This short is already taken. Try another.")
|
47
|
-
exit
|
48
|
-
end
|
49
|
-
end
|
34
|
+
|
35
|
+
short_suggestion ||= generate_short_suggestion OUTPUT_DIR
|
36
|
+
folder_path = get_a_folder_path OUTPUT_DIR, short_suggestion
|
37
|
+
|
50
38
|
|
51
39
|
FileUtils.mkdir_p(folder_path)
|
52
40
|
|
@@ -56,4 +44,4 @@ end
|
|
56
44
|
|
57
45
|
system("sh #{DEPLOY_SCRIPT}") if DEPLOY_SCRIPT
|
58
46
|
|
59
|
-
puts
|
47
|
+
puts File.join BASE_DOMAIN, short_suggestion
|
data/lib/functions.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
##
|
5
|
+
# Gets a folder path for the shortened url
|
6
|
+
def get_a_folder_path output_directory, short_suggestion = nil
|
7
|
+
folder_path = nil
|
8
|
+
|
9
|
+
unless short_suggestion
|
10
|
+
random_string = generate_short_suggestion output_directory
|
11
|
+
folder_path = get_a_folder_path output_directory, random_string
|
12
|
+
else
|
13
|
+
folder_path = File.join(output_directory, short_suggestion, '/')
|
14
|
+
if File.directory?(folder_path)
|
15
|
+
raise ("This short URL is already taken.")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
folder_path
|
20
|
+
end
|
21
|
+
|
22
|
+
def generate_short_suggestion output_directory
|
23
|
+
counter = 0
|
24
|
+
random_string = nil
|
25
|
+
|
26
|
+
loop do
|
27
|
+
random_string = SecureRandom.alphanumeric[..counter]
|
28
|
+
folder_path = File.join(output_directory, random_string, '/')
|
29
|
+
break unless File.directory?(folder_path)
|
30
|
+
counter += 1
|
31
|
+
end
|
32
|
+
|
33
|
+
random_string
|
34
|
+
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.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karthikeyan A K
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Cliz - The static URL shortner
|
14
14
|
email: mindaslab@protonmail.com
|
@@ -18,11 +18,12 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- bin/cliz
|
21
|
+
- lib/functions.rb
|
21
22
|
homepage: https://cliz.in
|
22
23
|
licenses:
|
23
24
|
- GPLV3
|
24
25
|
metadata: {}
|
25
|
-
post_install_message:
|
26
|
+
post_install_message:
|
26
27
|
rdoc_options: []
|
27
28
|
require_paths:
|
28
29
|
- lib
|
@@ -37,8 +38,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
37
38
|
- !ruby/object:Gem::Version
|
38
39
|
version: '0'
|
39
40
|
requirements: []
|
40
|
-
rubygems_version: 3.
|
41
|
-
signing_key:
|
41
|
+
rubygems_version: 3.2.3
|
42
|
+
signing_key:
|
42
43
|
specification_version: 4
|
43
44
|
summary: Cliz - The static URL shortner
|
44
45
|
test_files: []
|