<commit_before>module Admin
  class ImagesController < BaseController

    include ActionView::Helpers::SanitizeHelper
    include ActionView::Helpers::TextHelper

    defaults :collection_name => 'assets', :instance_name => 'asset'

    respond_to :json, :only => [:index, :create, :destroy]

    def index
      index! do |response|
        response.json do
          render :json => { :images => @assets.collect { |image| image_to_json(image) } }
        end
      end
    end

    def create
      params[:asset] = { :name => params[:name], :source => params[:file], :collection => begin_of_association_chain } if params[:file]

      a = Asset.new(params[:asset])

      begin
        a.save!
        render :json => image_to_json(a)
      rescue Exception => e
        # Rails.logger.info e.backtrace.join("\n")
        render :json => { :status => 'error' }
      end
    end

    protected

    def collection
      @assets ||= begin_of_association_chain.assets
    end

    def begin_of_association_chain
      @asset_collection ||= AssetCollection.find_or_create_internal(current_site)
    end

    def image_to_json(image)
      {
        :status       => 'success',
        :name         => truncate(image.name, :length => 15),
        :url          => image.source.url,
        :vignette_url => image.vignette_url,
        :destroy_url  => admin_image_url(image, :json)
      }
    end

  end
end<commit_msg>Include error backtrace in output<commit_after>module Admin
  class ImagesController < BaseController

    include ActionView::Helpers::SanitizeHelper
    include ActionView::Helpers::TextHelper

    defaults :collection_name => 'assets', :instance_name => 'asset'

    respond_to :json, :only => [:index, :create, :destroy]

    def index
      index! do |response|
        response.json do
          render :json => { :images => @assets.collect { |image| image_to_json(image) } }
        end
      end
    end

    def create
      params[:asset] = { :name => params[:name], :source => params[:file], :collection => begin_of_association_chain } if params[:file]

      a = Asset.new(params[:asset])

      begin
        a.save!
        render :json => image_to_json(a)
      rescue Exception => e
        # Rails.logger.info e.backtrace.join("\n")
        render :json => { :status => 'error', :backtrace => e.backtrace.join("\n") }
      end
    end

    protected

    def collection
      @assets ||= begin_of_association_chain.assets
    end

    def begin_of_association_chain
      @asset_collection ||= AssetCollection.find_or_create_internal(current_site)
    end

    def image_to_json(image)
      {
        :status       => 'success',
        :name         => truncate(image.name, :length => 15),
        :url          => image.source.url,
        :vignette_url => image.vignette_url,
        :destroy_url  => admin_image_url(image, :json)
      }
    end

  end
end
{'fraction_non_alphanumeric': 0.1196551724137931, 'fraction_numerical': 0.001379310344827586, 'mean_word_length': 2.5249088699878492, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 40, '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': '3858343', 'n_tokens_mistral': 889, 'n_tokens_neox': 862, 'n_words': 193}