<commit_before>class AjaxController < ApplicationController
  def scrobble
    artist = params[:artist]
    track = params[:track]
    result = nil
    
    if current_user.lastfm_token and current_user.scrobble_mode === true# and Rails.env.production?
      t = LastfmTrack.new(track, artist, @lastfm)
      
      result = t.scrobble
    end
    
    render :json => result
  end
  
  def activity
    artist = params[:artist]
    track = params[:track]
    queue = Queue.new
    
    video_url = 'http://www.molamp.net/artists/' + artist.gsub(' ', '+') + '/_/' + track.gsub(' ', '+')
    
    if current_user.facebook_token and current_user.activity_mode === true and Rails.env.production?
      begin
        Thread.new {
          queue << @facebook.put_connections('me', 'video.watches', :video => video_url)
        }
      rescue
        #queue << nil
      end
    end
    
    render :json => queue.pop 
  end
  
  def activity_delete
    id = params[:id]
    result = nil
    
    if current_user.facebook_token and current_user.activity_mode === true
      begin
        result = @facebook.delete_object(id)
      rescue<commit_msg>heroku won't allows anything related to queues unless paid for a worker<commit_after>class AjaxController < ApplicationController
  def scrobble
    artist = params[:artist]
    track = params[:track]
    result = nil
    
    if current_user.lastfm_token and current_user.scrobble_mode === true# and Rails.env.production?
      t = LastfmTrack.new(track, artist, @lastfm)
      
      result = t.scrobble
    end
    
    render :json => result
  end
  
  def activity
    artist = params[:artist]
    track = params[:track]
    thread = nil
    
    video_url = 'http://www.molamp.net/artists/' + artist.gsub(' ', '+') + '/_/' + track.gsub(' ', '+')
    
    if current_user.facebook_token and current_user.activity_mode === true and Rails.env.production?
        thread = Thread.new {
          Thread.current[:output] = @facebook.put_connections('me', 'video.watches', :video => video_url)
        }
    end
    
    sleep(3);
    
    result = thread ? thread[:output] : nil
    
    render :json => result 
  end
  
  def activity_delete
    id = params[:id]
    result = nil
    
    if current_user.facebook_token and current_user.activity_mode === true
      begin
        result = @facebook.delete_object(id)
      rescue
{'fraction_non_alphanumeric': 0.11157894736842106, 'fraction_numerical': 0.0004210526315789474, 'mean_word_length': 2.4686131386861314, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2535707', 'n_tokens_mistral': 745, 'n_tokens_neox': 732, 'n_words': 169}