goo.gl في طريقه للإغلاق (انظر Google URL Shortener links will no longer be available [updated] - Google Developers Blog). لذلك، ستتعطل الروابط الموجودة في منتداك والتي تتضمن روابط goo.gl بعد 25 أغسطس 2025.
لقد طورت هذا البرنامج النصي لعميل. استغرق الأمر وقتًا أطول بكثير مما قمت بفوترته له وأطول مما أرغب في الاعتراف به.
إنه يبحث عن جميع المشاركات التي تحتوي على goo.gl ثم (إذا لم تكن maps.app.goo.gl أو maps.goo.gl) يحاول استبدالها بعنوان URL الذي يعيده goo.gl. يستخدم مُراجع المشاركات، لذلك يمكنك رؤية أنه تم تحديثه ولماذا ويمكنك التراجع عنه إذا أردت. لقد حاولت جعله آمنًا قدر الإمكان، ولكن استخدمه على مسؤوليتك الخاصة.
إذا كنت لا تعرف كيفية تشغيل هذا البرنامج النصي، فربما لا يجب عليك القيام بذلك بنفسك. إذا كنت بحاجة إلى مساعدة في جعله يعمل ولديك ميزانية، فاتصل بي أو اسأل في Marketplace.
إذا استخدمته ولديك اقتراحات حول كيفية تحسينه، فيرجى الرد و/أو تعديله حسب ما تراه مناسبًا.
URL_CACHE ||= {}
def resolve_url_simple(short_url)
uri = URI.parse(short_url)
response = Net::HTTP.get_response(uri)
if response.is_a?(Net::HTTPRedirection)
response['location']
else
short_url # Return original if no redirection
end
rescue
short_url # Return original if there was an error
end
def resolve_url(short_url)
short_url.gsub!(/http:/,"https:")
# Check if the URL is already in the cache
return URL_CACHE[short_url] if URL_CACHE.key?(short_url)
begin
uri = URI.parse(short_url + "?si=1")
response = Net::HTTP.get_response(uri)
# Resolve the URL if it's a redirection
resolved_url = if response.is_a?(Net::HTTPRedirection)
response['location']
else
short_url # Return original if no redirection
end
sleep 1
# Store the resolved URL in the cache
URL_CACHE[short_url] = resolved_url
resolved_url
rescue
# Store the original URL in the cache in case of an error
URL_CACHE[short_url] = short_url
short_url
end
end
def replace_goo_gl_links(text)
goo_gl_regex = %r{(?<=\A|[\\[\\]\\(\\)\\s])(https?://)?goo\\.gl(/[a-zA-Z0-9]+)+}
text.gsub(goo_gl_regex) do |match|
if match.include?('maps.app.goo.gl')
match
else
full_url = match.start_with?('http') ? match : "https://#{match}"
print "FIXING!!: #{match} -----> "
fixed = resolve_url(full_url)
puts fixed
fixed
end
end
end
def replace_all_goo_gl_links
system_user= User.find(-1)
goo_go = Post.where("raw LIKE '%goo.gl%'")
total_posts = goo_go.count
puts "Found #{total_posts} posts to check"
count = 0
goo_go.find_each do |post|
count += 1
# puts "Processing #{count}. #{Discourse.base_url}/t/#{post.topic_id}/#{post.post_number}"
print "."
# for reasons unclear, trying to update posts in these topics crashed rails
# next if [145478,64885,84408].include? post.topic_id
# find goo.gl links and the the URL to see what it redirects to
new_raw = replace_goo_gl_links(post.raw)
if new_raw != post.raw
revision_options = {
edit_reason: "Fix goo.gl links",
bypass_bump: true
}
begin
puts "Revising (#{count}/#{total_posts}) #{Discourse.base_url}/t/#{post.topic_id}/#{post.post_number}"
if !post.topic # posts in delted topics have no topic and break PostRevisor
post.topic = Topic.with_deleted.find_by(id: post.topic_id)
next if !post.topic
end
PostRevisor.new(post).revise!(system_user, raw: new_raw, **revision_options)
rescue => e
puts "cannot revise (number: #{count} #{Discourse.base_url}/t/#{post.topic_id}/#{post.post_number}): #{e}"
end
sleep 15
end
end
end