From e58b7bb839c771a27cb5a021682bc4ea3e3a57bc Mon Sep 17 00:00:00 2001 From: Denis Fedoseev Date: Tue, 1 Aug 2017 15:33:29 +0300 Subject: [PATCH] Render image list on client --- fotostore.pl | 23 +++++------------------ lib/FotoStore/DB.pm | 1 - templates/layouts/base.html.ep | 3 --- 3 files changed, 5 insertions(+), 22 deletions(-) diff --git a/fotostore.pl b/fotostore.pl index ca9829a..d8dc0d5 100755 --- a/fotostore.pl +++ b/fotostore.pl @@ -54,7 +54,7 @@ plugin 'authentication', { my $digest = $sha->add($password); my $user_id = $db->check_user( $username, $digest->hexdigest() ); - $self->app->log->debug("user id: [$user_id]"); + # $self->app->log->debug("user id: [$user_id]"); return $user_id; }, @@ -126,22 +126,6 @@ get '/' => sub { 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; - - # Render - return $self->render( - images => \@images, - image_base => $IMAGE_BASE, - orig => $ORIG_DIR, - thumbs_size => $thumbs_size, - scales => \@scale_width, - user_id => $current_user->{'user_id'}, - ); - } => 'index'; get '/get_images' => ( authenticated => 1 ) => sub { @@ -163,10 +147,13 @@ get '/get_images' => ( authenticated => 1 ) => sub { $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 ); + my @scaled = (); for my $scale (@scale_width) { - $img_hash->{$scale} = File::Spec->catfile( '/', $IMAGE_BASE, $current_user->{'user_id'}, $scale, $file ); + push(@scaled, {'size' => $scale, 'url' => File::Spec->catfile( '/', $IMAGE_BASE, $current_user->{'user_id'}, $scale, $file )}) ; } + $img_hash->{'scales'} = \@scaled; + push(@$images, $img_hash); } diff --git a/lib/FotoStore/DB.pm b/lib/FotoStore/DB.pm index 1ea57ed..8947fc3 100644 --- a/lib/FotoStore/DB.pm +++ b/lib/FotoStore/DB.pm @@ -19,7 +19,6 @@ sub new { } sub check_user ($self, $nickname, $password) { - print STDERR "[$nickname][$password]"; my ($user_id) = $self->{'dbh'}->selectrow_array(q~select user_id from users where nickname=? and password=?~, undef, ($nickname, $password)); return $user_id; } diff --git a/templates/layouts/base.html.ep b/templates/layouts/base.html.ep index 7415699..aca3d9d 100644 --- a/templates/layouts/base.html.ep +++ b/templates/layouts/base.html.ep @@ -16,9 +16,6 @@ - - -