word edit: cover option changes thumbnail
authorMischa POSLAWSKY <perl@shiar.org>
Wed, 27 May 2020 22:51:55 +0000 (00:51 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 6 Jun 2020 01:49:20 +0000 (03:49 +0200)
writer.plp

index 92459150c238528a31156858f5805cba6902eeb3..b64fea08e3f8f2fb5dbab85e807dc070eb813e7a 100644 (file)
@@ -177,27 +177,26 @@ elsif ($ENV{REQUEST_METHOD} eq 'POST') {{
        };
 
        my $imgpath = "data/word/org/$row->{id}.jpg";
-       if (($row->{source} // '') ne ($replace->{source} // '')) {
+       my $reimage = eval {
+               ($row->{source} // '') ne ($replace->{source} // '') or return;
                # copy changed remote url to local file
                unlink $imgpath if -e $imgpath;
-               if (my $download = $row->{source}) {
-                       require LWP::UserAgent;
-                       my $ua = LWP::UserAgent->new;
-                       $ua->agent('/');
-                       my $status = $ua->mirror($download, $imgpath);
-                       $status->is_success or Alert([
-                               "Source image not found",
-                               "Download from <q>$download</q> failed: ".$status->status_line,
-                       ]);
-               }
-       }
-       elsif ($row->{thumb} ~~ $replace->{thumb}) {
-               # image and conversion unaltered
-               $imgpath = undef;
-       }
+               my $download = $row->{source} or return 1;
+               require LWP::UserAgent;
+               my $ua = LWP::UserAgent->new;
+               $ua->agent('/');
+               my $status = $ua->mirror($download, $imgpath);
+               $status->is_success
+                       or die "Download from <q>$download</q> failed: ".$status->status_line."\n";
+       };
+       !$@ or Alert(["Source image not found", $@]);
+
+       $reimage ||= $row->{thumb} ~~ $replace->{thumb};  # different convert
+       $reimage ||= $row->{cover} ~~ $replace->{cover};  # resize
+       $reimage++ if $fields{rethumb};  # force refresh
 
        my $thumbpath = "data/word/eng/$row->{form}.jpg";
-       if ($imgpath) {
+       if ($reimage) {
                if (-e $imgpath) {
                        my $xyres = $row->{cover} ? '600x400' : '300x200';
                        my @cmds = @{ $row->{thumb} // [] };