diff --git a/fotostore.pl b/fotostore.pl index a3a559d..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,25 +126,44 @@ get '/' => sub { my $current_user = $self->current_user; +} => '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; - # 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'}, - ); + my $images = []; -} => 'index'; + 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 ); + + my @scaled = (); + for my $scale (@scale_width) { + push(@scaled, {'size' => $scale, 'url' => File::Spec->catfile( '/', $IMAGE_BASE, $current_user->{'user_id'}, $scale, $file )}) ; + } + + $img_hash->{'scales'} = \@scaled; + + 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 { my $self = shift; @@ -163,17 +182,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); 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/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 @@ -
-
Logout
-
- - - - - - -
-
-
-
-
-
- - -
-
-<% 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 { %>
diff --git a/templates/layouts/base.html.ep b/templates/layouts/base.html.ep index a2dc11e..aca3d9d 100644 --- a/templates/layouts/base.html.ep +++ b/templates/layouts/base.html.ep @@ -13,9 +13,9 @@ - - - + + +