<commit_before>class AssetController < ApplicationController
  prepend_before_filter :fetch_asset

  def show
    thumb = nil
    unless @asset.filename == "#{params[:filename]}.#{params[:format]}"
      file = @asset.thumbnails.detect {|a| a.filename == "#{params[:filename]}.#{params[:format]}"}
      thumb = file.thumbnail if file
    end
    send_file(@asset.full_filename(thumb), :type => @asset.content_type, :disposition => (@asset.image? ? 'inline' : 'attachment'))
  end

  protected

  def fetch_asset
    @asset = Asset.find(params[:id], :include => ['pages', 'thumbnails']) if params[:id]
  end

  def authorized?
    if @asset
      current_user.may?(:read, @asset.page)
    else
      false
    end
  end

  def access_denied<commit_msg>regenerate the symlink if asset should be public but it's not and we don't have permission<commit_after>class AssetController < ApplicationController
  prepend_before_filter :fetch_asset

  def show
    thumb = nil
    unless @asset.filename == "#{params[:filename]}.#{params[:format]}"
      file = @asset.thumbnails.detect {|a| a.filename == "#{params[:filename]}.#{params[:format]}"}
      thumb = file.thumbnail if file
    end
    send_file(@asset.full_filename(thumb), :type => @asset.content_type, :disposition => (@asset.image? ? 'inline' : 'attachment'))
  end

  protected

  def fetch_asset
    @asset = Asset.find(params[:id], :include => ['pages', 'thumbnails']) if params[:id]
    if @asset.is_public? && !logged_in?
      @asset.update_access 
      redirect_to and return false
    end
  end

  def authorized?
    if @asset
      current_user.may?(:read, @asset.page)
    else
      false
    end
  end

  def access_denied
{'fraction_non_alphanumeric': 0.1388888888888889, 'fraction_numerical': 0.0, 'mean_word_length': 3.6897506925207755, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '1668509', 'n_tokens_mistral': 540, 'n_tokens_neox': 524, 'n_words': 129}