cliz 0.0.0 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/cliz +11 -43
- data/lib/functions.rb +57 -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: ff3f968702225f2eca11654dc309d70faa3ffba83da660aa1c6b570d759a2719
|
4
|
+
data.tar.gz: 4d7c5ec22057ba4985b3076def8901abf35eb023c14d4d5bf8ef7031f70cf790
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e40b13d6b3d477e31ca9c308d5a439f0536ded157e17774f2730584c25df56cf48f43833ba376bd796796d9a9dcd942de0ee9c2082af9da069e452a57bb8b81f
|
7
|
+
data.tar.gz: d87a0a516beb1d428582324849c8018461dbcaac577c31284824f7674cb47761ec0a015462eac7f1d09842b296abc90bf93b60a0b9ef710d574b630f0cd73ad3
|
data/bin/cliz
CHANGED
@@ -3,57 +3,25 @@
|
|
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
|
|
9
11
|
OUTPUT_DIR = config['output_dir']
|
10
12
|
BASE_DOMAIN = config['base_domain']
|
11
13
|
DEPLOY_SCRIPT = config['deploy_script']
|
12
|
-
|
13
|
-
<!DOCTYPE html>
|
14
|
-
<html>
|
15
|
-
<head>
|
16
|
-
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
|
17
|
-
<meta content="utf-8" http-equiv="encoding">
|
18
|
-
<script type="text/javascript">
|
19
|
-
window.location.replace("https://cliz.in");
|
20
|
-
</script>
|
21
|
-
<meta http-equiv="refresh" content="0; url='https://cliz.in'" />
|
22
|
-
</head>
|
23
|
-
<body>
|
24
|
-
<p>Please follow <a href="https://cliz.in">this link</a>.</p>
|
25
|
-
</body>
|
26
|
-
</html>
|
27
|
-
}
|
14
|
+
PRE_SCRIPT = config['pre_script']
|
28
15
|
|
29
16
|
url = ARGV[0]
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
50
|
-
|
51
|
-
FileUtils.mkdir_p(folder_path)
|
52
|
-
|
53
|
-
File.open "#{folder_path}/index.html", 'w' do |f|
|
54
|
-
f.puts redirect_content
|
55
|
-
end
|
17
|
+
short_suggestion = ARGV[1]
|
18
|
+
|
19
|
+
system("sh #{PRE_SCRIPT}") if PRE_SCRIPT
|
20
|
+
|
21
|
+
short_suggestion ||= generate_short_suggestion OUTPUT_DIR
|
22
|
+
folder_path = get_a_folder_path OUTPUT_DIR, short_suggestion
|
23
|
+
create_index_file(url, folder_path)
|
56
24
|
|
57
25
|
system("sh #{DEPLOY_SCRIPT}") if DEPLOY_SCRIPT
|
58
26
|
|
59
|
-
puts
|
27
|
+
puts File.join BASE_DOMAIN, short_suggestion
|
data/lib/functions.rb
ADDED
@@ -0,0 +1,57 @@
|
|
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
|
+
short_suggestion ||= generate_short_suggestion output_directory
|
10
|
+
folder_path = File.join(output_directory, short_suggestion, '/')
|
11
|
+
|
12
|
+
if File.directory?(folder_path)
|
13
|
+
raise ("This short URL is already taken.")
|
14
|
+
end
|
15
|
+
|
16
|
+
folder_path
|
17
|
+
end
|
18
|
+
|
19
|
+
def generate_short_suggestion output_directory
|
20
|
+
counter = 0
|
21
|
+
random_string = nil
|
22
|
+
|
23
|
+
loop do
|
24
|
+
random_string = SecureRandom.alphanumeric[..counter]
|
25
|
+
folder_path = File.join(output_directory, random_string, '/')
|
26
|
+
break unless File.directory?(folder_path)
|
27
|
+
counter += 1
|
28
|
+
end
|
29
|
+
|
30
|
+
random_string
|
31
|
+
end
|
32
|
+
|
33
|
+
def create_index_file url, folder_path
|
34
|
+
html = %Q{
|
35
|
+
<!DOCTYPE html>
|
36
|
+
<html>
|
37
|
+
<head>
|
38
|
+
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
|
39
|
+
<meta content="utf-8" http-equiv="encoding">
|
40
|
+
<script type="text/javascript">
|
41
|
+
window.location.replace("https://cliz.in");
|
42
|
+
</script>
|
43
|
+
<meta http-equiv="refresh" content="0; url='https://cliz.in'" />
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
<p>Please follow <a href="https://cliz.in">this link</a>.</p>
|
47
|
+
</body>
|
48
|
+
</html>
|
49
|
+
}
|
50
|
+
|
51
|
+
redirect_content = html.gsub 'https://cliz.in', url
|
52
|
+
FileUtils.mkdir_p(folder_path)
|
53
|
+
|
54
|
+
File.open "#{folder_path}/index.html", 'w' do |f|
|
55
|
+
f.puts redirect_content
|
56
|
+
end
|
57
|
+
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.6
|
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-24 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.15
|
42
|
+
signing_key:
|
42
43
|
specification_version: 4
|
43
44
|
summary: Cliz - The static URL shortner
|
44
45
|
test_files: []
|