From 6010579c39fe533799fd717e18f61d7adc92f010 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Sun, 6 May 2012 10:44:24 -0700 Subject: [PATCH] md5 the user's diaspora id for wallpaper image filename; clean up photo_form.js a little (thx max) --- .../javascripts/app/forms/picture_form.js | 34 +++++++++---------- app/uploaders/wallpaper_uploader.rb | 12 ++++--- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/app/assets/javascripts/app/forms/picture_form.js b/app/assets/javascripts/app/forms/picture_form.js index 2f46dc71e..21f3ba64c 100644 --- a/app/assets/javascripts/app/forms/picture_form.js +++ b/app/assets/javascripts/app/forms/picture_form.js @@ -4,7 +4,8 @@ app.forms.PictureBase = app.views.Base.extend({ "change input[name='photo[user_file]']" : "submitForm" }, - photoUploaded : $.noop, + onSubmit : $.noop, + uploadSuccess : $.noop, postRenderTemplate : function(){ this.$("input[name=authenticity_token]").val($("meta[name=csrf-token]").attr("content")) @@ -12,6 +13,16 @@ app.forms.PictureBase = app.views.Base.extend({ submitForm : function (){ this.$("form").submit(); + this.onSubmit(); + }, + + photoUploaded : function(evt, xhr) { + resp = JSON.parse(xhr.responseText) + if(resp.success) { + this.uploadSuccess(resp) + } else { + alert("Upload failed! Please try again. " + resp.error); + } } }); @@ -30,18 +41,12 @@ app.forms.Picture = app.forms.PictureBase.extend({ this.renderPhotos(); }, - submitForm : function (){ - this.$("form").submit(); + onSubmit : function (){ this.$(".photos").append($('')) }, - photoUploaded : function(evt, xhr) { - resp = JSON.parse(xhr.responseText) - if(resp.success) { - this.photos.add(new Backbone.Model(resp.data)) - } else { - alert("Upload failed! Please try again. " + resp.error); - } + uploadSuccess : function(resp) { + this.photos.add(new Backbone.Model(resp.data)) }, renderPhotos : function(){ @@ -57,12 +62,7 @@ app.forms.Picture = app.forms.PictureBase.extend({ app.forms.Wallpaper = app.forms.PictureBase.extend({ templateName : "wallpaper-form", - photoUploaded : function(evt, xhr) { - resp = JSON.parse(xhr.responseText) - if(resp.success) { - $("#profile").css("background-image", "url(" + resp.data.wallpaper + ")") - } else { - alert("Upload failed! Please try again. " + resp.error); - } + uploadSuccess : function(resp) { + $("#profile").css("background-image", "url(" + resp.data.wallpaper + ")") } }); \ No newline at end of file diff --git a/app/uploaders/wallpaper_uploader.rb b/app/uploaders/wallpaper_uploader.rb index a097fee04..9932b3ef6 100644 --- a/app/uploaders/wallpaper_uploader.rb +++ b/app/uploaders/wallpaper_uploader.rb @@ -3,8 +3,6 @@ class WallpaperUploader < CarrierWave::Uploader::Base storage :file - process :darken - def store_dir "uploads/images" end @@ -13,9 +11,13 @@ class WallpaperUploader < CarrierWave::Uploader::Base %w(jpg jpeg png tiff) end - #def filename - # SecureRandom.hex(10) + File.extname(@filename) if @filename - #end + # Filename is associated with the user's diaspora handle, ensuring uniqueness + # and that only one copy is kept in the filesystem. + def filename + Digest::MD5.hexdigest(model.diaspora_handle) + File.extname(@filename) if @filename + end + + process :darken def darken manipulate! do |img|