Skip to content

Commit

Permalink
Fix indendation in controllers, models and .gitmodules
Browse files Browse the repository at this point in the history
  • Loading branch information
Darep committed Jul 6, 2014
1 parent a651c02 commit 3fcd434
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 211 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "public"]
path = public
url=git://github.com/Darep/Beatstream-client.git
url=git://github.com/Darep/Beatstream-client.git
25 changes: 13 additions & 12 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
class ApplicationController < ActionController::Base
before_filter :authorize
before_filter :redirect_to_https
protect_from_forgery
before_filter :authorize
before_filter :redirect_to_https
protect_from_forgery

protected
protected

def authorize
unless User.find_by_id(session[:user_id])
redirect_to login_url
end
end
def authorize
unless User.find_by_id(session[:user_id])
redirect_to login_url
end
end

def redirect_to_https
redirect_to :protocol => "https://" unless (request.ssl? || request.local?)
end

def redirect_to_https
redirect_to :protocol => "https://" unless (request.ssl? || request.local?)
end
end
12 changes: 6 additions & 6 deletions app/controllers/playlists_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class PlaylistsController < ApplicationController
def index
# TODO: return a list of users' playlists
end
def index
# TODO: return a list of users' playlists
end

def new
# TODO: this
end
def new
# TODO: this
end
end
34 changes: 17 additions & 17 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
class SessionsController < ApplicationController
skip_before_filter :authorize
skip_before_filter :authorize

def new
render :layout => 'login'
end
def new
render :layout => 'login'
end

def create
if params[:password] && user = User.authenticate(params[:username], params[:password])
session[:username] = user.username
session[:user_id] = user.id
redirect_to root_url
else
redirect_to login_url, :alert => "Oops! Now that wasn't right, was it?"
end
def create
if params[:password] && user = User.authenticate(params[:username], params[:password])
session[:username] = user.username
session[:user_id] = user.id
redirect_to root_url
else
redirect_to login_url, :alert => "Oops! Now that wasn't right, was it?"
end
end

def destroy
session[:username] = nil
session[:user_id] = nil
redirect_to login_url
end
def destroy
session[:username] = nil
session[:user_id] = nil
redirect_to login_url
end
end
63 changes: 31 additions & 32 deletions app/controllers/settings_controller.rb
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
class SettingsController < ApplicationController

def index
@user = User.find(session[:user_id])
render :layout => false
end

def save
@user = User.find(session[:user_id])
if @user.update_attributes(params[:user])
respond_to do |format|
format.html { redirect_to :action => 'index' }
format.json { render :nothing => true }
end
else
render :action => 'index', :layout => false
end
def index
@user = User.find(session[:user_id])
render :layout => false
end

def save
@user = User.find(session[:user_id])
if @user.update_attributes(params[:user])
respond_to do |format|
format.html { redirect_to :action => 'index' }
format.json { render :nothing => true }
end
else
render :action => 'index', :layout => false
end
end

def lastfm_callback
token = params[:token]
def lastfm_callback
token = params[:token]

lastfm_session = Rockstar::Auth.new.session(token)
lastfm_session = Rockstar::Auth.new.session(token)

@user = User.find(session[:user_id])
@user.update_attributes(:lastfm_session_key => lastfm_session.key, :lastfm_username => lastfm_session.username)
@user = User.find(session[:user_id])
@user.update_attributes(:lastfm_session_key => lastfm_session.key, :lastfm_username => lastfm_session.username)

respond_to do |format|
format.html { redirect_to :action => 'index' }
format.json { render :nothing => true }
end
respond_to do |format|
format.html { redirect_to :action => 'index' }
format.json { render :nothing => true }
end
end

def lastfm_disconnect
@user = User.find(session[:user_id])
@user.update_attributes(:lastfm_session_key => nil, :lastfm_username => nil)
def lastfm_disconnect
@user = User.find(session[:user_id])
@user.update_attributes(:lastfm_session_key => nil, :lastfm_username => nil)

respond_to do |format|
format.html { redirect_to :action => 'index' }
format.json { render :nothing => true }
end
respond_to do |format|
format.html { redirect_to :action => 'index' }
format.json { render :nothing => true }
end
end
end
142 changes: 71 additions & 71 deletions app/controllers/songs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,101 +8,101 @@

class SongsController < ApplicationController

def index
songs_json = '';

if params[:refresh]
Rails.logger.info 'Forced song list refresh'
refresh(songs_json)
else
begin
f = File.open(SONGS_JSON_FILE, 'r')
Rails.logger.info 'Songs JSON modified: ' + f.mtime.to_s
songs_json = f.read
rescue Errno::ENOENT
Rails.logger.info 'Songs JSON file not found --> refreshing songs list'
refresh(songs_json)
end
end

render :text => songs_json
def index
songs_json = '';

if params[:refresh]
Rails.logger.info 'Forced song list refresh'
refresh(songs_json)
else
begin
f = File.open(SONGS_JSON_FILE, 'r')
Rails.logger.info 'Songs JSON modified: ' + f.mtime.to_s
songs_json = f.read
rescue Errno::ENOENT
Rails.logger.info 'Songs JSON file not found --> refreshing songs list'
refresh(songs_json)
end
end

def play
filepath = MUSIC_PATH + params[:file]
render :text => songs_json
end

response.content_type = Mime::Type.lookup_by_extension("mp3")
def play
filepath = MUSIC_PATH + params[:file]

render :text => File.open(filepath, 'rb') { |f| f.read }
#send_file filepath, :type => 'audio/mpeg'
end
response.content_type = Mime::Type.lookup_by_extension("mp3")

def now_playing
expires_now # don't cache
render :text => File.open(filepath, 'rb') { |f| f.read }
#send_file filepath, :type => 'audio/mpeg'
end

artist = params[:artist]
title = params[:title]
def now_playing
expires_now # don't cache

@user = User.find(session[:user_id])
artist = params[:artist]
title = params[:title]

if @user != nil && @user.lastfm_session_key != nil
Rails.logger.info 'Update Now Playing to "' + artist + ' - ' + title + '" for user ' + @user.username
@user = User.find(session[:user_id])

track = Rockstar::Track.new(artist, title)
track.updateNowPlaying(Time.now, @user.lastfm_session_key)
end
if @user != nil && @user.lastfm_session_key != nil
Rails.logger.info 'Update Now Playing to "' + artist + ' - ' + title + '" for user ' + @user.username

respond_to do |format|
format.json { render :nothing => true }
end
track = Rockstar::Track.new(artist, title)
track.updateNowPlaying(Time.now, @user.lastfm_session_key)
end

def scrobble
expires_now # don't cache
respond_to do |format|
format.json { render :nothing => true }
end
end

artist = params[:artist]
title = params[:title]
def scrobble
expires_now # don't cache

@user = User.find(session[:user_id])
artist = params[:artist]
title = params[:title]

if @user != nil && @user.lastfm_session_key != nil
Rails.logger.info 'Scrobbling track "' + artist + ' - ' + title + '" for user ' + @user.username
@user = User.find(session[:user_id])

track = Rockstar::Track.new(artist, title)
track.scrobble(Time.now, @user.lastfm_session_key)
end
if @user != nil && @user.lastfm_session_key != nil
Rails.logger.info 'Scrobbling track "' + artist + ' - ' + title + '" for user ' + @user.username

respond_to do |format|
format.json { render :nothing => true }
end
track = Rockstar::Track.new(artist, title)
track.scrobble(Time.now, @user.lastfm_session_key)
end

respond_to do |format|
format.json { render :nothing => true }
end
end

private
private

def refresh(songs_as_json)
songs = []

Find.find(MUSIC_PATH) do |file|
if File.directory?(file) || file !~ /.*\.mp3$/i || file =~ /^\./
#Rails.logger.info 'Skipping file: ' + file
next
end

begin
mp3 = Song.new(file, songs.length)
songs.push(mp3)
rescue Exception => e
Rails.logger.info e
Rails.logger.info 'Failed to load MP3: ' + file
# TODO: collect the broken mp3s into a separate array
# TODO: count the broken mp3s
end
songs = []

Find.find(MUSIC_PATH) do |file|
if File.directory?(file) || file !~ /.*\.mp3$/i || file =~ /^\./
#Rails.logger.info 'Skipping file: ' + file
next
end

begin
mp3 = Song.new(file, songs.length)
songs.push(mp3)
rescue Exception => e
Rails.logger.info e
Rails.logger.info 'Failed to load MP3: ' + file
# TODO: collect the broken mp3s into a separate array
# TODO: count the broken mp3s
end
end

songs = songs.sort_by { |song| song.to_natural_sort_string }
songs = songs.sort_by { |song| song.to_natural_sort_string }

songs_as_json = songs.to_json
File.open(SONGS_JSON_FILE, 'w') { |f| f.write(songs_as_json) }
songs_as_json = songs.to_json
File.open(SONGS_JSON_FILE, 'w') { |f| f.write(songs_as_json) }
end

end
8 changes: 4 additions & 4 deletions app/helpers/settings_helper.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'rockstar'

module SettingsHelper
def lastfm_token_url
auth = Rockstar::Auth.new
auth.token
end
def lastfm_token_url
auth = Rockstar::Auth.new
auth.token
end
end
Loading

0 comments on commit 3fcd434

Please sign in to comment.