mirror of
https://framagit.org/fiat-tux/hat-softwares/lutim.git
synced 2026-03-28 17:42:54 +01:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
438ce5050e |
@@ -1,6 +1,7 @@
|
||||
Revision history for Lutim
|
||||
|
||||
0.15.0 ????-??-??
|
||||
- ✨ — Add --nuke option to image command
|
||||
|
||||
0.14.0 2023-12-18
|
||||
- ⬆️ Update dependencies
|
||||
|
||||
@@ -46,7 +46,8 @@ sub run {
|
||||
'r|remove=s{1,}' => \my @remove,
|
||||
'y|yes' => \my $yes,
|
||||
'q|quiet' => \my $quiet,
|
||||
's|search=s' => \my $ip
|
||||
's|search=s' => \my $ip,
|
||||
'n|nuke=s' => \my $nuke,
|
||||
;
|
||||
|
||||
if (scalar @info) {
|
||||
@@ -85,9 +86,43 @@ sub run {
|
||||
push @shorts, $e->short;
|
||||
print_infos($e, $csv);
|
||||
});
|
||||
say sprintf('%d matching URLs', $u->size);
|
||||
say sprintf('%d matching images', $u->size);
|
||||
say sprintf("If you want to delete those images, please do:\n carton exec script/lutim image --remove %s", join(' ', @shorts)) if @shorts;
|
||||
}
|
||||
if ($nuke) {
|
||||
my $i = get_short($c, $nuke);
|
||||
if ($i && $i->created_by) {
|
||||
my $u = Lutim::DB::Image->new(app => $c->app)->search_exact_created_by($i->created_by);
|
||||
my @shorts;
|
||||
say sprintf('%d images created by the same IP address (%s) than image %s', $u->size, $i->created_by, $nuke);
|
||||
my $confirm = ($yes) ? 'yes' : undef;
|
||||
unless (defined $confirm) {
|
||||
printf('Are you sure you want to remove those %d images? [N/y] ', $u->size);
|
||||
$confirm = <STDIN>;
|
||||
chomp $confirm;
|
||||
}
|
||||
if ($confirm =~ m/^y(es)?$/i) {
|
||||
$u->each(sub {
|
||||
my ($e, $num) = @_;
|
||||
my $i = get_short($c, $e->short);
|
||||
if ($i) {
|
||||
print_infos($i, $csv);
|
||||
if ($i->enabled) {
|
||||
delete_short($c, $i, 1);
|
||||
} else {
|
||||
say sprintf('The image %s is already disabled', $e->short);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
say 'Answer was not "y" or "yes". Aborting deletion.';
|
||||
}
|
||||
} elsif (! $i->created_by) {
|
||||
say sprintf('Image %s does not contain its creator’s IP address.', $nuke);
|
||||
} else {
|
||||
say sprintf('Sorry, can’t find image %s', $nuke);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub get_short {
|
||||
@@ -168,7 +203,7 @@ sub delete_short {
|
||||
|
||||
my $confirm = ($y) ? 'yes' : undef;
|
||||
unless (defined $confirm) {
|
||||
printf('Are you sure you want to remove this image (%s) ? [N/y] ', $i->short);
|
||||
printf('Are you sure you want to remove this image (%s)? [N/y] ', $i->short);
|
||||
$confirm = <STDIN>;
|
||||
chomp $confirm;
|
||||
}
|
||||
@@ -191,6 +226,7 @@ Lutim::Command::image - Manage URL in Lutim's database
|
||||
carton exec script/lutim image --info <short> <short> [--csv] Print infos about the space-separated images (--csv creates a CSV output)
|
||||
carton exec script/lutim image --remove <short> <short> [--yes] [--quiet] Delete the space-separated images (--yes disables confirmation, --quiet disables informations printing)
|
||||
carton exec script/lutim image --search <ip> Print infos about the images uploaded by this IP (database LIKE, may include images uploaded by other IPs)
|
||||
carton exec script/lutim image --nuke <short> Delete the image and all images sent by the same IP address and print infos about the deleted images
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
@@ -345,6 +345,20 @@ sub to_hash {
|
||||
|
||||
=back
|
||||
|
||||
=head2 search_exact_created_by
|
||||
|
||||
=over 1
|
||||
|
||||
=item B<Usage> : C<$c-E<gt>search_exact_created_by($ip)>
|
||||
|
||||
=item B<Arguments> : an IP address
|
||||
|
||||
=item B<Purpose> : get enabled images that have been uploaded by this IP address
|
||||
|
||||
=item B<Returns> : a Mojo::Collection object containing the matching images as Lutim::DB::Image objects
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
1;
|
||||
|
||||
@@ -213,6 +213,27 @@ sub search_created_by {
|
||||
return c(@images);
|
||||
}
|
||||
|
||||
sub search_exact_created_by {
|
||||
my $c = shift;
|
||||
my $ip = shift;
|
||||
|
||||
my @images;
|
||||
|
||||
my $records = $c->app->pg->db->select('lutim', undef, { enabled => 1, created_by => $ip })->hashes;
|
||||
|
||||
$records->each(
|
||||
sub {
|
||||
my ($e, $num) = @_;
|
||||
my $i = Lutim::DB::Image->new(app => $c->app);
|
||||
$i->_slurp($e);
|
||||
|
||||
push @images, $i;
|
||||
}
|
||||
);
|
||||
|
||||
return c(@images);
|
||||
}
|
||||
|
||||
sub _slurp {
|
||||
my $c = shift;
|
||||
my $r = shift;
|
||||
|
||||
@@ -214,6 +214,27 @@ sub search_created_by {
|
||||
return c(@images);
|
||||
}
|
||||
|
||||
sub search_exact_created_by {
|
||||
my $c = shift;
|
||||
my $ip = shift;
|
||||
|
||||
my @images;
|
||||
|
||||
my $records = $c->app->sqlite->db->select('lutim', undef, { enabled => 1, created_by => $ip })->hashes;
|
||||
|
||||
$records->each(
|
||||
sub {
|
||||
my ($e, $num) = @_;
|
||||
my $i = Lutim::DB::Image->new(app => $c->app);
|
||||
$i->_slurp($e);
|
||||
|
||||
push @images, $i;
|
||||
}
|
||||
);
|
||||
|
||||
return c(@images);
|
||||
}
|
||||
|
||||
sub _slurp {
|
||||
my $c = shift;
|
||||
my $r = shift;
|
||||
|
||||
Reference in New Issue
Block a user