استبدال روابط goo.gl

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

8 إعجابات

لماذا تستبعد هؤلاء؟ هذه الروابط لن تنكسر؟

وشكراً على هذا النص البرمجي. لقد أعدت المشاركات التي تحتوي على هذه الروابط المختصرة في منتدياتي، وهناك الكثير منها سيحتاج إلى إصلاح حينها. :+1:

إعجاب واحد (1)

إليك ما يولده خرائط جوجل اليوم: https://maps.app.goo.gl/Qz14oUZQv9aHCCfg6. لقد قررت تخمين أن تلك النطاقات التي قرروا الاحتفاظ بها. :person_shrugging:

إعجابَين (2)

أرى أيضًا https://goo.gl/maps و https://goo.gl/photos/ وأتوقع ألا يتأثر كلاهما أيضًا.

إعجابَين (2)

لا أعرف. إذا كانت تعمل الآن بدون تحذير، فسأقول أنك على حق.

أنا متأكد تمامًا من أن البرنامج النصي يحاول استبدالها.

3 إعجابات

الصفحة المرتبطة في OP تقول:

لاحظ أن روابط goo.gl التي تم إنشاؤها عبر تطبيقات Google (مثل مشاركة الخرائط) ستستمر في العمل.

لذا يفترض، نعم، أنها ستستمر في العمل. خاصة إذا لم تظهر أي نوافذ اعتراضية.

هل لديك روابط محددة يمكنك نشرها؟ ربما يمكن استبدال https://goo.gl/maps/ID بـ https://maps.app.goo.gl/ID، على الرغم من أنها لا تعمل في الاتجاه الآخر.

على أي حال، ربما لا يضر استبدالها؟

إعجابَين (2)

من الصعب القول. ربما؟

أحاول ألا أقضي 5 ساعات أخرى في هذه المهمة التي تستغرق ساعتين، ولكن إليك بعض الأمثلة

https://goo.gl/maps/bFFQr8eL4F62

https://goo.gl/maps/BPCy1us5GkJQ2zMX8 يصبح

https://www.google.com/maps/place/SUZUKI%E9%91%AB%E6%BD%A4%E8%BB%8A%E6%A5%AD-%E9%B4%BB%E5%AF%B6%E5%8F%B0%E5%8C%97%E6%97%97%E8%89%A6%E5%BA%97/@25.0488943,121.5803302,16.17z/data=!4m5!3m4!1s0x3442ab9666e0cf09:0x7be03675872f9c63!8m2!3d25.051748!4d121.5809526?shorturl=1

لذلك ربما يكون من الآمن تعديل

    if match.include?('maps.app.goo.gl')

إلى شيء مثل

    if match.include?('maps.app.goo.gl') || match.include?('goo.gl/maps')

وربما إضافة صورة واحدة أيضًا.

وأنا تعلمت أيضًا أنك تحتاج إلى إعادة بناء المشاركات التي تعرض الروابط المستبدلة.

أعتقد أن مهمة “rake” مناسبة مع بعض الاختبارات، ولكنني قضيت بالفعل 3 أضعاف الساعات التي تم فوترتها لهذه المهمة.

كنت أتساءل فقط عما إذا كانت هذه متكافئة:

https://goo.gl/maps/bFFQr8eL4F62
https://maps.app.goo.gl/bFFQr8eL4F62

ولكن هذا ليس هو الحال.

كل الدلائل تشير إلى أن الأول سيستمر في العمل على أي حال :+1:

3 إعجابات

إليك واحدة
https://goo.gl/photos/NBtTJoYjhrMqRdso9
يشير اختبار سريع إلى أن جوجل لم تعد تنشئ روابط قصيرة كهذه، بل تستخدم النطاقات الفرعية بدلاً من ذلك.

إعجاب واحد (1)

لذا فمن المحتمل أنه ليس من السيئ أن يقوم البرنامج النصي بإلغاء اختصارها.

إعجاب واحد (1)

لقد رأيت bypass_bump: true وقمت بتشغيل هذا معتقدًا أنه لن يملأ عرض “الأحدث” الخاص بي بمئات التعديلات. لكنه بالتأكيد يملأ عرض “الأحدث”. يسعدني دفع هذا السعر لمحاربة تعفن الروابط، لكنني اعتقدت أنني سأقدم تنبيهًا للشخص التالي.

اتضح أن “إعادة تعيين تاريخ التحديث” يعيدها خارج عرض “الأحدث”.

إعجابَين (2)