fix: user id and link id int64 types

This commit is contained in:
sjdonado
2025-03-20 08:13:07 +01:00
parent 38f9cfd48e
commit 73ee4c4479
9 changed files with 33 additions and 45 deletions
-1
View File
@@ -8,7 +8,6 @@ require "../models/*"
module App::Services::Cli
def self.create_user(name, api_key = nil)
user = App::Models::User.new
user.id = UUID.v4.to_s
user.name = name
user.api_key = api_key || Random::Secure.urlsafe_base64()
+2 -3
View File
@@ -5,7 +5,7 @@ IpLookup.load_mmdb("data/GeoLite2-Country.mmdb")
module App::Services
class ClickTracker
@@queue = Channel(Tuple(String, String, String, String, String)).new(1000)
@@queue = Channel(Tuple(Int64, String, String, String, String)).new(1000)
@@initialized = false
def self.init
@@ -25,7 +25,6 @@ module App::Services
user_agent = user_agent_str != "Unknown" ? UserAgent.new(user_agent_str) : nil
click = App::Models::Click.new
click.id = UUID.v4.to_s
click.link_id = link_id
click.country = country
click.user_agent = user_agent_str
@@ -45,7 +44,7 @@ module App::Services
end
end
def self.track(link_id : String, client_ip : String, user_agent : String, source : String, referer : String)
def self.track(link_id : Int64, client_ip : String, user_agent : String, source : String, referer : String)
init if !@@initialized
@@queue.send({link_id, client_ip, user_agent, source, referer})
+1 -1
View File
@@ -2,7 +2,7 @@ require "digest"
require "base64"
module App::Services::SlugService
def self.shorten_url(url : String, user_id : String) : String
def self.shorten_url(url : String, user_id : Int64) : String
combined = "#{user_id}-#{url}"
crc32_hash = Digest::CRC32.digest(combined)
base62_encoded = Base64.urlsafe_encode(crc32_hash).strip.tr("-_=", "")