From 3bb9ef5b5595fc833a65129d9d81977662e561d9 Mon Sep 17 00:00:00 2001 From: Denis Fedoseev Date: Mon, 31 Jul 2017 20:21:03 +0300 Subject: [PATCH 1/3] comment --- fotostore.pl | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/fotostore.pl b/fotostore.pl index a3a559d..46ce772 100755 --- a/fotostore.pl +++ b/fotostore.pl @@ -145,6 +145,7 @@ get '/' => sub { } => 'index'; # Upload image file +# There is no restriction for file size in app because restriction is present in nginx configuration post '/upload' => ( authenticated => 1 ) => sub { my $self = shift; @@ -163,17 +164,6 @@ post '/upload' => ( authenticated => 1 ) => sub { ); } - # Upload max size - #my $upload_max_size = 3 * 1024 * 1024; - - # Over max size - #if ($image->size > $upload_max_size) { - # return $self->render( - # template => 'error', - # message => "Upload fail. Image size is too large." - # ); - #} - # Check file type my $image_type = $image->headers->content_type; my %valid_types = map { $_ => 1 } qw(image/gif image/jpeg image/png); From ec32870b98090bc5d7578064ce91a8d547678f17 Mon Sep 17 00:00:00 2001 From: Denis Fedoseev Date: Tue, 1 Aug 2017 15:06:08 +0300 Subject: [PATCH 2/3] Render image list on client --- fotostore.pl | 31 +++++++++++++++++++ templates/images_list.html.ep | 54 ---------------------------------- templates/index.html.ep | 2 +- templates/layouts/base.html.ep | 4 +++ 4 files changed, 36 insertions(+), 55 deletions(-) delete mode 100644 templates/images_list.html.ep diff --git a/fotostore.pl b/fotostore.pl index 46ce772..ca9829a 100755 --- a/fotostore.pl +++ b/fotostore.pl @@ -144,6 +144,37 @@ get '/' => sub { } => 'index'; +get '/get_images' => ( authenticated => 1 ) => sub { + my $self = shift; + + my $current_user = $self->current_user; + + my $files_list = $db->get_files($current_user->{'user_id'}, 20); + + my $thumbs_dir = File::Spec->catfile( $IMAGE_DIR, $current_user->{'user_id'}, $thumbs_size ); + + my @images = map { $_->{'file_name'} } @$files_list; + + my $images = []; + + for my $img_item (@$files_list) { + my $file = $img_item->{'file_name'}; + my $img_hash = {}; + $img_hash->{'original_url'} = File::Spec->catfile( '/', $IMAGE_BASE, $current_user->{'user_id'}, $ORIG_DIR, $file ); + $img_hash->{'thumbnail_url'} = File::Spec->catfile( '/', $IMAGE_BASE, $current_user->{'user_id'}, $thumbs_size, $file ); + + for my $scale (@scale_width) { + $img_hash->{$scale} = File::Spec->catfile( '/', $IMAGE_BASE, $current_user->{'user_id'}, $scale, $file ); + } + + push(@$images, $img_hash); + } + + + # Render + return $self->render( json => $images ); +}; + # Upload image file # There is no restriction for file size in app because restriction is present in nginx configuration post '/upload' => ( authenticated => 1 ) => sub { diff --git a/templates/images_list.html.ep b/templates/images_list.html.ep deleted file mode 100644 index 865ef6e..0000000 --- a/templates/images_list.html.ep +++ /dev/null @@ -1,54 +0,0 @@ -
- -
- - - - - - -
-
-
-
-
-
- - -
-
-<% foreach my $image (@$images) { %> -
-
- "> -
-
- Image original - <% for my $scale (@$scales) { %> - <%= $scale %> - <% } %> -
- -
-<% } %> -
-
\ No newline at end of file diff --git a/templates/index.html.ep b/templates/index.html.ep index bcf2fac..d15117b 100644 --- a/templates/index.html.ep +++ b/templates/index.html.ep @@ -2,7 +2,7 @@

Rough, Slow, Stupid, Contrary Photohosting

<% if (is_user_authenticated()) { %> - %= include 'images_list' + %= include 'includes/images_list' <% } else { %>