X-Git-Url: https://git.sesse.net/?p=pr0n;a=blobdiff_plain;f=perl%2FSesse%2Fpr0n%2FRotate.pm;h=eb8d17ebc8c386ea7f1cc746e9d410a0355dc4e6;hp=9cf18d8ef69ed8f790ced723733a812366730838;hb=fd1e8cc4d43ed344438cb93e203ca146fe243487;hpb=b9c62b0e96eb2b04cf0f4355174831606f982f18 diff --git a/perl/Sesse/pr0n/Rotate.pm b/perl/Sesse/pr0n/Rotate.pm index 9cf18d8..eb8d17e 100644 --- a/perl/Sesse/pr0n/Rotate.pm +++ b/perl/Sesse/pr0n/Rotate.pm @@ -14,6 +14,11 @@ sub handler { return Apache2::Const::OK; } + # FIXME: People can rotate and delete across vhosts using this interface. + # We should add some sanity checks. + + my @to_purge = (); + Sesse::pr0n::Common::header($r, "Rotation/deletion results"); { @@ -28,6 +33,7 @@ sub handler { if ($key =~ /^rot-(\d+)-(90|180|270)$/ && $apr->param($key) eq 'on') { my ($id, $rotval) = ($1,$2); my $fname = Sesse::pr0n::Common::get_disk_location($r, $id); + push @to_purge, Sesse::pr0n::Common::get_all_cache_urls($r, $dbh, $id); (my $tmpfname = $fname) =~ s/\.jpg$/-tmp.jpg/; system("/usr/bin/jpegtran -rotate $rotval -copy all < '$fname' > '$tmpfname' && mv '$tmpfname' '$fname'") == 0 @@ -37,19 +43,22 @@ sub handler { if ($rotval == 90 || $rotval == 270) { my $q = $dbh->do('UPDATE images SET height=width,width=height WHERE id=?', undef, $id) or dberror($r, "Size clear of $id failed"); - $dbh->do('UPDATE events SET last_update=CURRENT_TIMESTAMP WHERE id=( SELECT event FROM images WHERE id=? )', + $dbh->do('UPDATE last_picture_cache SET last_update=CURRENT_TIMESTAMP WHERE (vhost,event)=( SELECT vhost,event FROM images WHERE id=? )', undef, $id) or dberror($r, "Cache invalidation at $id failed"); } } elsif ($key =~ /^del-(\d+)$/ && $apr->param($key) eq 'on') { my $id = $1; + push @to_purge, Sesse::pr0n::Common::get_all_cache_urls($r, $dbh, $id); { eval { - $dbh->do('UPDATE events SET last_update=CURRENT_TIMESTAMP WHERE id=( SELECT event FROM images WHERE id=? )', + $dbh->do('UPDATE last_picture_cache SET last_update=CURRENT_TIMESTAMP WHERE (vhost,event)=( SELECT vhost,event FROM images WHERE id=? )', undef, $id); $dbh->do('INSERT INTO deleted_images SELECT * FROM images WHERE id=?', undef, $id); + $dbh->do('DELETE FROM exif_info WHERE image=?', + undef, $id); $dbh->do('DELETE FROM images WHERE id=?', undef, $id); }; @@ -65,9 +74,13 @@ sub handler { } my $event = $apr->param('event'); - $dbh->do('UPDATE events SET last_update=CURRENT_TIMESTAMP WHERE id=?', undef, $event) + $dbh->do('UPDATE last_picture_cache SET last_update=CURRENT_TIMESTAMP WHERE vhost=? AND event=?', undef, $r->get_server_name, $event) or dberror($r, "Cache invalidation failed"); + push @to_purge, "/$event/"; + push @to_purge, "/+all/"; + Sesse::pr0n::Common::purge_cache($r, @to_purge); + Sesse::pr0n::Common::footer($r); return Apache2::Const::OK;