Permalink
Browse files

license added, upload restricted to image files only

  • Loading branch information...
1 parent 0dcf6bd commit 3289cce7ec4978e0b3516a09b963addab4f52838 @zlorfi committed Mar 28, 2013
Showing with 55 additions and 24 deletions.
  1. +7 −0 LICENSE.md
  2. +12 −0 README.md
  3. +12 −7 app.rb
  4. +19 −16 views/index.haml
  5. +5 −1 views/upload.haml
View
@@ -0,0 +1,7 @@
+Copyright (c) 2013 Michael Skrynski
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -15,8 +15,20 @@
- `bundle install`
- start `mongodb`
+- create `tmp` and `upload` directories (`mkdir tmp upload`) and make them writable for your Apache
+- install ImageMagic (`apt-get -y install imagemagick` or `yum -y install ImageMagick.x86_64`)
- `bundle exec shotgun config.ru` for development (a bit of a warning, `rack_flash` doesn't seem to work with `shotgun`)
- `bundle exec puma config.ru` for production
## TODO
- image handler exception
+- store already loaded images in session
+- fix a whimsical doubling bug when showing images
+- huge multiupload of images causes failed images to load in gallery overview
+
+## Copyright
+(The MIT license)
+
+Copyright (C) 2013 Michael Skrynski
+
+See [LICENSE.md](LICENSE.md).
View
19 app.rb
@@ -147,10 +147,10 @@ def count_all_pictures
post "/upload" do
protected!
content_type 'application/json', :charset => 'utf-8' if request.xhr?
- if params[:file]
+ if params[:file] && params[:file][:type].match(/image\/(gif|png|jpe?g)/)
filename = params[:file][:filename]
file = params[:file][:tempfile]
-
+
prepared_image = app.fetch_file(file).process!(:resize, '800x800>')
image_uid = app.store(prepared_image, :meta => {:upload_time => Time.now, :name => filename})
picture = Picture.create(image_uid: image_uid,
@@ -163,7 +163,7 @@ def count_all_pictures
redirect "/i/#{picture.id}" if !request.xhr?
picture.to_json
else
- flash[:alert] = 'You have to choose a file first'
+ flash[:alert] = 'You have to choose an image file first'
redirect "/upload"
end
@@ -183,9 +183,14 @@ def count_all_pictures
protected!
p = Picture.find(params[:image_id])
if p.delete
- File.delete("upload/#{p.image_uid}")
- flash[:success] = "Image #{p.image_name} has been deleted"
- redirect '/'
+ begin
+ File.delete("upload/#{p.image_uid}")
+ flash[:success] = "Image #{p.image_name} has been deleted"
+ redirect '/'
+ rescue => e
+ flash[:alert] = "ERROR! #{e.message}"
+ redirect '/'
+ end
else
flash[:alert] = "ERROR!"
end
@@ -194,7 +199,7 @@ def count_all_pictures
get '/gallery/:items/:skip' do
if params[:items] && params[:skip]
@pictures = Picture.all.asc(:image_date).limit(params[:items]).skip(params[:skip])
- haml :gallery, :layout => false #!request.xhr?
+ haml :gallery, :layout => !request.xhr?
else
flash.now[:alert] = "ERROR!"
end
View
@@ -1,7 +1,7 @@
.row
.large-8.columns
%ul#gallery.small-block-grid-4.large-block-grid-6
- =# haml :gallery
+ =# haml :gallery if !request.xhr?
#load_more
.small.button.expand.radius
@@ -21,26 +21,29 @@
$(document).ready(function() {
- var items = 12;
- var skip = 12;
+ var items = 15;
+ var skip = items;
$.get('/gallery/' + items + '/0', function(data){
$(data).appendTo("#gallery");
+ if (skip >= "#{count_all_pictures}") {
+ $('#load_more').hide();
+ }
});
- $('#load_more').click(function(data){
- if(skip < "#{count_all_pictures}") {
- console.log(skip);
- console.log("#{count_all_pictures}");
- $.get('/gallery/' + items + '/' + skip, function(data){
- $(data).appendTo("#gallery");
- skip += 12;
- });
- }
- else {
- $('#load_more').hide();
- }
- });
+ $('#load_more').click(function(data){
+ if(skip < "#{count_all_pictures}") {
+ console.log(skip);
+ console.log("#{count_all_pictures}");
+ $.get('/gallery/' + items + '/' + skip, function(data){
+ $(data).appendTo("#gallery");
+ skip += 12;
+ });
+ }
+ else {
+ $('#load_more').hide();
+ }
+ });
$('.fancybox').fancybox({
openEffect: 'none',
View
@@ -8,7 +8,7 @@
%label Title
%input.title{:type => "text", :placeholder => "Insert Title", :name => :title}
%label File
- %input.file{:type => :file, :name => :file, :multiple => ""}
+ %input.file{:type => :file, :name => :file, :multiple => "", :accept => 'image/*'}
-#%input.small.button{:type => "submit" ,:value => "Upload", :id => 'upload'}
#progress_bar
@@ -26,6 +26,10 @@
$('#file_upload').fileupload({
autoUpload: true,
+ limitMultiFileUploads: 5,
+ maxNumberOfFiles: 5,
+ maxFileSize: 10000000,
+ acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
add: function (event, data) {
$.ajax({
url: '/upload',

0 comments on commit 3289cce

Please sign in to comment.