darjeelink 0.13.3 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/app/controllers/darjeelink/short_links_controller.rb +1 -1
- data/app/models/darjeelink/short_link.rb +16 -20
- data/lib/darjeelink/version.rb +1 -1
- 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: 96f614f236d3e7d9d03fe066719066ce2b4e1d3e5673fd0c78756bcdbfe0bbe6
|
4
|
+
data.tar.gz: b698bd03bf5d648650aa72b8056e47ee952211732dda6257837e1e2b87f21853
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76068de4b9ac74d9bce9e2255cc9b28637dc3d32dcd8409d1b12598f14cb92508abf730b8f2a693873b24b485e7202708e9b8ad8639e88f921054f8841559421
|
7
|
+
data.tar.gz: 7f56e2b13c2f9041205e65e792a9b9afb72779d516bed82dc652379a1ff482c94f515627681e065a4116c5a8c51355029bf4b2b07faa71fcd92f3becdc2fdc55
|
data/README.md
CHANGED
@@ -101,7 +101,10 @@ Each key is a hyphenated source-medium. If you just want the source then omit t
|
|
101
101
|
Each value is a slightly more readable version for display.
|
102
102
|
|
103
103
|
## Development
|
104
|
-
|
104
|
+
|
105
|
+
Docker can be used to run tests easily - 'docker-compose up' should run the unit tests.
|
106
|
+
|
107
|
+
Another approach is to use Vagrant. `vagrant up` will create an isolated darjeelink instance.
|
105
108
|
Before you run `vagrant up`, make sure to create `.env.development` & `.env.test` files as detailed below.
|
106
109
|
|
107
110
|
### Setup development environment
|
@@ -60,7 +60,7 @@ module Darjeelink
|
|
60
60
|
begin
|
61
61
|
yield
|
62
62
|
rescue ActiveRecord::RecordNotUnique
|
63
|
-
flash[:error] = "#{
|
63
|
+
flash[:error] = "#{short_link_params[:shortened_path]} already used! Choose a different custom path"
|
64
64
|
return redirect_to(error_redirect_path)
|
65
65
|
rescue ActiveRecord::RecordInvalid => e
|
66
66
|
flash[:error] = e.message.to_s
|
@@ -1,8 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'securerandom'
|
4
|
+
|
3
5
|
module Darjeelink
|
4
6
|
class ShortLink < ApplicationRecord
|
5
|
-
|
7
|
+
# ActiveRecord::RecordNotUnique error unable to be raised in a transaction that is not committed
|
8
|
+
after_commit :generate_short_link
|
9
|
+
|
10
|
+
def self.auto_generate_shortened_path
|
11
|
+
# our current db has a case insensitive constraint so we might as well downcase here before we get to db level
|
12
|
+
pp SecureRandom.urlsafe_base64(3).downcase
|
13
|
+
end
|
6
14
|
|
7
15
|
validates_presence_of :url
|
8
16
|
validates :url, :shortened_path, format: {
|
@@ -31,26 +39,14 @@ module Darjeelink
|
|
31
39
|
def generate_short_link
|
32
40
|
return if shortened_path.present?
|
33
41
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
# with only minor modification
|
42
|
-
i = id
|
43
|
-
return ALPHABET[0] if i.zero?
|
44
|
-
|
45
|
-
generated_path = []
|
46
|
-
base = ALPHABET.length
|
47
|
-
|
48
|
-
while i.positive?
|
49
|
-
generated_path << ALPHABET[i.modulo(base)]
|
50
|
-
i /= base
|
42
|
+
begin
|
43
|
+
attempt ||= 0
|
44
|
+
update!(shortened_path: self.class.auto_generate_shortened_path)
|
45
|
+
rescue ActiveRecord::RecordNotUnique
|
46
|
+
# we only want to try 5 times to prevent infinite loop
|
47
|
+
attempt += 1
|
48
|
+
attempt <= 5 ? retry : raise
|
51
49
|
end
|
52
|
-
|
53
|
-
generated_path.join.reverse
|
54
50
|
end
|
55
51
|
end
|
56
52
|
end
|
data/lib/darjeelink/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: darjeelink
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Hulme
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: omniauth
|
@@ -253,7 +253,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
253
253
|
requirements:
|
254
254
|
- - ">="
|
255
255
|
- !ruby/object:Gem::Version
|
256
|
-
version:
|
256
|
+
version: 3.1.2
|
257
257
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
258
258
|
requirements:
|
259
259
|
- - ">="
|