<commit_before>class EbooksController < ApplicationController
  def index
    if current_user
      @ebooks = current_user.ebooks
      @title = "Home"
    else
      redirect_to root_path
    end
    @ebook = Ebook.new
  end

  def show
    @ebook = Ebook.find(params[:id])
    @pages = @ebook.pages.order("created_at ASC").paginate(:page => params[:page], :per_page => 1)
    if params[:page]
      @ebook.update_attribute(:bookmark, params[:page])
    end
    @bookmark = @ebook.bookmark
    render 'show'
  end

  def create
    @current_user = current_user
    title = EPUB::Parser.parse(params[:ebook][:attachment].path).metadata.title

    params[:ebook][:title] = title
  	@ebook = @current_user.ebooks.create(ebook_params)
    if @ebook.save
        Resque.enqueue(EbookUploader, @ebook.id, ENV['PUSHER_APP_ID'], ENV['PUSHER_KEY'], ENV['PUSHER_SECRET'])
        redirect_to ebook_path(@ebook)
    else
        render "create"
    end
  end

  def destroy
    @current_user = current_user
    @ebook = Ebook.find(params[:id])
    dir = "public/uploads/ebooks/#{@ebook.user.name.to_s.tr(' ', '_')}/#{@ebook.title.tr(' ', '_')}"

    s3 = AWS::S3.new
    bucket_name = ENV['S3_BUCKET_NAME']
    s3.buckets[bucket_name].objects.with_prefix(dir).delete_all # delete directory contents
    s3.buckets[bucket_name].objects.delete(dir) # delete directory

    @ebook.destroy
    redirect_to ebooks_path, notice: "#{@ebook.title} deleted!"
  end

  def about
    @title = "About"
    render "about"
  end

  def contact
    @title = "Contact"
    render "contact"
  end

	private
   	 def ebook_params
    	  params.require(:ebook).permit(:title, :attachment)
   	 end
end<commit_msg>edited delete message<commit_after>class EbooksController < ApplicationController
  def index
    if current_user
      @ebooks = current_user.ebooks
      @title = "Home"
    else
      redirect_to root_path
    end
    @ebook = Ebook.new
  end

  def show
    @ebook = Ebook.find(params[:id])
    @pages = @ebook.pages.order("created_at ASC").paginate(:page => params[:page], :per_page => 1)
    if params[:page]
      @ebook.update_attribute(:bookmark, params[:page])
    end
    @bookmark = @ebook.bookmark
    render 'show'
  end

  def create
    @current_user = current_user
    title = EPUB::Parser.parse(params[:ebook][:attachment].path).metadata.title

    params[:ebook][:title] = title
  	@ebook = @current_user.ebooks.create(ebook_params)
    if @ebook.save
        Resque.enqueue(EbookUploader, @ebook.id, ENV['PUSHER_APP_ID'], ENV['PUSHER_KEY'], ENV['PUSHER_SECRET'])
        redirect_to ebook_path(@ebook)
    else
        render "create"
    end
  end

  def destroy
    @current_user = current_user
    @ebook = Ebook.find(params[:id])
    dir = "public/uploads/ebooks/#{@ebook.user.name.to_s.tr(' ', '_')}/#{@ebook.title.tr(' ', '_')}"

    s3 = AWS::S3.new
    bucket_name = ENV['S3_BUCKET_NAME']
    s3.buckets[bucket_name].objects.with_prefix(dir).delete_all # delete directory contents
    s3.buckets[bucket_name].objects.delete(dir) # delete directory

    @ebook.destroy
    redirect_to ebooks_path, notice: "'#{@ebook.title}' deleted!"
  end

  def about
    @title = "About"
    render "about"
  end

  def contact
    @title = "Contact"
    render "contact"
  end

	private
   	 def ebook_params
    	  params.require(:ebook).permit(:title, :attachment)
   	 end
end
{'fraction_non_alphanumeric': 0.1343990526939017, 'fraction_numerical': 0.003552397868561279, 'mean_word_length': 3.2935196950444725, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '5378170', 'n_tokens_mistral': 1176, 'n_tokens_neox': 1155, 'n_words': 221}