Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 39fcde3a03b354a32441c56b1795219cef378c8b @sudara committed Mar 11, 2008
Showing 1,503 changed files with 110,280 additions and 0 deletions.
@@ -0,0 +1,15 @@
+*.log
+db/schema.rb
+db/schema.sql
+config/deploy.rb
+config/database.yml
+config/amazon_s3.yml
+config/defensio.yml
+config/facebooker.yml
+config/basecamp.yml
+*.sql
+public/images/pretty_text/*.*
+log/*.log
+.DS_Store
+*.tmp
+public/stylesheets/*.css
@@ -0,0 +1,3 @@
+load 'deploy' if respond_to?(:namespace) # cap2 differentiator
+Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
+load 'config/deploy'
@@ -0,0 +1,38 @@
+= The future is bright
+
+The future of music distribution online, brought to you by Sudara
+
+Amazing: We now live in a world where 1 person, in his spare time can provide limitless distribution for hundreds of artists, thousands of songs, millions of copies. Truly, we are at the beginning of a revolution in music making.
+
+I invite you to join me in moving good music away from companies looking (still) to profit from musicians and help me to create the best damn online home for DIY / independent / online-savy musicians.
+
+== Want to join forces?
+
+First of all, talk to me. You can send me electronic mail. Sudara...at...nameofthisproject....com
+
+The nameofthisproject and the production site is:
+
+http://alonetone.com
+
+Here is the codebase, which is open source and open development.
+
+== Set it up
+
+You'll need to setup 5 config files for it to run flawlessly:
+
+ database.yml
+ amazon_s3.yml (you can always ignore this and set Asset and Pic to use the filesysem)
+ basecamp.yml (for todo list, you don't need it unless you want pages/todo)
+ defensio.yml (spam protection)
+ facebooker.yml (for facebook app)
+
+You'll need some gems, at least:
+ rmagick
+ haml
+ facebooker
+ ruby-mp3info
+ mocha (for rspec)
+ googlecharts
+ aws-s3
+
+If I were you, I would email me.
@@ -0,0 +1,10 @@
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require(File.join(File.dirname(__FILE__), 'config', 'boot'))
+
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+require 'tasks/rails'
@@ -0,0 +1,141 @@
+class ApplicationController < ActionController::Base
+ helper :all # include all helpers, all the time
+
+ protect_from_forgery :secret => 'f90bac24ac12962052d00bfc2bd34ef2'
+
+ include AuthenticatedSystem
+ include ExceptionLoggable
+ before_filter :set_tab, :ie6, :is_sudo
+ before_filter :ie6
+ before_filter :login_by_token, :display_news
+ before_filter :set_page_title
+ before_filter :currently_online, :prep_bugaboo
+ before_filter :update_last_seen_at, :only => [:index, :show]
+ before_filter :set_latest_update_title
+
+ # let ActionView have a taste of our authentication
+ helper_method :current_user, :logged_in?, :admin?, :last_active
+
+
+ rescue_from ActiveRecord::RecordNotFound, :with => :show_error
+ rescue_from NoMethodError, :with => :show_error
+
+ # all errors end up here
+ def show_error(exception)
+ if RAILS_ENV == 'production' && admin?
+ flash[:error] = "#{exception.message}"
+ redirect_to_default
+ elsif RAILS_ENV == 'production'
+ if facebook?
+ flash[:error] = "Alonetone made a boo boo: <br/> #{exception.message}"
+ render :partial => 'facebook_accounts/error', :layout => true
+ else
+ # show something decent for visitors
+ flash[:error] = "Whups! That didn't work out. We've logged it, but feel free to let us know (bottom right) if something is giving you trouble"
+ redirect_to_default
+ end
+ else
+ # let me see what's wrong in dev mode.
+ raise exception
+ end
+ end
+
+
+
+ protected
+ def facebook?
+ !(params[:fb_sig] == nil)
+ end
+
+
+ def sudo_to(destination_user)
+ return false unless session[:sudo] || current_user.admin?
+ if session[:sudo] && destination_user.admin?
+ logger.warn('coming out of sudo to admin account')
+ session[:sudo] = nil
+ @sudo = nil
+ else
+ session[:sudo] = true
+ logger.warn("SUDO: #{current_user.name} is sudoing to #{destination_user.name}")
+ @sudo = true
+ end
+ self.current_user = destination_user
+ logger.warn("SUDO: #{current_user.name}")
+ true
+ end
+
+ def ie6
+ @ie6 = true if request.env['HTTP_USER_AGENT'] and request.env['HTTP_USER_AGENT'].include? "MSIE 6.0"
+ end
+
+ def currently_online
+ @online = User.currently_online
+ end
+
+ def find_user
+ @user = (params[:login] || params[:id])? User.find_by_login(params[:login] || params[:id]) : current_user
+ end
+
+ def find_asset
+ @asset = @user.assets.find_by_permalink(params[:permalink] || params[:id])
+ @asset = @user.assets.find(params[:id]) if !@asset && params[:id]
+ end
+
+ def find_playlists
+ @playlist = @user.playlists.find_by_permalink(params[:permalink] || params[:id], :include =>[:tracks => :asset])
+ @playlist = @user.playlists.find(params[:id], :include =>[:tracks => :asset]) if !@playlist && params[:id]
+ end
+
+ def authorized?
+ # by default, users can hit every action if it involves their user, and it's not about deleting things.
+ admin_or_owner
+ end
+
+ # authorization tricks
+
+ def admin_or_owner(record=current_user)
+ admin? || (!%w(destroy admin edit update).include?(action_name) && (params[:login].nil? || params[:login] == record.login))
+ end
+
+ def admin_or_owner_with_delete(record=current_user)
+ admin? || (params[:login].nil? || params[:login] == record.login)
+ end
+
+ def set_page_title
+ @page_title = "alonetone - a damn fine home for musicians. Upload mp3s, host and share your music."
+ end
+
+
+ def render_text(text)
+ render :text => text
+ end
+
+ def set_tab
+ @tab = ''
+ end
+
+ def prep_bugaboo
+ @user_report = UserReport.new(:user => @current_user || nil, :params => params)
+ end
+
+ def display_news
+ return unless logged_in?
+ @display_news = true if session[:last_active] && (session[:last_active] < Update.find(:first, :order => 'created_at DESC').created_at)
+ end
+
+ def is_sudo
+ @sudo = session[:sudo]
+ end
+
+ # override default behavior to ensure that 'log in to app' returns user somewhere useful
+ def application_is_not_installed_by_facebook_user
+ redirect_to session[:facebook_session].install_url(:next => "#{request.request_uri}")
+ end
+
+ def set_latest_update_title
+ @latest_update = Update.find(:all, :order => 'created_at DESC', :limit => 1 ).first
+ end
+
+ private
+
+end
@@ -0,0 +1,170 @@
+class AssetsController < ApplicationController
+ before_filter :find_user
+ before_filter :find_asset, :only => [:show, :edit, :update, :destroy]
+
+ # we check to see if the current_user is authorized based on the asset.user
+ before_filter :login_required, :except => [:index, :show, :latest]
+ before_filter :find_referer, :only => :show
+
+ rescue_from NoMethodError, :with => :latest
+
+ # GET /assets
+ # GET /assets.xml
+ def index
+ @page_title = @user.name + "'s uploaded music on alonetone"
+ @assets = @user.assets.paginate(:all, :order => 'created_at DESC', :per_page => 60, :page => params[:page])
+ respond_to do |format|
+ format.html # index.rhtml
+ format.xml { render :xml => @assets.to_xml }
+ format.rss { render :xml => @assets.to_xml }
+ format.js do render :update do |page|
+ page.replace 'stash', :partial => "assets"
+ end
+ end
+ end
+ end
+
+ # GET /assets/1
+ # GET /assets/1.xml
+ def show
+ respond_to do |format|
+ format.rss
+ format.html do
+ @page_title = "#{@asset.title} by #{@user.name} on alonetone"
+ @assets = [@asset]
+ @listens = @asset.listens.find(:all)
+ @comments = @asset.comments.find_all_by_spam(false)
+ end
+ format.mp3 do
+ register_listen
+ redirect_to @asset.public_mp3
+ end
+ end
+ end
+
+ # aka home page
+ def latest
+ limit = (params[:latest] && params[:latest].to_i < 50) ? params[:latest] : 5
+ @page_title = "Latest #{limit} uploaded mp3s on alonetone" if params[:latest]
+ @assets = Asset.latest(limit)
+ @popular = Asset.most_popular(limit)
+ @playlists = Playlist.latest(6)
+ respond_to do |wants|
+ wants.html
+ wants.rss
+ end
+ end
+
+ def top
+ top = (params[:top] && params[:top].to_i < 50) ? params[:top] : 20
+ @page_title = "Top #{top} tracks on alonetone"
+ @popular = Asset.most_popular(top)
+ respond_to do |wants|
+ wants.html { render :action => 'latest'}
+ wants.rss
+ end
+ end
+
+ def search
+ @assets = Asset.find(:all, :conditions => [ "assets.filename LIKE ? OR assets.title LIKE ?", "%#{params[:search]}%","%#{params[:search]}%"], :limit => 10)
+ render :partial => 'results', :layout => false
+ end
+
+ # GET /assets/new
+ def new
+ @tab = 'upload' if current_user == @user
+ @asset = Asset.new
+ end
+
+ # GET /assets/1;edit
+ def edit
+ end
+
+ # POST /assets
+ # POST /assets.xml
+ def create
+ #collect and prepare
+ @assets = []
+ params[:asset] ||= {}
+ params[:asset_data] ||= []
+ params[:asset].delete(:title) if params[:asset_data].size > 1
+
+ params[:asset_data].each do |file|
+ unless file.is_a?(String)
+ Asset.extract_mp3s(file) do |valid_mp3|
+ @assets << current_user.assets.create(params[:asset].merge(:uploaded_data => valid_mp3))
+ end
+ end
+ end
+ flashes = ''
+ good = false
+ @assets.each do |asset|
+ # TODO: find a non-hackish way to ensure content_types are only mp3s at this point
+ # The problem is a zip can contain a zip, which passes validation
+ # Furthermore, if there is an issue with the zip, the rescue in the Asset model will hand the file back
+ # Butt ugly, my friends.
+ if !asset.new_record?
+ flashes += "#{CGI.escapeHTML asset.filename} uploaded!<br/>"
+ good = true
+ else
+ errors = asset.errors.collect{|attr, msg| msg }
+ flashes += "'#{CGI.escapeHTML asset.filename}' failed to upload: <br/>#{errors}<br/>"
+ end
+ end
+ if good
+ flash[:ok] = flashes
+ redirect_to user_tracks_path(current_user)
+ else
+ flash[:error] = flashes
+ redirect_to new_user_track_path(current_user)
+ end
+ end
+
+ # PUT /assets/1
+ # PUT /assets/1.xml
+ def update
+ respond_to do |format|
+ if @asset.update_attributes(params[:asset])
+ flash[:ok] = 'Track updated!'
+ format.html { redirect_to edit_user_track_url(current_user, @asset) }
+ format.xml { head :ok }
+ else
+ format.html { render :action => "edit" }
+ format.xml { render :xml => @asset.errors.to_xml }
+ end
+ end
+ end
+
+ # DELETE /assets/1
+ # DELETE /assets/1.xml
+ def destroy
+ @asset.destroy
+ flash[:ok] = 'We threw the puppy away. No one can listen to it again (unless you reupload it, of course ;)'
+ respond_to do |format|
+ format.html { redirect_to user_tracks_url(current_user) }
+ format.xml { head :ok }
+ end
+ end
+
+ protected
+
+ def find_referer
+ case params[:referer]
+ when 'itunes' then @referer = 'itunes'
+ when 'download' then @referer = 'download'
+ when 'home' then @referer = 'home'
+ when 'facebook' then @referer = 'facebook'
+ when nil
+ @referer = (request.env['HTTP_REFERER'] && !request.env['HTTP_REFERER'].empty?) ? request.env['HTTP_REFERER'] : 'alonetone'
+ end
+ end
+
+ def authorized?
+ # admin or the owner of the asset can edit/update/delete
+ admin? || (params[:permalink].nil? || (current_user != :false && @asset.user_id.to_s == current_user.id.to_s))
+ end
+
+ def register_listen
+ @asset.listens.create(:listener => (current_user || nil), :track_owner=> @asset.user, :source => @referer)
+ end
+end
Oops, something went wrong. Retry.

0 comments on commit 39fcde3

Please sign in to comment.