mirror of
https://framagit.org/fiat-tux/hat-softwares/lutim.git
synced 2026-07-13 21:31:23 +02:00
Issue #42; abstraction layer finished
This commit is dedicated to Schoumi, who is supporting me on Tipeee. Many thanks :-)
This commit is contained in:
+136
-22
@@ -13,6 +13,120 @@ sub new {
|
||||
return $c;
|
||||
}
|
||||
|
||||
sub count_delete_at_day_endis {
|
||||
my $c = shift;
|
||||
my $day = shift;
|
||||
my $enabled = shift;
|
||||
my $created = shift;
|
||||
|
||||
if (defined $created) {
|
||||
return Lutim::DB::SQLite::Lutim->count('WHERE path IS NOT NULL AND delete_at_day = ? AND enabled = ? AND created_at < ?', $day, $enabled, $created);
|
||||
} else {
|
||||
return Lutim::DB::SQLite::Lutim->count('WHERE path IS NOT NULL AND delete_at_day = ? AND enabled = ?', $day, $enabled);
|
||||
}
|
||||
}
|
||||
|
||||
sub count_created_before {
|
||||
my $c = shift;
|
||||
my $time = shift;
|
||||
|
||||
return Lutim::DB::SQLite::Lutim->count('WHERE path IS NOT NULL AND created_at < ?', $time);
|
||||
}
|
||||
|
||||
sub select_created_after {
|
||||
my $c = shift;
|
||||
my $time = shift;
|
||||
|
||||
my @images;
|
||||
|
||||
my @records = Lutim::DB::SQLite::Lutim->select('WHERE path IS NOT NULL AND created_at >= ?', $time);
|
||||
|
||||
for my $e (@records) {
|
||||
my $i = Lutim::DB::Image->new(app => $c->app);
|
||||
$i->record($e);
|
||||
$i->_slurp;
|
||||
|
||||
push @images, $i;
|
||||
}
|
||||
|
||||
return c(@images);
|
||||
}
|
||||
|
||||
sub select_empty {
|
||||
my $c = shift;
|
||||
|
||||
my @records = Lutim::DB::SQLite::Lutim->select('WHERE path IS NULL LIMIT 1');
|
||||
|
||||
$c->record($records[0]);
|
||||
$c = $c->_slurp;
|
||||
|
||||
return $c;
|
||||
}
|
||||
|
||||
sub write {
|
||||
my $c = shift;
|
||||
|
||||
if ($c->record) {
|
||||
$c->record->update(
|
||||
counter => $c->counter,
|
||||
created_at => $c->created_at,
|
||||
created_by => $c->created_by,
|
||||
delete_at_day => $c->delete_at_day,
|
||||
delete_at_first_view => $c->delete_at_first_view,
|
||||
enabled => $c->enabled,
|
||||
filename => $c->filename,
|
||||
footprint => $c->footprint,
|
||||
height => $c->height,
|
||||
last_access_at => $c->last_access_at,
|
||||
mediatype => $c->mediatype,
|
||||
mod_token => $c->mod_token,
|
||||
path => $c->path,
|
||||
short => $c->short,
|
||||
width => $c->width
|
||||
);
|
||||
} else {
|
||||
my $record = Lutim::DB::SQLite::Lutim->create(
|
||||
counter => $c->counter,
|
||||
created_at => $c->created_at,
|
||||
created_by => $c->created_by,
|
||||
delete_at_day => $c->delete_at_day,
|
||||
delete_at_first_view => $c->delete_at_first_view,
|
||||
enabled => $c->enabled,
|
||||
filename => $c->filename,
|
||||
footprint => $c->footprint,
|
||||
height => $c->height,
|
||||
last_access_at => $c->last_access_at,
|
||||
mediatype => $c->mediatype,
|
||||
mod_token => $c->mod_token,
|
||||
path => $c->path,
|
||||
short => $c->short,
|
||||
width => $c->width
|
||||
);
|
||||
$c->record($record);
|
||||
}
|
||||
|
||||
return $c;
|
||||
}
|
||||
|
||||
sub count_short {
|
||||
my $c = shift;
|
||||
my $short = shift;
|
||||
|
||||
return Lutim::DB::SQLite::Lutim->count('WHERE short IS ?', $short);
|
||||
}
|
||||
|
||||
sub count_empty {
|
||||
my $c = shift;
|
||||
|
||||
return Lutim::DB::SQLite::Lutim->count('WHERE path IS NULL');
|
||||
}
|
||||
|
||||
sub count_not_empty {
|
||||
my $c = shift;
|
||||
|
||||
return Lutim::DB::SQLite::Lutim->count('WHERE path IS NOT NULL');
|
||||
}
|
||||
|
||||
sub clean_ips_until {
|
||||
my $c = shift;
|
||||
my $time = shift;
|
||||
@@ -50,7 +164,7 @@ sub get_images_to_clean {
|
||||
|
||||
my @images;
|
||||
|
||||
my @records = c(Lutim::DB::SQLite::Lutim->select('WHERE enabled = 1 AND (delete_at_day * 86400) < (? - created_at) AND delete_at_day != 0', time()));
|
||||
my @records = Lutim::DB::SQLite::Lutim->select('WHERE enabled = 1 AND (delete_at_day * 86400) < (? - created_at) AND delete_at_day != 0', time());
|
||||
|
||||
for my $e (@records) {
|
||||
my $i = Lutim::DB::Image->new(app => $c->app);
|
||||
@@ -68,7 +182,7 @@ sub get_50_oldest {
|
||||
|
||||
my @images;
|
||||
|
||||
my @records = c(Lutim::DB::SQLite::Lutim->select('WHERE path IS NOT NULL AND enabled = 1 ORDER BY created_at ASC LIMIT 50'));
|
||||
my @records = Lutim::DB::SQLite::Lutim->select('WHERE path IS NOT NULL AND enabled = 1 ORDER BY created_at ASC LIMIT 50');
|
||||
|
||||
for my $e (@records) {
|
||||
my $i = Lutim::DB::Image->new(app => $c->app);
|
||||
@@ -93,31 +207,31 @@ sub disable {
|
||||
sub _slurp {
|
||||
my $c = shift;
|
||||
|
||||
my @urls;
|
||||
my @images;
|
||||
if ($c->record) {
|
||||
@urls = ($c->record);
|
||||
@images = ($c->record);
|
||||
} elsif ($c->short) {
|
||||
@urls = Lutim::DB::SQLite::Lutim->select('WHERE short = ?', $c->short);
|
||||
@images = Lutim::DB::SQLite::Lutim->select('WHERE short = ?', $c->short);
|
||||
}
|
||||
|
||||
if (scalar @urls) {
|
||||
$c->short($urls[0]->short);
|
||||
$c->path($urls[0]->path);
|
||||
$c->footprint($urls[0]->footprint);
|
||||
$c->enabled($urls[0]->enabled);
|
||||
$c->mediatype($urls[0]->mediatype);
|
||||
$c->filename($urls[0]->filename);
|
||||
$c->counter($urls[0]->counter);
|
||||
$c->delete_at_first_view($urls[0]->delete_at_first_view);
|
||||
$c->delete_at_day($urls[0]->delete_at_day);
|
||||
$c->created_at($urls[0]->created_at);
|
||||
$c->created_by($urls[0]->created_by);
|
||||
$c->last_access_at($urls[0]->last_access_at);
|
||||
$c->mod_token($urls[0]->mod_token);
|
||||
$c->width($urls[0]->width);
|
||||
$c->height($urls[0]->height);
|
||||
if (scalar @images) {
|
||||
$c->short($images[0]->short);
|
||||
$c->path($images[0]->path);
|
||||
$c->footprint($images[0]->footprint);
|
||||
$c->enabled($images[0]->enabled);
|
||||
$c->mediatype($images[0]->mediatype);
|
||||
$c->filename($images[0]->filename);
|
||||
$c->counter($images[0]->counter);
|
||||
$c->delete_at_first_view($images[0]->delete_at_first_view);
|
||||
$c->delete_at_day($images[0]->delete_at_day);
|
||||
$c->created_at($images[0]->created_at);
|
||||
$c->created_by($images[0]->created_by);
|
||||
$c->last_access_at($images[0]->last_access_at);
|
||||
$c->mod_token($images[0]->mod_token);
|
||||
$c->width($images[0]->width);
|
||||
$c->height($images[0]->height);
|
||||
|
||||
$c->record($urls[0]) unless $c->record;
|
||||
$c->record($images[0]) unless $c->record;
|
||||
}
|
||||
|
||||
return $c;
|
||||
|
||||
Reference in New Issue
Block a user