word/edit: retain json columns to compare image source
authorMischa POSLAWSKY <perl@shiar.org>
Tue, 17 Jan 2023 01:38:00 +0000 (02:38 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Thu, 9 Feb 2023 17:54:06 +0000 (18:54 +0100)
Prevent downloads of unaltered images.

word/edit.plp

index 2968642860ae37a31326c04f10d96a291744c7a9..dcb4d3dd44e08aae860114e9eba781fe29a085be 100644 (file)
@@ -153,6 +153,7 @@ elsif (defined $post{form}) {{
                my $val = $colinfo->{-multiple} && @val ? \@val : $val[-1];
                if (my $jsoncol = $colinfo->{-json}) {
                        $row->{$jsoncol}->{$col} = $val;  # hash will be encoded
+                       ref $_ eq 'HASH' or $_ = decode_json($_) for $replace->{$jsoncol} // ();
                }
                else {
                        $row->{$col} = $val;
@@ -162,7 +163,7 @@ elsif (defined $post{form}) {{
        while (my ($col, $val) = each %{$row}) {
                # convert json subcolumns to database string
                ref $val eq 'HASH' or next;
-               $val = { %{decode_json($_)}, %{$val} } for $replace->{$col} // ();  # preserve unknown
+               $val = { %{$_}, %{$val} } for $replace->{$col} // ();  # preserve unknown
                defined $val->{$_} or delete $val->{$_} for keys %{$val};  # delete emptied
                $row->{$col} = encode_json($val);
        }
@@ -214,13 +215,13 @@ elsif (defined $post{form}) {{
        require Shiar_Sheet::ImagePrep;
        my $image = Shiar_Sheet::ImagePrep->new($wordcol{source}->{-src}->($row));
        my $reimage = eval {
-               ($imagecol->{source} // '') ne ($replace->{source} // '') or return;
+               ($imagecol->{source} // '') ne ($replace->{image}->{source} // '') or return;
                $image->download($imagecol->{source});
        };
        !$@ or Alert(["Source image not found", $@]);
 
-       $reimage ||= $row->{image} ~~ $replace->{image};  # different source
-       $reimage ||= $row->{cover} ~~ $replace->{cover};  # resize
+       $reimage ||= $row->{convert} ~~ $replace->{image}->{convert};  # different
+       $reimage ||= $row->{cover}   ~~ $replace->{image}->{cover};  # resize
        $reimage++ if $fields{rethumb};  # force refresh
        if ($reimage) {
                eval {