Skip to content

Commit

Permalink
Merge pull request #1159 from Difegue/dev
Browse files Browse the repository at this point in the history
LRR 0.9.31
  • Loading branch information
Difegue authored Jan 13, 2025
2 parents e337c94 + 3c13881 commit 7b9c1da
Show file tree
Hide file tree
Showing 28 changed files with 245 additions and 188 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/push-continous-delivery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ jobs:

buildNightlyWSL:
name: Build Nightly Windows Packages
needs: exportDockerRootFS
needs:
- exportDockerRootFS
- exportDockerRootFSLegacy
runs-on: windows-latest
steps:
- uses: actions/checkout@master
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
[<img src="https://img.shields.io/github/downloads/difegue/lanraragi/total.svg">](https://github.com/Difegue/LANraragi/releases)
[<img src="https://img.shields.io/github/release/difegue/lanraragi.svg?label=latest%20release">](https://github.com/Difegue/LANraragi/releases/latest)
[<img src="https://img.shields.io/homebrew/v/lanraragi.svg">](https://formulae.brew.sh/formula/lanraragi)

[<img src="https://img.shields.io/website/https/lrr.tvc-16.science.svg?label=demo%20website&up_message=online">](https://lrr.tvc-16.science/)
[<img src="https://github.com/Difegue/LANraragi/actions/workflows/push-continuous-integration.yml/badge.svg">](https://github.com/Difegue/LANraragi/actions)
[<img src="https://img.shields.io/discord/612709831744290847">](https://discord.gg/aRQxtbg)
Expand Down
15 changes: 8 additions & 7 deletions lib/LANraragi.pm
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ sub startup {
$self->secrets( [ $secret . hostname() ] );
$self->plugin('RenderFile');

# Load i18n
LANraragi::Utils::I18NInitializer::initialize($self);

# Set Template::Toolkit as default renderer so we can use the LRR templates
$self->plugin('TemplateToolkit');
$self->renderer->default_handler('tt2');
Expand Down Expand Up @@ -91,6 +88,9 @@ sub startup {
die;
}

# Load i18n
LANraragi::Utils::I18NInitializer::initialize($self);

# Catch Redis errors on our first connection. This is useful in case of temporary LOADING errors,
# Where Redis lets us send commands but doesn't necessarily reply to them properly.
# (https://github.com/redis/redis/issues/4624)
Expand Down Expand Up @@ -194,18 +194,19 @@ sub startup {

my $prefix = $self->LRR_BASEURL;
if ($prefix) {
if (!$prefix =~ m|^/[^"]*[^/"]$|) {
if ( !$prefix =~ m|^/[^"]*[^/"]$| ) {
say "Warning: configured URL prefix '$prefix' invalid, ignoring";

# if prefix is invalid, then set it to empty for the cookie
$prefix = "";
}
else {
} else {
$c->req->url->base->path($prefix);
}
}

# SameSite=Lax is the default behavior here; I set it
# explicitly to get rid of a warning in the browser
$c->cookie("lrr_baseurl" => $prefix, { samesite => "lax" });
$c->cookie( "lrr_baseurl" => $prefix, { samesite => "lax" } );
}
);

Expand Down
1 change: 0 additions & 1 deletion lib/LANraragi/Controller/Api/Archive.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use File::Temp qw(tempdir);
use File::Basename;
use File::Find;

use LANraragi::Utils::Archive qw(extract_thumbnail);
use LANraragi::Utils::Generic qw(render_api_response is_archive get_bytelength);
use LANraragi::Utils::Database qw(get_archive_json set_isnew);
use LANraragi::Utils::Logging qw(get_logger);
Expand Down
19 changes: 11 additions & 8 deletions lib/LANraragi/Controller/Api/Search.pm
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,19 @@ sub handle_datatables {
# Collection (tags column)
if ( $req->param("columns[$i][name]") eq "tags" ) {
$categoryfilter = $req->param("columns[$i][search][value]");
}

# New filter (isnew column)
if ( $req->param("columns[$i][name]") eq "isnew" ) {
$newfilter = $req->param("columns[$i][search][value]") eq "true";
}
# Specific hacks for the buily-in newonly/untagged selectors
# Those have hardcoded 'category' IDs
if ( $categoryfilter eq "NEW_ONLY" ) {
$newfilter = 1;
$categoryfilter = "";
}

if ( $categoryfilter eq "UNTAGGED_ONLY" ) {
$untaggedfilter = 1;
$categoryfilter = "";
}

# Untagged filter (untagged column)
if ( $req->param("columns[$i][name]") eq "untagged" ) {
$untaggedfilter = $req->param("columns[$i][search][value]") eq "true";
}
$i++;
}
Expand Down
28 changes: 14 additions & 14 deletions lib/LANraragi/Model/Archive.pm
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package LANraragi::Model::Archive;

use v5.36;
use experimental 'try';

use strict;
use warnings;
use utf8;

use feature qw(signatures);
no warnings 'experimental::signatures';

use Cwd 'abs_path';
use Redis;
use Time::HiRes qw(usleep);
Expand Down Expand Up @@ -70,17 +70,17 @@ sub update_thumbnail {
my $newthumb = "";

# Get the required thumbnail we want to make the main one
eval { $newthumb = extract_thumbnail( $thumbdir, $id, $page, 1 ) };
no warnings 'experimental::try';
try {
$newthumb = extract_thumbnail( $thumbdir, $id, $page, 1, 1 )
} catch ($e) {
render_api_response( $self, "update_thumbnail", $e );
return;
}

if ( $@ || !$newthumb ) {
render_api_response( $self, "update_thumbnail", $@ );
if ( !$newthumb ) {
render_api_response( $self, "update_thumbnail", "Thumbnail not generated." );
} else {
if ( $newthumb ne $thumbname && $newthumb ne "" ) {

# Copy the thumbnail to the main thumbnail location
cp( $newthumb, $thumbname );
}

$self->render(
json => {
operation => "update_thumbnail",
Expand Down Expand Up @@ -114,8 +114,8 @@ sub generate_page_thumbnails {

my $should_queue_job = 0;

for ( my $page = 2; $page <= $pages; $page++ ) {
my $thumbname = ( $page - 1 > 0 ) ? "$thumbdir/$subfolder/$id/$page.$format" : "$thumbdir/$subfolder/$id.$format";
for ( my $page = 1; $page <= $pages; $page++ ) {
my $thumbname = "$thumbdir/$subfolder/$id/$page.$format";

unless ( $force == 0 && -e $thumbname ) {
$logger->debug("Thumbnail for page $page doesn't exist (path: $thumbname or force=$force), queueing job.");
Expand Down
27 changes: 10 additions & 17 deletions lib/LANraragi/Model/Plugins.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ use LANraragi::Utils::Tags qw(rewrite_tags split_tags_to_array);
use LANraragi::Utils::Plugins qw(get_plugin_parameters get_plugin);

# Sub used by Auto-Plugin.
sub exec_enabled_plugins_on_file {
sub exec_enabled_plugins_on_file ($id) {

my $id = shift;
my $logger = get_logger( "Auto-Plugin", "lanraragi" );

$logger->info("Executing enabled metadata plugins on archive with id $id.");
Expand Down Expand Up @@ -95,10 +94,10 @@ sub exec_enabled_plugins_on_file {

# Unlike the two other methods, exec_login_plugin takes a plugin name and does the Redis lookup itself.
# Might be worth consolidating this later.
sub exec_login_plugin {
my $plugname = shift;
my $ua = Mojo::UserAgent->new;
my $logger = get_logger( "Plugin System", "lanraragi" );
sub exec_login_plugin ($plugname) {

my $ua = Mojo::UserAgent->new;
my $logger = get_logger( "Plugin System", "lanraragi" );

if ($plugname) {
$logger->debug("Calling matching login plugin $plugname.");
Expand All @@ -125,9 +124,7 @@ sub exec_login_plugin {
return $ua;
}

sub exec_script_plugin {

my ( $plugin, %settings ) = @_;
sub exec_script_plugin ( $plugin, %settings ) {

no warnings 'experimental::try';

Expand All @@ -153,9 +150,8 @@ sub exec_script_plugin {
}
}

sub exec_download_plugin {
sub exec_download_plugin ( $plugin, $input, @settings ) {

my ( $plugin, $input, @settings ) = @_;
my $logger = get_logger( "Plugin System", "lanraragi" );

my %pluginfo = $plugin->plugin_info();
Expand Down Expand Up @@ -186,9 +182,7 @@ sub exec_download_plugin {
}

# Execute a specified plugin on a file, described through its Redis ID.
sub exec_metadata_plugin {

my ( $plugin, $id, %args ) = @_;
sub exec_metadata_plugin ( $plugin, $id, %args ) {

no warnings 'experimental::try';

Expand All @@ -212,7 +206,7 @@ sub exec_metadata_plugin {
$thumbhash = "";

try {
extract_thumbnail( $thumbdir, $id, 0, 1 );
extract_thumbnail( $thumbdir, $id, 1, 1, 1 );
$thumbhash = $redis->hget( $id, "thumbhash" );
$thumbhash = LANraragi::Utils::Database::redis_decode($thumbhash);
} catch ($e) {
Expand Down Expand Up @@ -299,8 +293,7 @@ sub exec_metadata_plugin {
}

# TODO: remove after the deprecation period
sub has_old_style_params {
my (%params) = @_;
sub has_old_style_params (%params) {
return ( exists $params{'customargs'} );
}

Expand Down
59 changes: 35 additions & 24 deletions lib/LANraragi/Model/Reader.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package LANraragi::Model::Reader;

use v5.36;
use experimental 'try';

use strict;
use warnings;
use utf8;
Expand All @@ -12,46 +15,54 @@ use File::Copy qw(move);
use Mojo::JSON qw(encode_json);
use Data::Dumper;
use URI::Escape;
use Image::Magick;

use LANraragi::Utils::Generic qw(is_image shasum);
use LANraragi::Utils::Archive qw(extract_archive get_filelist);
use LANraragi::Utils::Generic qw(is_image shasum);
use LANraragi::Utils::Logging qw(get_logger);
use LANraragi::Utils::Archive qw(extract_archive get_filelist);
use LANraragi::Utils::Database qw(redis_decode);

# resize_image(image,quality, size_threshold)
# Convert an image to a cheaper on bandwidth format through ImageMagick.
sub resize_image {
# This will no-op if the ImageMagick bindings are unavailable.
sub resize_image ( $imgpath, $quality, $threshold ) {

no warnings 'experimental::try';
try {
require Image::Magick;
my $img = Image::Magick->new;

my ( $imgpath, $quality, $threshold ) = @_;
my $img = Image::Magick->new;
#Is the file size higher than the threshold?
if ( ( int( ( -s $imgpath ) / 1024 * 10 ) / 10 ) > $threshold ) {

#Is the file size higher than the threshold?
if ( ( int( ( -s $imgpath ) / 1024 * 10 ) / 10 ) > $threshold ) {
# For JPEG, the size option (or jpeg:size option) provides a hint to the JPEG decoder
# that it can reduce the size on-the-fly during decoding. This saves memory because
# it never has to allocate memory for the full-sized image
$img->Set( option => 'jpeg:size=1064x' );

# For JPEG, the size option (or jpeg:size option) provides a hint to the JPEG decoder
# that it can reduce the size on-the-fly during decoding. This saves memory because
# it never has to allocate memory for the full-sized image
$img->Set( option => 'jpeg:size=1064x' );
$img->Read($imgpath);

$img->Read($imgpath);
my ( $origw, $origh ) = $img->Get( 'width', 'height' );
if ( $origw > 1064 ) {
$img->Resize( geometry => '1064x' );
}

my ( $origw, $origh ) = $img->Get( 'width', 'height' );
if ( $origw > 1064 ) {
$img->Resize( geometry => '1064x' );
# Set format to jpeg and quality
$img->Set( quality => $quality, magick => "jpg" );
$img->Write($imgpath);
}
undef $img;
} catch ($e) {

# Set format to jpeg and quality
$img->Set( quality => $quality, magick => "jpg" );
$img->Write($imgpath);
# Magick is unavailable, do nothing
my $logger = get_logger( "Reader", "lanraragi" );
$logger->debug("ImageMagick is not available , skipping image resizing: $e");
}
undef $img;

}

# build_reader_JSON(mojo, id, forceReload)
# Opens the archive specified by its ID, and returns a json containing the page names.
sub build_reader_JSON {

my ( $self, $id, $force ) = @_;
sub build_reader_JSON ( $self, $id, $force ) {

# Queue a full extract job into Minion.
# This'll fill in the missing pages (or regen everything if force = 1)
Expand All @@ -62,7 +73,7 @@ sub build_reader_JSON {

# Get the path from Redis.
# Filenames are stored as they are on the OS, so no decoding!
my $redis = LANraragi::Model::Config->get_redis;
my $redis = LANraragi::Model::Config->get_redis;
my $archive = $redis->hget( $id, "file" );

# Parse archive to get its list of images
Expand Down
6 changes: 3 additions & 3 deletions lib/LANraragi/Model/Tankoubon.pm
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ sub get_tankoubon ( $tank_id, $fulldata = 0, $page = 0 ) {

%tank = filter_hash_by_keys( \@allowed_keys, %tank );

my $total = $redis->zcard($tank_id) - 1;
my $total = $redis->zcount($tank_id, 1, "+inf");

return ( $total, $#archives + 1, %tank );
}
Expand Down Expand Up @@ -232,8 +232,8 @@ sub update_metadata ( $tank_id, $data ) {
my $redis = LANraragi::Model::Config->get_redis;
my $err = "";
my $name = $data->{"metadata"}->{"name"} || undef;
my $summary = $data->{"metadata"}->{"summary"} || undef;
my $tags = $data->{"metadata"}->{"tags"} || undef;
my $summary = exists $data->{"metadata"}->{"summary"} ? $data->{"metadata"}->{"summary"} : undef;
my $tags = exists $data->{"metadata"}->{"tags"} ? $data->{"metadata"}->{"tags"} : undef;

if ( $redis->exists($tank_id) ) {
if ( defined $name ) {
Expand Down
Loading

0 comments on commit 7b9c1da

Please sign in to comment.