From 4db2d4f19f95b0b5bb7ba9dcdc7ea72c65760223 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 10 Nov 2009 16:03:17 -0800 Subject: initial commit --- .../app/controllers/application_controller.rb | 3 ++ .../app/controllers/files_controller.rb | 39 ++++++++++++++ .../app/helpers/application_helper.rb | 3 ++ examples/rails_app-2.3.4/app/models/upr_status.rb | 35 +++++++++++++ .../rails_app-2.3.4/app/views/files/index.html.erb | 60 ++++++++++++++++++++++ 5 files changed, 140 insertions(+) create mode 100644 examples/rails_app-2.3.4/app/controllers/application_controller.rb create mode 100644 examples/rails_app-2.3.4/app/controllers/files_controller.rb create mode 100644 examples/rails_app-2.3.4/app/helpers/application_helper.rb create mode 100644 examples/rails_app-2.3.4/app/models/upr_status.rb create mode 100644 examples/rails_app-2.3.4/app/views/files/index.html.erb (limited to 'examples/rails_app-2.3.4/app') diff --git a/examples/rails_app-2.3.4/app/controllers/application_controller.rb b/examples/rails_app-2.3.4/app/controllers/application_controller.rb new file mode 100644 index 0000000..11df5d1 --- /dev/null +++ b/examples/rails_app-2.3.4/app/controllers/application_controller.rb @@ -0,0 +1,3 @@ +class ApplicationController < ActionController::Base + helper :all # include all helpers, all the time +end diff --git a/examples/rails_app-2.3.4/app/controllers/files_controller.rb b/examples/rails_app-2.3.4/app/controllers/files_controller.rb new file mode 100644 index 0000000..3d82107 --- /dev/null +++ b/examples/rails_app-2.3.4/app/controllers/files_controller.rb @@ -0,0 +1,39 @@ +require 'digest/sha1' + +class FilesController < ApplicationController + defined?($upr) or before_filter do + # grab the backend in case we forget to set it (or if we're using DRb) + defined?($upr) or ObjectSpace.each_object(Upr::InputWrapper) do |x| + $upr ||= x.backend + end + end + + def index + end + + def status + tmp = $upr.read(params[:upload_id]).inspect + render :text => "#{Rack::Utils.escape_html(tmp)}\n" + end + + def progress + render :update do |page| + status = $upr.read(params[:upload_id]) and + page.upload_progress.update(status.length, status.seen) + end + end + + def upload + file = params[:data] + digest = Digest::SHA1.new + if buf = file.read(16384) + begin + digest.update(buf) + end while file.read(16384, buf) + end + render :text => "params: #{Rack::Utils.escape_html(params.inspect)}.\n" \ + "sha1: #{digest.hexdigest}\n" \ + '' + end +end diff --git a/examples/rails_app-2.3.4/app/helpers/application_helper.rb b/examples/rails_app-2.3.4/app/helpers/application_helper.rb new file mode 100644 index 0000000..22a7940 --- /dev/null +++ b/examples/rails_app-2.3.4/app/helpers/application_helper.rb @@ -0,0 +1,3 @@ +# Methods added to this helper will be available to all templates in the application. +module ApplicationHelper +end diff --git a/examples/rails_app-2.3.4/app/models/upr_status.rb b/examples/rails_app-2.3.4/app/models/upr_status.rb new file mode 100644 index 0000000..81031c2 --- /dev/null +++ b/examples/rails_app-2.3.4/app/models/upr_status.rb @@ -0,0 +1,35 @@ +class UprStatus < ActiveRecord::Base + cattr_accessor :gc_cutoff + @@gc_cutoff = 10 + + class << self + def read(upid) + if rv = find_by_upid(upid) + rv.time = Time.now.to_i + rv.save + rv + end + end + + def start(upid, length) + # this must be a find_or_create_by since some users have twitchy + # fingers and hit the upload button prematurely + find_or_create_by_upid(upid) do |x| + x.length = length + x.time = Time.now.to_i + x.seen = 0 + end + end + + def incr(upid, nr) + update_all("seen = seen + #{nr.to_i}, time = #{Time.now.to_i}", + { :upid => upid }) + end + + def gc + cutoff = Time.now.to_i - @@gc_cutoff + delete_all "time < #{cutoff}" + end + end + +end diff --git a/examples/rails_app-2.3.4/app/views/files/index.html.erb b/examples/rails_app-2.3.4/app/views/files/index.html.erb new file mode 100644 index 0000000..b604ee0 --- /dev/null +++ b/examples/rails_app-2.3.4/app/views/files/index.html.erb @@ -0,0 +1,60 @@ + + + + upr test + <%= javascript_include_tag :all %> + + + +<% +upid = "#{Time.now.to_i}.#{rand}" +act = { :action => 'upload', :upload_id => upid } +opt = { + :multipart => true, + :target => 'upload', + :onsubmit => "UploadProgress.monitor('#{escape_javascript(upid)}')" +} +-%> +

<%= link_to upid, :action => 'status', :upload_id => upid %>

+<% form_tag(act, opt) do %> +
+

<%= file_field_tag :data %>

+
+

<%= link_to_function 'Add File Field', 'UploadProgress.FileField.add()' %> +

+

<%= submit_tag :Upload %>

+<% end %> + +
+
+ + + + + -- cgit v1.2.3-24-ge0c7