cliz 0.0.2 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/cliz +3 -36
- data/lib/functions.rb +65 -20
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf2b89520afac2243cd1502181849fbeb54adad8a74cbe636b1601b63354a28a
|
4
|
+
data.tar.gz: 45c04731b97d3fdba3909a7899caa6907bd193dc7de51dea54a3a003c1d2e416
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ff881c6b9dc0ea2492363f9130f28388569a9dc8555c7ce03c9215469ddedf3a121d625dfbb7efd08eb6a958ebcdf16c402644b461917aa5215c52afa109855
|
7
|
+
data.tar.gz: 64466811659c65d6c381e54b440dcd4cbf2838e342f3998121d9ec5fd1b83e869da267f929c00b2f8a3e9eaa3ad61bb418a6d5f86e0c41381088bfe19230fa08
|
data/bin/cliz
CHANGED
@@ -5,43 +5,10 @@ require 'fileutils'
|
|
5
5
|
require 'yaml'
|
6
6
|
require_relative '../lib/functions.rb'
|
7
7
|
|
8
|
+
include Cliz
|
8
9
|
|
9
10
|
config = YAML.load(File.read('config.yml'))
|
10
|
-
|
11
|
-
OUTPUT_DIR = config['output_dir']
|
12
|
-
BASE_DOMAIN = config['base_domain']
|
13
|
-
DEPLOY_SCRIPT = config['deploy_script']
|
14
|
-
HTML = %Q{
|
15
|
-
<!DOCTYPE html>
|
16
|
-
<html>
|
17
|
-
<head>
|
18
|
-
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
|
19
|
-
<meta content="utf-8" http-equiv="encoding">
|
20
|
-
<script type="text/javascript">
|
21
|
-
window.location.replace("https://cliz.in");
|
22
|
-
</script>
|
23
|
-
<meta http-equiv="refresh" content="0; url='https://cliz.in'" />
|
24
|
-
</head>
|
25
|
-
<body>
|
26
|
-
<p>Please follow <a href="https://cliz.in">this link</a>.</p>
|
27
|
-
</body>
|
28
|
-
</html>
|
29
|
-
}
|
30
|
-
|
31
11
|
url = ARGV[0]
|
32
12
|
short_suggestion = ARGV[1]
|
33
|
-
|
34
|
-
|
35
|
-
short_suggestion ||= generate_short_suggestion OUTPUT_DIR
|
36
|
-
folder_path = get_a_folder_path OUTPUT_DIR, short_suggestion
|
37
|
-
|
38
|
-
|
39
|
-
FileUtils.mkdir_p(folder_path)
|
40
|
-
|
41
|
-
File.open "#{folder_path}/index.html", 'w' do |f|
|
42
|
-
f.puts redirect_content
|
43
|
-
end
|
44
|
-
|
45
|
-
system("sh #{DEPLOY_SCRIPT}") if DEPLOY_SCRIPT
|
46
|
-
|
47
|
-
puts File.join BASE_DOMAIN, short_suggestion
|
13
|
+
short_url = short config, url, short_suggestion
|
14
|
+
puts short_url
|
data/lib/functions.rb
CHANGED
@@ -1,31 +1,76 @@
|
|
1
1
|
require 'securerandom'
|
2
2
|
require 'fileutils'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
module Cliz
|
5
|
+
##
|
6
|
+
# Gets a folder path for the shortened url
|
7
|
+
def get_a_folder_path output_directory, short_suggestion = nil
|
8
|
+
folder_path = nil
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
short_suggestion ||= generate_short_suggestion output_directory
|
11
|
+
folder_path = File.join(output_directory, short_suggestion, '/')
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
if File.directory?(folder_path)
|
14
|
+
raise ("This short URL is already taken.")
|
15
|
+
end
|
16
|
+
|
17
|
+
folder_path
|
18
|
+
end
|
19
|
+
|
20
|
+
def generate_short_suggestion output_directory
|
21
|
+
counter = 0
|
22
|
+
random_string = nil
|
23
|
+
|
24
|
+
loop do
|
25
|
+
random_string = SecureRandom.alphanumeric[..counter]
|
26
|
+
folder_path = File.join(output_directory, random_string, '/')
|
27
|
+
break unless File.directory?(folder_path)
|
28
|
+
counter += 1
|
29
|
+
end
|
30
|
+
|
31
|
+
random_string
|
14
32
|
end
|
15
33
|
|
16
|
-
folder_path
|
17
|
-
|
34
|
+
def create_index_file url, folder_path
|
35
|
+
html = %Q{
|
36
|
+
<!DOCTYPE html>
|
37
|
+
<html>
|
38
|
+
<head>
|
39
|
+
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
|
40
|
+
<meta content="utf-8" http-equiv="encoding">
|
41
|
+
<script type="text/javascript">
|
42
|
+
window.location.replace("https://cliz.in");
|
43
|
+
</script>
|
44
|
+
<meta http-equiv="refresh" content="0; url='https://cliz.in'" />
|
45
|
+
</head>
|
46
|
+
<body>
|
47
|
+
<p>Please follow <a href="https://cliz.in">this link</a>.</p>
|
48
|
+
</body>
|
49
|
+
</html>
|
50
|
+
}
|
18
51
|
|
19
|
-
|
20
|
-
|
21
|
-
random_string = nil
|
52
|
+
redirect_content = html.gsub 'https://cliz.in', url
|
53
|
+
FileUtils.mkdir_p(folder_path)
|
22
54
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
break unless File.directory?(folder_path)
|
27
|
-
counter += 1
|
55
|
+
File.open "#{folder_path}/index.html", 'w' do |f|
|
56
|
+
f.puts redirect_content
|
57
|
+
end
|
28
58
|
end
|
29
59
|
|
30
|
-
|
31
|
-
|
60
|
+
def short config, url, short_suggestion = nil
|
61
|
+
output_dir = config['output_dir']
|
62
|
+
base_domain = config['base_domain']
|
63
|
+
deploy_script = config['deploy_script']
|
64
|
+
pre_script = config['pre_script']
|
65
|
+
|
66
|
+
system("sh #{pre_script}") if pre_script
|
67
|
+
|
68
|
+
short_suggestion ||= generate_short_suggestion output_dir
|
69
|
+
folder_path = get_a_folder_path output_dir, short_suggestion
|
70
|
+
create_index_file(url, folder_path)
|
71
|
+
|
72
|
+
system("sh #{deploy_script}") if deploy_script
|
73
|
+
|
74
|
+
File.join base_domain, short_suggestion
|
75
|
+
end
|
76
|
+
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.8
|
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-
|
11
|
+
date: 2021-05-15 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.
|
41
|
+
rubygems_version: 3.2.15
|
42
42
|
signing_key:
|
43
43
|
specification_version: 4
|
44
44
|
summary: Cliz - The static URL shortner
|