Database support #1
9 changed files with 38 additions and 122 deletions
126
fotostore.pl
126
fotostore.pl
|
@ -10,13 +10,17 @@ use File::Spec 'catfile';
|
||||||
use Cwd;
|
use Cwd;
|
||||||
|
|
||||||
use Imager;
|
use Imager;
|
||||||
|
use DBI;
|
||||||
|
use Digest::SHA;
|
||||||
|
|
||||||
my $config = plugin 'Config'=> {file => 'application.conf'};;
|
my $config = plugin 'Config'=> {file => 'application.conf'};;
|
||||||
|
|
||||||
my $predefined_user = 'alpha6';
|
my $predefined_user = 'alpha6';
|
||||||
my $predefined_password = $config->{'password'};
|
my $predefined_password = $config->{'password'};
|
||||||
|
|
||||||
die "No user password defined!" unless($predefined_password);
|
die 'No user password defined!' unless($predefined_password);
|
||||||
|
|
||||||
|
my $dbh = DBI->connect(sprintf('dbi:SQLite:dbname=%s', $config->{'db_file'}),"","");
|
||||||
|
|
||||||
# Image base URL
|
# Image base URL
|
||||||
my $IMAGE_BASE = 'images';
|
my $IMAGE_BASE = 'images';
|
||||||
|
@ -220,123 +224,3 @@ sub create_filename {
|
||||||
}
|
}
|
||||||
|
|
||||||
app->start;
|
app->start;
|
||||||
|
|
||||||
__DATA__
|
|
||||||
|
|
||||||
@@ error.html.ep
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" >
|
|
||||||
<title>Error</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<%= $message %>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
||||||
@@ no_logged.html.ep
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" >
|
|
||||||
<title>Rough, Slow, Stupid, Contrary Photohosting</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>Rough, Slow, Stupid, Contrary Photohosting</h1>
|
|
||||||
<form method="post" action="<%= url_for('login') %>" >
|
|
||||||
<div>
|
|
||||||
<input type="text" name="username" >
|
|
||||||
<input type="password" name="password">
|
|
||||||
<input type="submit" value="Login">
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
||||||
@@ index.html.ep
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" >
|
|
||||||
<title>Rough, Slow, Stupid, Contrary Photohosting</title>
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<!-- Bootstrap styles -->
|
|
||||||
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
|
|
||||||
<!-- Generic page styles -->
|
|
||||||
<link rel="stylesheet" href="/file_uploader/css/style.css">
|
|
||||||
<!-- blueimp Gallery styles -->
|
|
||||||
<link rel="stylesheet" href="//blueimp.github.io/Gallery/css/blueimp-gallery.min.css">
|
|
||||||
<!-- CSS to style the file input field as button and adjust the Bootstrap progress bars -->
|
|
||||||
<link rel="stylesheet" href="/file_uploader/css/jquery.fileupload.css">
|
|
||||||
<link rel="stylesheet" href="/file_uploader/css/jquery.fileupload-ui.css">
|
|
||||||
<!-- CSS adjustments for browsers with JavaScript disabled -->
|
|
||||||
<noscript><link rel="stylesheet" href="/file_uploader/css/jquery.fileupload-noscript.css"></noscript>
|
|
||||||
<noscript><link rel="stylesheet" href="/file_uploader/css/jquery.fileupload-ui-noscript.css"></noscript>
|
|
||||||
<style>
|
|
||||||
.bar {
|
|
||||||
height: 18px;
|
|
||||||
background: green;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>Rough, Slow, Stupid, Contrary Photohosting</h1>
|
|
||||||
<% if (is_user_authenticated()) { %>
|
|
||||||
<div><a href="/logout">Logout</a></div>
|
|
||||||
<hr>
|
|
||||||
<input id="fileupload" type="file" name="image" data-url="/upload" multiple>
|
|
||||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
|
|
||||||
<script src="/file_uploader/js/vendor/jquery.ui.widget.js"></script>
|
|
||||||
<script src="/file_uploader/js/jquery.iframe-transport.js"></script>
|
|
||||||
<script src="/file_uploader/js/jquery.fileupload.js"></script>
|
|
||||||
<script>
|
|
||||||
$(function () {
|
|
||||||
$('#fileupload').fileupload({
|
|
||||||
dataType: 'json',
|
|
||||||
done: function (e, data) {
|
|
||||||
$.each(data.result.files, function (index, file) {
|
|
||||||
$('<p/>').text(file.name).appendTo('#lastUploadLog');
|
|
||||||
});
|
|
||||||
},
|
|
||||||
sequentialUploads: true,
|
|
||||||
progressall: function (e, data) {
|
|
||||||
var progress = parseInt(data.loaded / data.total * 100, 10);
|
|
||||||
$('#progress .bar').css(
|
|
||||||
'width',
|
|
||||||
progress + '%'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
<div id="progress">
|
|
||||||
<div class="bar" style="width: 0%;"></div>
|
|
||||||
</div>
|
|
||||||
<div id="lastUploadLog"></div>
|
|
||||||
<!-- display images from server -->
|
|
||||||
<div>
|
|
||||||
<% foreach my $image (@$images) { %>
|
|
||||||
<div>
|
|
||||||
<hr>
|
|
||||||
<div>
|
|
||||||
<a href='<%= "/$image_base/$orig/$image" %>'>Image original</a>
|
|
||||||
<% for my $scale (@$scales) { %>
|
|
||||||
<a href='<%= "/$image_base/$scale/$image" %>'><%= $scale %></a>
|
|
||||||
<% } %>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<img src="<%= "/$image_base/$thumbs_size/$image" %>">
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<% } %>
|
|
||||||
</div>
|
|
||||||
<% } else { %>
|
|
||||||
<form method="post" action="<%= url_for('login') %>" >
|
|
||||||
<div>
|
|
||||||
<input type="text" name="username" >
|
|
||||||
<input type="password" name="password">
|
|
||||||
<input type="submit" value="Login">
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
<% } %>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
17
sql/deploy/images.sql
Normal file
17
sql/deploy/images.sql
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
-- Deploy fotostore:images to sqlite
|
||||||
|
|
||||||
|
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
|
||||||
|
);
|
||||||
|
|
||||||
|
COMMIT;
|
7
sql/revert/images.sql
Normal file
7
sql/revert/images.sql
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
-- Revert fotostore:images from sqlite
|
||||||
|
|
||||||
|
BEGIN;
|
||||||
|
|
||||||
|
DROP TABLE images;
|
||||||
|
|
||||||
|
COMMIT;
|
|
@ -3,3 +3,4 @@
|
||||||
%uri=https://rsscp.ru/
|
%uri=https://rsscp.ru/
|
||||||
|
|
||||||
users 2017-07-22T06:53:03Z Denis Fedoseev <denis.fedoseev@gmail.com> # Creates table to track our users.
|
users 2017-07-22T06:53:03Z Denis Fedoseev <denis.fedoseev@gmail.com> # Creates table to track our users.
|
||||||
|
images 2017-07-22T07:17:52Z Denis Fedoseev <denis.fedoseev@gmail.com> # Creates table to track users images.
|
7
sql/verify/images.sql
Normal file
7
sql/verify/images.sql
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
-- Verify fotostore:images on sqlite
|
||||||
|
|
||||||
|
BEGIN;
|
||||||
|
|
||||||
|
select file_id, owner_id, file_name, created_time from images where 0;
|
||||||
|
|
||||||
|
ROLLBACK;
|
Loading…
Reference in a new issue