diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/VNDB/Handler/VNEdit.pm | 74 |
1 files changed, 38 insertions, 36 deletions
diff --git a/lib/VNDB/Handler/VNEdit.pm b/lib/VNDB/Handler/VNEdit.pm index 1a607e73..79f439ec 100644 --- a/lib/VNDB/Handler/VNEdit.pm +++ b/lib/VNDB/Handler/VNEdit.pm @@ -117,57 +117,59 @@ sub edit { { post => 'anime', required => 0, default => '' }, { post => 'image', required => 0, default => 0, template => 'int' }, { post => 'img_nsfw', required => 0, default => 0 }, - { post => 'credits', required => 0, default => '', maxlength => 5000 }, - { post => 'seiyuu', required => 0, default => '', maxlength => 5000 }, + { post => 'credits', required => 0, default => '[]', maxlength => 5000 }, + { post => 'seiyuu', required => 0, default => '[]', maxlength => 5000 }, { post => 'vnrelations', required => 0, default => '', maxlength => 5000 }, { post => 'screenshots', required => 0, default => '', maxlength => 1000 }, { post => 'editsum', required => 0, maxlength => 5000 }, { post => 'ihid', required => 0 }, { post => 'ilock', required => 0 }, ); - push @{$frm->{_err}}, 'badeditsum' if !$nosubmit && (!$frm->{editsum} || lc($frm->{editsum}) eq lc($frm->{desc})); + my $raw_c = !$frm->{_err} && json_validate($frm, 'credits', + { field => 'aid', required => 1, template => 'int' }, + { field => 'role', required => 1, enum => $self->{staff_roles} }, + { field => 'note', required => 0, maxlength => 300, default => '' }, + ); + my $raw_s = !$frm->{_err} && json_validate($frm, 'seiyuu', + { field => 'aid', required => 1, template => 'int' }, + { field => 'cid', required => 1, template => 'int' }, + { field => 'note', required => 0, maxlength => 300, default => '' }, + ); # handle image upload $frm->{image} = _uploadimage($self, $frm) if !$nosubmit; my (@credits, @seiyuu); if(!$nosubmit && !$frm->{_err}) { - eval { # catch json decoding errors - my $raw_c = $frm->{credits} ? json_decode $frm->{credits} : []; - my $raw_s = $frm->{seiyuu} ? json_decode $frm->{seiyuu} : []; - - # ensure submitted alias IDs exist within database - my @alist = map $_->{aid}, @$raw_c, @$raw_s; - my %staff = @alist ? map +($_->{aid} => 1), @{$self->dbStaffGet(aid => \@alist, results => 200)} : (); - return unless %staff; # exit from the eval block if staff list is empty - - # check for duplicate credits - my $last_c = { aid => 0, role => '' }; - for my $c (sort { $a->{aid} <=> $b->{aid} || $a->{role} cmp $b->{role} } @$raw_c) { - next unless exists $staff{$c->{aid}}; - # discard entries with identical name & role - next if $last_c->{aid} == $c->{aid} && $last_c->{role} eq $c->{role}; - $c->{aid} += 0; - push @credits, $c; - $last_c = $c; - } + # ensure submitted alias IDs exist within database + my @alist = map $_->{aid}, @$raw_c, @$raw_s; + my %staff = @alist ? map +($_->{aid} => 1), @{$self->dbStaffGet(aid => \@alist, results => 200)} : (); + + # check for duplicate credits + my $last_c = { aid => 0, role => '' }; + for my $c (sort { $a->{aid} <=> $b->{aid} || $a->{role} cmp $b->{role} } @$raw_c) { + next unless exists $staff{$c->{aid}}; + # discard entries with identical name & role + next if $last_c->{aid} == $c->{aid} && $last_c->{role} eq $c->{role}; + $c->{aid} += 0; + push @credits, $c; + $last_c = $c; + } - # if character list is empty, any seiyuu data will be discarded - if (@$chars && @$raw_s) { - my %vn_chars = map +($_->{id} => 1), @$chars; - my $last_s = { aid => 0, cid => 0 }; - for my $s (sort { $a->{aid} <=> $b->{aid} || $a->{cid} <=> $b->{cid} } @$raw_s) { - next unless $staff{$s->{aid}} && $vn_chars{$s->{cid}}; # weed out odd credits - next if $last_s->{aid} == $s->{aid} && $last_s->{cid} == $s->{cid}; - $s->{cid} += 0; # force numeric conversion - $s->{aid} += 0; - push @seiyuu, $s; - $last_s = $s; - } + # if character list is empty, any seiyuu data will be discarded + if (@$chars && @$raw_s) { + my %vn_chars = map +($_->{id} => 1), @$chars; + my $last_s = { aid => 0, cid => 0 }; + for my $s (sort { $a->{aid} <=> $b->{aid} || $a->{cid} <=> $b->{cid} } @$raw_s) { + next unless $staff{$s->{aid}} && $vn_chars{$s->{cid}}; # weed out odd credits + next if $last_s->{aid} == $s->{aid} && $last_s->{cid} == $s->{cid}; + $s->{cid} += 0; # force numeric conversion + $s->{aid} += 0; + push @seiyuu, $s; + $last_s = $s; } - }; - push @{$frm->{_err}}, [ 'credits', 'template', 'json' ] if $@; + } } if(!$nosubmit && !$frm->{_err}) { # parse and re-sort fields that have multiple representations of the same information |