<commit_before>require 'active_support/concern'
require 'bitly'

module ProjectMediaEmbed
  extend ActiveSupport::Concern

  included do
    after_update :clear_caches
  end

  def oembed_url(format = '')
    format = ".#{format}" unless format.blank?
    url = CONFIG['checkdesk_base_url'] + '/api/project_medias/' + self.id.to_s + '/oembed' + format
    request = RequestStore[:request]
    url += '?' + request.query_string if request.present? && !request.query_string.blank?
    url
  end

  def embed_url(shorten = true)
    url = CONFIG['pender_url'] + '/api/medias.html?url=' + self.full_url.to_s
    return url unless shorten && CONFIG['bitly_key']
    Rails.cache.fetch("shorten-url-#{self.id}") do
      # Shorten using Bit.ly and return the shortened URL
      begin
        bitly = Bitly.client.shorten(url)
        bitly.short_url
      rescue StandardError => e
        Rails.logger.error "[ProjectMedia] Exception when generating Bitly link for #{url}: #{e.message}"
        url
      end
    end
  end

  def embed_analysis
    item_show_analysis_defined = (begin self.get_annotations('memebuster').last.load.get_field('memebuster_show_analysis') rescue nil end)
    item_show_analysis = (begin self.get_annotations('memebuster').last.load.get_field_value('memebuster_show_analysis') rescue false end)
    if (item_show_analysis_defined && item_show_analysis) || (!item_show_analysis_defined && self.team.get_embed_analysis)
      begin self.get_annotations('analysis').last.load.get_field_value('analysis_text').to_s rescue nil end<commit_msg>Fixing Bit.ly URL cache key<commit_after>require 'active_support/concern'
require 'bitly'

module ProjectMediaEmbed
  extend ActiveSupport::Concern

  included do
    after_update :clear_caches
  end

  def oembed_url(format = '')
    format = ".#{format}" unless format.blank?
    url = CONFIG['checkdesk_base_url'] + '/api/project_medias/' + self.id.to_s + '/oembed' + format
    request = RequestStore[:request]
    url += '?' + request.query_string if request.present? && !request.query_string.blank?
    url
  end

  def embed_url(shorten = true)
    url = CONFIG['pender_url'] + '/api/medias.html?url=' + self.full_url.to_s
    return url unless shorten && CONFIG['bitly_key']
    Rails.cache.fetch("shorten-url-#{self.full_url}") do
      # Shorten using Bit.ly and return the shortened URL
      begin
        bitly = Bitly.client.shorten(url)
        bitly.short_url
      rescue StandardError => e
        Rails.logger.error "[ProjectMedia] Exception when generating Bitly link for #{url}: #{e.message}"
        url
      end
    end
  end

  def embed_analysis
    item_show_analysis_defined = (begin self.get_annotations('memebuster').last.load.get_field('memebuster_show_analysis') rescue nil end)
    item_show_analysis = (begin self.get_annotations('memebuster').last.load.get_field_value('memebuster_show_analysis') rescue false end)
    if (item_show_analysis_defined && item_show_analysis) || (!item_show_analysis_defined && self.team.get_embed_analysis)
      begin self.get_annotations('analysis').last.load.get_field_value('analysis_text').to_s rescue nil end
{'fraction_non_alphanumeric': 0.11496815286624204, 'fraction_numerical': 0.0, 'mean_word_length': 4.08252427184466, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1548957', 'n_tokens_mistral': 988, 'n_tokens_neox': 979, 'n_words': 205}