<commit_before>class ChannelsController < ApplicationController
  
  # layout "fu3"
  layout 'application'

  before_filter :login_required

  respond_to :html, :json
  
  def index
    if current_user && current_user.password_hash.blank?
      redirect_to password_user_path(:id => current_user.id) and return
    end
    @recent_channels = Channel.recent_channels(current_user, (params[:page] || 1).to_i)
    @recent_channels.each { |c| c.current_user = current_user }
    respond_with @recent_channels
  end
  
  def show
    if params[:id] == "all"
      all
    else
      posts(false)
      respond_with @channel
    end
  end

  def posts(respond=true)
    @channel = Channel.find(params[:id], :include => :posts)
    @channel.visit(current_user)
    @post = Post.new
    if respond
      respond_with @channel.posts.all(:include => :user)
    end
  end

  def all
    @channels = Channel.all_channels(current_user, (params[:page] || 1).to_i)
    render "all"
  end
  
  def new
    @channel = Channel.new
  end
  
  def create
    @channel = Channel.create(params[:channel].merge(:user_id => current_user.id))
    
    redirect_to channel_path(@channel)
  end
  
  def search
    @query = params[:search].to_s
    if @query =~ /^title:(.*)$/
      @search = Channel.search($1, :per_page => 25, :page => (params[:page] || 1).to_i, :star => true)
    else
      @search = ThinkingSphinx.search(@query, :classes => [Channel, Post], :per_page => 25, :page => (params[:page] || 1).to_i, :star => true)
    end
    
    respond_to do |format|
      format.html
      format.json { render :json => @search.map { |r| {:title => r.title, :display_title => r.excerpts.title, :id => r.id} } }
    end
  end
  
end
<commit_msg>Create channel via json<commit_after>class ChannelsController < ApplicationController
  
  # layout "fu3"
  layout 'application'

  before_filter :login_required

  respond_to :html, :json
  
  def index
    if current_user && current_user.password_hash.blank?
      redirect_to password_user_path(:id => current_user.id) and return
    end
    @recent_channels = Channel.recent_channels(current_user, (params[:page] || 1).to_i)
    @recent_channels.each { |c| c.current_user = current_user }
    respond_with @recent_channels
  end
  
  def show
    if params[:id] == "all"
      all
    else
      posts(false)
      respond_with @channel
    end
  end

  def posts(respond=true)
    @channel = Channel.find(params[:id], :include => :posts)
    @channel.visit(current_user)
    @post = Post.new
    if respond
      respond_with @channel.posts.all(:include => :user)
    end
  end

  def all
    @channels = Channel.all_channels(current_user, (params[:page] || 1).to_i)
    render "all"
  end
  
  def new
    @channel = Channel.new
  end
  
  def create
    @channel = Channel.create(params[:channel].merge(:user_id => current_user.id))

    respond_with @channel do |f|
      f.html { redirect_to channel_path(@channel) }
      j.json { render :json => @channel }
    end
  end
  
  def search
    @query = params[:search].to_s
    if @query =~ /^title:(.*)$/
      @search = Channel.search($1, :per_page => 25, :page => (params[:page] || 1).to_i, :star => true)
    else
      @search = ThinkingSphinx.search(@query, :classes => [Channel, Post], :per_page => 25, :page => (params[:page] || 1).to_i, :star => true)
    end
    
    respond_to do |format|
      format.html
      format.json { render :json => @search.map { |r| {:title => r.title, :display_title => r.excerpts.title, :id => r.id} } }
    end
  end
  
end

{'fraction_non_alphanumeric': 0.13613303269447577, 'fraction_numerical': 0.005636978579481398, 'mean_word_length': 3.010169491525424, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 34, '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': '959868', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1191, 'n_words': 277}