From c88d48f2a3ce4a29f9abfeef27dc448e654ee746 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Thu, 28 May 2020 00:51:55 +0200 Subject: [PATCH] word edit: cover option changes thumbnail --- writer.plp | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/writer.plp b/writer.plp index 9245915..b64fea0 100644 --- a/writer.plp +++ b/writer.plp @@ -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 $download 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 $download 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} // [] }; -- 2.30.0