Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: shelling/dropbox.io
base: bc1b185d05
...
head fork: shelling/dropbox.io
compare: 7923ac4963
  • 2 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
Commits on Dec 04, 2012
@shelling add config for mogilefs client 54cca3c
Commits on Dec 05, 2012
@shelling complete skeleton 7923ac4
View
67 assets/javascripts/application.js
@@ -0,0 +1,67 @@
+var DropboxIO = {
+ Model: {},
+ Collection: {},
+ View: {},
+ Router: {},
+ initialize: function() {
+ }
+};
+
+DropboxIO.Model.File = Backbone.Model.extend({
+ initialize: function() {
+ },
+});
+
+DropboxIO.Collection.Files = Backbone.Collection.extend({
+ initialize: function() {
+ },
+ model: DropboxIO.Model.File,
+ url: "/file/list",
+});
+
+$(document).ready(function() {
+
+ var FU = $("#fileupload");
+
+ FU.fileupload({
+ autoUpload: true,
+ dataType: "json",
+ multipart: true,
+ type: "post",
+ url: "/file",
+ done: function(e, data) {
+ new DropboxIO.Collection.Files(data.result).each(function(file) {
+ $(".filelist").append(
+ $("<li>").html(file.get("filename"))
+ );
+ });
+ $(this).find(".fileupload-progress")
+ .addClass("fade")
+ .find(".bar")
+ .css("width", "0%")
+ },
+ progressall: function(e, data) {
+ var progress = parseInt(data.loaded / data.total * 100, 10);
+ $(this).find(".fileupload-progress")
+ .removeClass("fade")
+ .find(".bar")
+ .css("width", progress + "%")
+ }
+ });
+
+ // Get information of files have been uploaded
+ FU.each(function () {
+ new DropboxIO.Collection.Files().fetch({
+ success: function(self, response) {
+ self.each(function(file) {
+ $(".filelist").append(
+ $("<li>").html(file.get("filename"))
+ );
+ });
+ },
+ error: function(self, xhr) {
+ }
+ });
+ });
+
+});
View
24 assets/stylesheets/application.scss
@@ -0,0 +1,24 @@
+
+#header {
+ height: 140px;
+}
+
+.fileinput-button {
+ position: relative;
+ overflow: hidden;
+ float: left;
+ margin-right: 4px;
+ input {
+ position: absolute;
+ top: 0;
+ right: 0;
+ margin: 0;
+ opacity: 0;
+ filter: alpha(opacity=0);
+ transform: translate(-300px, 0) scale(4);
+ font-size: 23px;
+ direction: ltr;
+ cursor: pointer;
+ }
+}
+
View
10 config/application.yml
@@ -0,0 +1,10 @@
+---
+development:
+
+ mogilefs:
+ domain: dropbox
+ hosts:
+ - 127.0.0.1:7001
+
+production:
+
View
44 environments.rb
@@ -0,0 +1,44 @@
+require "bundler/setup"
+Bundler.require
+
+class App < Sinatra::Base
+
+ configure :development do
+ register Sinatra::Reloader
+ end
+
+ register Sinatra::ConfigFile
+ register Sinatra::RespondWith
+ config_file "config/application.yml"
+
+ set :database, YAML.load_file("config/database.yml")[ENV['RACK_ENV']].symbolize_keys
+
+ Sequel.connect(settings.database.symbolize_keys)
+ Sequel::Model.plugin :timestamps, :update_on_create => true
+ Sequel::Model.plugin :validation_helpers
+
+ enable :logging
+
+ helpers do
+ include Rack::Utils
+ alias_method :h, :escape_html
+ end
+
+ helpers Sinatra::ContentFor
+
+ not_found do
+ "not found"
+ end
+
+ get "/" do
+ haml :index
+ end
+
+end
+
+["lib", "models", "workers", "routes"].each do |path|
+ Dir["#{path}/*.rb"].each do |file|
+ require_relative file
+ end
+end
+
View
36 models/mog_files.rb
@@ -0,0 +1,36 @@
+class MogFile < Sequel::Model
+
+ attr_accessor :tempfile
+
+ @@keyman = UUID.new
+ @@mogclient = MogileFS::MogileFS.new(App.settings.mogilefs.symbolize_keys)
+
+ def path
+ @@mogclient.get_paths(self.mogkey)
+ end
+
+ def info
+ @@mogclient.file_info(self.mogkey)
+ end
+
+ def initialize_set(attrs)
+ self.mogkey = @@keyman.generate
+ self.tempfile = attrs[:tempfile]
+ self.mimetype = attrs[:type]
+ attrs.delete_if { |k,v| not self.class.columns.include? k }
+ super
+ end
+
+ def before_save
+ if tempfile
+ @@mogclient.store_file(mogkey, nil, tempfile)
+ end
+ super
+ end
+
+ def before_destroy
+ @@mogclient.delete(mogkey)
+ super
+ end
+
+end
View
54 routes/file_handler.rb
@@ -0,0 +1,54 @@
+class App < Sinatra::Base
+
+ get "/file/list" do
+ MogFile.all.to_json
+ end
+
+ get "/file/:uuid/?" do
+ @mog_file = MogFile.where(mogkey: params[:uuid]).first
+ if @mog_file
+ @mog_file.to_json
+ else
+ not_found
+ end
+ end
+
+ get "/file/:uuid/original" do
+ @mog_file = MogFile.where(mogkey: params[:uuid]).first
+ if @mog_file
+ headers "X-REPROXY-URL" => @mog_file.path[0],
+ "Content-Type" => @mog_file.mimetype
+ else
+ not_found
+ end
+ end
+
+ post "/file/?" do
+ params[:files].map { |f|
+ @mogfile = MogFile.new(f)
+ @mogfile.save
+ @mogfile.to_hash
+ }.to_json
+ end
+
+ put "/file/:uuid" do
+ @mog_file = MogFile.where(mogkey: params[:uuid]).first
+ if @mog_file
+ @mog_file.update JSON.parse(request.body.read).symbolize_keys
+ 1.to_json
+ else
+ not_found
+ end
+ end
+
+ delete "/file/:uuid" do
+ @mog_file = MogFile.where(mogkey: params[:uuid]).first
+ if @mog_file
+ @mog_file.destroy
+ 1.to_json
+ else
+ not_found
+ end
+ end
+
+end
View
19 views/index.haml
@@ -0,0 +1,19 @@
+.container
+
+ %form#fileupload{method: "post", enctype: "multipart/form-data"}
+
+ .row.fileupload-buttonbar
+
+ .span7
+ %span.btn.btn-success.fileinput-button
+ %i.icon-plus.icon-white
+ %span= "上傳檔案"
+ %input{type: "file", name: "files[]", multiple: "multiple"}
+
+ .span5.fileupload-progress.fade
+ .progress.progress-success.progress-striped.active{:role => "progressbar", :"aria-valuemax" => "100"}
+ .bar
+
+ .row
+ .span12
+ %ul.filelist
View
44 views/layout.haml
@@ -0,0 +1,44 @@
+!!! 5
+%html{lang: "en"}
+ %head
+
+ %meta{charset: "utf-8"}
+ %meta{:"http-equiv" => "X-UA-Compatible", :content => "IE=edge,chrome=1"}
+ %meta{name: "viewport", content: "width=device-width"}
+
+ %title= "dropbox.io"
+
+ %link{rel: "stylesheet", href: "//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/css/bootstrap-combined.min.css"}
+
+ <!--[if lt IE 7]>
+ %link{rel: "stylesheet", href: "//blueimp.github.com/cdn/css/bootstrap-ie6.min.css"}
+ <![endif]-->
+
+ %link{href: "http://fonts.googleapis.com/css?family=Lobster|Copse|PT+Sans|Satisfy", media: "screen", type: "text/css", rel:"stylesheet"}
+ %link{rel: "stylesheet", href: "/assets/application.css"}
+
+ <!--[if lt IE 9]>
+ %script{src: "//html5shim.googlecode.com/svn/trunk/html5.js"}
+ <![endif]-->
+
+ %script{src: "//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"}
+ %script{src: "//blueimp.github.com/jQuery-File-Upload/js/vendor/jquery.ui.widget.js"}
+ %script{src: "//blueimp.github.com/jQuery-File-Upload/js/jquery.iframe-transport.js"}
+ %script{src: "//blueimp.github.com/jQuery-File-Upload/js/jquery.fileupload.js"}
+ <!--[if gte IE 8]>
+ %script{src: "//blueimp.github.com/jQuery-File-Upload/js/cors/jquery.xdr-transport.js"}
+ <![endif]-->
+ %script{src: "//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/js/bootstrap.min.js"}
+
+ %script{src: "//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.2/underscore-min.js"}
+ %script{src: "//cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js"}
+
+ %script{src: "/assets/application.js"}
+
+ %body
+ #header
+
+ #body
+ = yield
+
+ #footer

No commit comments for this range

Something went wrong with that request. Please try again.