Add instance statistics at /fullstats

This commit is contained in:
Luc Didry 2017-07-17 22:23:38 +02:00
parent 1fbe93a71c
commit 1c2cee539d
2 changed files with 31 additions and 0 deletions

View File

@ -319,6 +319,11 @@ sub startup {
shift->render(template => 'about');
})->name('about');
# Get instance stats
$r->get('/fullstats')
->to('Misc#fullstats')
->name('fullstats');
# Get a file
$r->get('/r/:short')->
to('Files#r')->

View File

@ -0,0 +1,26 @@
# vim:set sw=4 ts=4 sts=4 ft=perl expandtab:
package Lufi::Controller::Misc;
use Mojo::Base 'Mojolicious::Controller';
use Mojo::File;
use LufiDB;
use Lufi::File;
use Lufi::Slice;
sub fullstats {
my $c = shift;
my $files = LufiDB::Files->count('WHERE created_at IS NOT null AND deleted = 0');
my $deleted = LufiDB::Files->count('WHERE created_at IS NOT null AND deleted = 1');
my $empty = LufiDB::Files->count('WHERE created_at IS null');
return $c->render(
json => {
files => $files,
deleted => $deleted,
empty => $empty,
timestamp => time,
}
);
}
1;