darjeelink 0.13.3 → 0.14.1
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: 4f5ecabb09d4b9a2e0a12553b98e220e915e6ccbb2ab5d0a7781a68fd8919844
|
4
|
+
data.tar.gz: 8e2451e81d04c586cb4722dfee5ea17e0d8358eee38204dc005ce20ab6c2589a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6876cb53f8605e28f2ace40885178e9b68dbee5516c23f2596b456d97c9dc1a303429b8f20499a6a617452db8ce0391bdcce9b7224124109a20764eb1c658908
|
7
|
+
data.tar.gz: be14a81de6bb7a609acb727a33decd5bf9a63bd7c1ccbd9b41288e4f9162aa518c77485f80c5f3126ba20fb0d7a342631bcccae1848a3e574f6fec9c050afcc4
|
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.1
|
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-07-27 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
|
- - ">="
|