From 5d4a0fd63f4d5946fe9de3cfb7ad8da4ec653279 Mon Sep 17 00:00:00 2001 From: Denis Fedoseev Date: Wed, 2 Aug 2017 07:46:54 +0300 Subject: [PATCH 1/2] Field original_filename was added to database --- public/css/main.css | 1 + sql/deploy/images.sql | 12 +----------- sql/revert/images.sql | 35 ++++++++++++++++++++++++++++++++++- sql/sqitch.plan | 3 +++ sql/verify/images.sql | 2 +- 5 files changed, 40 insertions(+), 13 deletions(-) diff --git a/public/css/main.css b/public/css/main.css index f68d8dd..d349733 100644 --- a/public/css/main.css +++ b/public/css/main.css @@ -12,4 +12,5 @@ width: 32px; height: 32px; overflow: hidden; + cursor: pointer; } \ No newline at end of file diff --git a/sql/deploy/images.sql b/sql/deploy/images.sql index 00b577a..d21a584 100644 --- a/sql/deploy/images.sql +++ b/sql/deploy/images.sql @@ -2,16 +2,6 @@ BEGIN; -CREATE TABLE images ( - file_id INTEGER PRIMARY KEY AUTOINCREMENT, - owner_id INTEGER NOT NULL, - file_name TEXT NOT NULL, - created_time DATETIME NOT NULL - DEFAULT CURRENT_TIMESTAMP, - FOREIGN KEY ( - owner_id - ) - REFERENCES users (user_id) ON DELETE CASCADE -); +ALTER TABLE images ADD COLUMN original_filename TEXT NOT NULL DEFAULT "Unknown"; COMMIT; diff --git a/sql/revert/images.sql b/sql/revert/images.sql index f4eeb8a..aa83e6b 100644 --- a/sql/revert/images.sql +++ b/sql/revert/images.sql @@ -1,7 +1,40 @@ --- Revert fotostore:images from sqlite +-- Deploy fotostore:images to sqlite BEGIN; +PRAGMA foreign_keys = 0; + +CREATE TABLE images_rever_temp_table AS SELECT * + FROM images; + DROP TABLE images; +CREATE TABLE images ( + file_id INTEGER PRIMARY KEY AUTOINCREMENT, + owner_id INTEGER NOT NULL, + file_name TEXT NOT NULL, + created_time DATETIME NOT NULL + DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY ( + owner_id + ) + REFERENCES users (user_id) ON DELETE CASCADE +); + +INSERT INTO images ( + file_id, + owner_id, + file_name, + created_time + ) + SELECT file_id, + owner_id, + file_name, + created_time + FROM images_rever_temp_table; + +DROP TABLE images_rever_temp_table; + +PRAGMA foreign_keys = 1; + COMMIT; diff --git a/sql/sqitch.plan b/sql/sqitch.plan index 1f26348..d7782a9 100644 --- a/sql/sqitch.plan +++ b/sql/sqitch.plan @@ -8,3 +8,6 @@ albums 2017-07-22T08:50:11Z Denis Fedoseev # Albums d user_images [users images] 2017-07-22T09:16:20Z Denis Fedoseev # +user_images table album_images [images albums] 2017-07-22T09:21:13Z Denis Fedoseev # +images to album mapping user_albums [users albums] 2017-07-22T09:47:48Z Denis Fedoseev # Albums to users mapping +@v1.0.0 2017-08-02T03:46:51Z Denis Fedoseev # Tag v1.0.0. +images [images@v1.0.0] 2017-08-02T03:55:08Z Denis Fedoseev # Adds images.original_filename. +@v1.1.0 2017-08-02T04:46:42Z Denis Fedoseev # Tag v1.1.0. diff --git a/sql/verify/images.sql b/sql/verify/images.sql index 0ea514f..c87c195 100644 --- a/sql/verify/images.sql +++ b/sql/verify/images.sql @@ -2,6 +2,6 @@ BEGIN; -select file_id, owner_id, file_name, created_time from images where 0; +select file_id, owner_id, file_name, original_filename, created_time from images where 0; ROLLBACK; -- 2.43.0 From 066ab0197cada0add292c212011a52e76aabfcaf Mon Sep 17 00:00:00 2001 From: Denis Fedoseev Date: Wed, 2 Aug 2017 07:55:54 +0300 Subject: [PATCH 2/2] Show original filename in web --- fotostore.pl | 3 ++- lib/FotoStore/DB.pm | 4 ++-- templates/includes/images_list.html.ep | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/fotostore.pl b/fotostore.pl index f4f0760..203f0a1 100755 --- a/fotostore.pl +++ b/fotostore.pl @@ -144,6 +144,7 @@ get '/get_images' => ( authenticated => 1 ) => sub { for my $img_item (@$files_list) { my $file = $img_item->{'file_name'}; my $img_hash = {}; + $img_hash->{'filename'} = $img_item->{'original_filename'}; $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 ); @@ -233,7 +234,7 @@ post '/upload' => ( authenticated => 1 ) => sub { or die $scaled->errstr; } - if ( !$db->add_file( $user->{'user_id'}, $filename ) ) { + if ( !$db->add_file( $user->{'user_id'}, $filename, $image->filename) ) { #TODO: Send error msg } diff --git a/lib/FotoStore/DB.pm b/lib/FotoStore/DB.pm index 8947fc3..49dea87 100644 --- a/lib/FotoStore/DB.pm +++ b/lib/FotoStore/DB.pm @@ -51,8 +51,8 @@ sub add_user($self, $username, $password, $fullname) { } -sub add_file($self, $user_id, $filename) { - my $rows = $self->{'dbh'}->do(q~insert into images (owner_id, file_name) values (?, ?)~, undef, ($user_id, $filename)); +sub add_file($self, $user_id, $filename, $original_filename) { + my $rows = $self->{'dbh'}->do(q~insert into images (owner_id, file_name, original_filename) values (?, ?, ?)~, undef, ($user_id, $filename, $original_filename)); if ($self->{'dbh'}->errstr) { die $self->{'dbh'}->errstr; } diff --git a/templates/includes/images_list.html.ep b/templates/includes/images_list.html.ep index 16d63c9..5649542 100644 --- a/templates/includes/images_list.html.ep +++ b/templates/includes/images_list.html.ep @@ -38,7 +38,8 @@
- + +
{{ image.filename }}
    -- 2.43.0