]> git.sesse.net Git - pr0n/blobdiff - perl/Sesse/pr0n/Rotate.pm
Add a mechanism for invalidating the front-end cache, if any. Currently it spits...
[pr0n] / perl / Sesse / pr0n / Rotate.pm
index be562255da39bb134ac488c9b7c1d2894d3a7290..eb8d17ebc8c386ea7f1cc746e9d410a0355dc4e6 100644 (file)
@@ -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
@@ -43,6 +49,7 @@ sub handler {
                                }
                        } 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 {
@@ -70,6 +77,10 @@ sub handler {
        $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;