Skip to content

Commit

Permalink
Reuse generate_archive_list to make code more DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
siliconfeces committed Oct 14, 2023
1 parent 2945d1a commit 19174b8
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions lib/LANraragi/Controller/Category.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,18 @@ sub index {

$redis->quit();

#Then complete it with the rest from the database.
#40-character long keys only => Archive IDs
my @keys = $redis->keys('????????????????????????????????????????');

my @idlist = LANraragi::Model::Archive::generate_archive_list;
#Parse the archive list and build <li> elements accordingly.
my $arclist = "";

#Only show IDs that still have their files present.
foreach my $id (@keys) {
my $zipfile = $redis->hget( $id, "file" );
my $title = $redis->hget( $id, "title" );
$title = redis_decode($title);
$title = xml_escape($title);

if ( -e $zipfile ) {
$arclist .=
"<li><input type='checkbox' name='archive' id='$id' class='archive' onchange='Category.updateArchiveInCategory(this.id, this.checked)'>";
$arclist .= "<label for='$id'> $title</label></li>";
}
foreach my $arc (@idlist) {
my $title = xml_escape($arc->{title});
my $id = xml_escape($arc->{arcid});

$arclist .=
"<li><input type='checkbox' name='archive' id='$id' class='archive' onchange='Category.updateArchiveInCategory(this.id, this.checked)'>";
$arclist .= "<label for='$id'> $title</label></li>";
}

$redis->quit();
Expand Down

0 comments on commit 19174b8

Please sign in to comment.