Skip to content

Commit

Permalink
Merge pull request #777 from Difegue/dev
Browse files Browse the repository at this point in the history
LRR 0.8.9
  • Loading branch information
Difegue authored Mar 19, 2023
2 parents 21fa4f4 + f0b4e08 commit 3dbce9f
Show file tree
Hide file tree
Showing 65 changed files with 1,989 additions and 360 deletions.
11 changes: 11 additions & 0 deletions .github/holopin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
organization: lanraragi
defaultSticker: clcv2m3k3787908igx3n92wd4
stickers:
- id: clekglig8137209kxga2do5jq
alias: give-him-the-burg
holobytes:
- evolvingStickerId: clcv23azc576308igea3o58p8
alias: holobyte
from: true
in: true

1 change: 1 addition & 0 deletions .perlcriticrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[-Subroutines::ProhibitSubroutinePrototypes]
36 changes: 31 additions & 5 deletions lib/LANraragi.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use Sys::Hostname;
use Config;

use LANraragi::Utils::Generic qw(start_shinobu start_minion);
use LANraragi::Utils::Logging qw(get_logger);
use LANraragi::Utils::Logging qw(get_logger get_logdir);
use LANraragi::Utils::Plugins qw(get_plugins);
use LANraragi::Utils::TempFolder qw(get_temp);
use LANraragi::Utils::Routing;
Expand Down Expand Up @@ -70,6 +70,12 @@ sub startup {
die;
}

# Check old settings and migrate them if needed
if ( $self->LRR_CONF->get_redis->keys('LRR_*') ) {
say "Migrating old settings to new format...";
migrate_old_settings($self);
}

my $devmode;

# Catch Redis errors on our first connection. This is useful in case of temporary LOADING errors,
Expand All @@ -95,16 +101,21 @@ sub startup {
$self->mode('development');
$self->LRR_LOGGER->info("LANraragi $version (re-)started. (Debug Mode)");

#Tell the mojo logger to print to stdout as well
my $logpath = get_logdir . "/mojo.log";

#Tell the mojo logger to log to file
$self->log->on(
message => sub {
my ( $time, $level, @lines ) = @_;

print "[Mojolicious] ";
print $lines[0];
print "\n";
open( my $fh, '>>', $logpath )
or die "Could not open file '$logpath' $!";

print $fh "[Mojolicious] " . $lines[0] . " " . $lines[1] . "\n";
close $fh;
}
);

} else {
$self->mode('production');
$self->LRR_LOGGER->info("LANraragi $version started. (Production Mode)");
Expand Down Expand Up @@ -191,4 +202,19 @@ sub add_sigint_handler {
}
}

sub migrate_old_settings {
my $self = shift;

# Grab all LRR_* keys from LRR_CONF->get_redis and move them to the config DB
my $redis = $self->LRR_CONF->get_redis;
my $config_db = $self->LRR_CONF->get_configdb;
my @keys = $redis->keys('LRR_*');

foreach my $key (@keys) {
say "Migrating $key to database $config_db";
$redis->move( $key, $config_db );
}

}

1;
8 changes: 5 additions & 3 deletions lib/LANraragi/Controller/Api/Archive.pm
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ sub serve_file {

my $self = shift;
my $id = check_id_parameter( $self, "serve_file" ) || return;
my $redis = $self->LRR_CONF->get_redis();
my $redis = $self->LRR_CONF->get_redis;

my $file = $redis->hget( $id, "file" );
$redis->quit();
Expand Down Expand Up @@ -183,7 +183,8 @@ sub update_progress {
# Undocumented parameter to force progress update
my $force = $self->req->param('force') || 0;

my $redis = $self->LRR_CONF->get_redis();
my $redis = $self->LRR_CONF->get_redis;
my $redis_cfg = $self->LRR_CONF->get_redis_config;
my $pagecount = $redis->hget( $id, "pagecount" );

if ( LANraragi::Model::Config->enable_localprogress ) {
Expand All @@ -207,9 +208,10 @@ sub update_progress {
$redis->hset( $id, "progress", $page );

# Update total pages read statistic
$redis->incr("LRR_TOTALPAGESTAT");
$redis_cfg->incr("LRR_TOTALPAGESTAT");

$redis->quit();
$redis_cfg->quit();

$self->render(
json => {
Expand Down
10 changes: 9 additions & 1 deletion lib/LANraragi/Controller/Api/Category.pm
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,15 @@ sub add_to_category {
my ( $result, $err ) = LANraragi::Model::Category::add_to_category( $catid, $arcid );

if ($result) {
render_api_response( $self, "add_to_category" );
my $successMessage = "Added $arcid to Category $catid!";
my %category = LANraragi::Model::Category::get_category($catid);
my $title = LANraragi::Model::Archive::get_title($arcid);

if (%category && defined($title)) {
$successMessage = "Added \"$title\" to category \"$category{name}\"!";
}

render_api_response( $self, "add_to_category", undef, $successMessage );
} else {
render_api_response( $self, "add_to_category", $err );
}
Expand Down
8 changes: 6 additions & 2 deletions lib/LANraragi/Controller/Api/Database.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ sub serve_backup {

sub drop_database {
LANraragi::Utils::Database::drop_database();

# Force a refresh
invalidate_cache(1);

render_api_response( shift, "drop_database" );
}

Expand Down Expand Up @@ -46,8 +50,8 @@ sub clean_database {
sub clear_new_all {

my $self = shift;
my $redis = $self->LRR_CONF->get_redis();
my $redis_search = $self->LRR_CONF->get_redis_search();
my $redis = $self->LRR_CONF->get_redis;
my $redis_search = $self->LRR_CONF->get_redis_search;

# Get all archives thru redis
# 40-character long keys only => Archive IDs
Expand Down
2 changes: 1 addition & 1 deletion lib/LANraragi/Controller/Api/Other.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use LANraragi::Utils::Plugins qw(get_plugin get_plugins get_plugin_parameters us
sub serve_serverinfo {
my $self = shift;

my $redis = $self->LRR_CONF->get_redis;
my $redis = $self->LRR_CONF->get_redis_config;
my $last_clear = $redis->hget( "LRR_SEARCHCACHE", "created" ) || time;
my $page_stat = LANraragi::Model::Stats::get_page_stat;
$redis->quit();
Expand Down
3 changes: 2 additions & 1 deletion lib/LANraragi/Controller/Api/Shinobu.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ sub reset_filemap {
# This is a shinobu endpoint even though we're deleting stuff in redis
# since we'll have to restart shinobu anyway to proc filemap re-creation.

my $redis = $self->LRR_CONF->get_redis;
my $redis = $self->LRR_CONF->get_redis_config;
$redis->del("LRR_FILEMAP");
$redis->quit();

my $shinobu = ${ retrieve( get_temp . "/shinobu.pid" ) };

Expand Down
2 changes: 1 addition & 1 deletion lib/LANraragi/Controller/Batch.pm
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ sub socket {
my $self = shift;
my $cancelled = 0;
my $client = $self->tx;
my $redis = $self->LRR_CONF->get_redis();
my $redis = $self->LRR_CONF->get_redis;

my $logger = get_logger( "Batch Tagging", "lanraragi" );

Expand Down
2 changes: 1 addition & 1 deletion lib/LANraragi/Controller/Category.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use LANraragi::Utils::Database qw(redis_decode);
sub index {

my $self = shift;
my $redis = $self->LRR_CONF->get_redis();
my $redis = $self->LRR_CONF->get_redis;
my $force = 0;

my $userlogged = $self->LRR_CONF->enable_pass == 0 || $self->session('is_logged');
Expand Down
6 changes: 4 additions & 2 deletions lib/LANraragi/Controller/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,16 @@ sub index {
enablecryptofs => $self->LRR_CONF->enable_cryptofs,
hqthumbpages => $self->LRR_CONF->get_hqthumbpages,
csshead => generate_themes_header($self),
tempsize => get_tempsize
tempsize => get_tempsize,
replacedupe => $self->LRR_CONF->get_replacedupe
);
}

# Save the given parameters to the Redis config
sub save_config {

my $self = shift;
my $redis = $self->LRR_CONF->get_redis();
my $redis = $self->LRR_CONF->get_redis_config;

my $success = 1;
my $errormess = "";
Expand Down Expand Up @@ -84,6 +85,7 @@ sub save_config {
usedatemodified => ( scalar $self->req->param('usedatemodified') ? '1' : '0' ),
enablecryptofs => ( scalar $self->req->param('enablecryptofs') ? '1' : '0' ),
hqthumbpages => ( scalar $self->req->param('hqthumbpages') ? '1' : '0' ),
replacedupe => ( scalar $self->req->param('replacedupe') ? '1' : '0' ),
);

# Only add newpassword field as password if enablepass = 1
Expand Down
2 changes: 1 addition & 1 deletion lib/LANraragi/Controller/Edit.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ sub index {
#Does the passed file exist in the database?
my $id = $self->req->param('id');

my $redis = $self->LRR_CONF->get_redis();
my $redis = $self->LRR_CONF->get_redis;

if ( $redis->exists($id) ) {
my %hash = $redis->hgetall($id);
Expand Down
2 changes: 1 addition & 1 deletion lib/LANraragi/Controller/Index.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ sub random_archive {
my $archive = "";
my $archiveexists = 0;

my $redis = $self->LRR_CONF->get_redis();
my $redis = $self->LRR_CONF->get_redis;

# We get a random archive ID.
# We check for the length to (sort-of) avoid not getting an archive ID.
Expand Down
7 changes: 1 addition & 6 deletions lib/LANraragi/Controller/Logging.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ sub print_redis {
}

sub print_mojo {

my $self = shift;

#Depending on the mode, look for development or production.log
my $mode = $self->app->mode;
print_lines_from_file( $self, $mode );
print_lines_from_file( shift, "mojo" );
}

1;
10 changes: 4 additions & 6 deletions lib/LANraragi/Controller/Plugins.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ use LANraragi::Utils::Logging qw(get_logger);
# This action will render a template
sub index {

my $self = shift;
my $redis = $self->LRR_CONF->get_redis;
my $self = shift;

#Build plugin lists, array of hashes
# Build plugin lists, array of hashes
my @metaplugins = get_plugins("metadata");
my @loginplugins = get_plugins("login");
my @scriptplugins = get_plugins("script");
my @downloadplugins = get_plugins("download");

$redis->quit();
$self->render(
template => "plugins",
title => $self->LRR_CONF->get_htmltitle,
Expand Down Expand Up @@ -72,7 +70,7 @@ sub craft_plugin_array {
sub save_config {

my $self = shift;
my $redis = $self->LRR_CONF->get_redis;
my $redis = $self->LRR_CONF->get_redis_config;

# Update settings for every plugin.
my @plugins = get_plugins("all");
Expand Down Expand Up @@ -174,7 +172,7 @@ sub process_upload {
return;
}

my $dir = getcwd() . ("/lib/LANraragi/Plugin/$plugintype/");
my $dir = getcwd() . ("/lib/LANraragi/Plugin/$plugintype/");
my $output_file = $dir . $filename;

$logger->info("Uploading new plugin $filename to $output_file ...");
Expand Down
19 changes: 19 additions & 0 deletions lib/LANraragi/Model/Archive.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ 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 All @@ -18,6 +21,22 @@ use LANraragi::Utils::Archive qw(extract_single_file extract_thumbnail);
use LANraragi::Utils::Database
qw(redis_encode redis_decode invalidate_cache set_title set_tags get_archive_json get_archive_json_multi);

# get_archive(id)
# Returns the title for the archive matching the given id.
# Returns undef if the id doesn't exist.
sub get_title($id) {

my $logger = get_logger( "Archives", "lanraragi" );
my $redis = LANraragi::Model::Config->get_redis;

if ( $id eq "" ) {
$logger->debug("No archive ID provided.");
return ();
}

return $redis->hget( $id, "title" );
}

# Functions used when dealing with archives.

# Generates an array of all the archive JSONs in the database that have existing files.
Expand Down
4 changes: 3 additions & 1 deletion lib/LANraragi/Model/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ sub get_redis_internal {
# Auto-reconnect on, one attempt every 2ms up to 3 seconds. Die after that.
my $redis = Redis->new(
server => &get_redisad,
debug => $ENV{LRR_DEVSERVER} ? "1" : "0",
reconnect => 3
);

Expand All @@ -87,7 +88,7 @@ sub get_redis_conf {
my $param = $_[0];
my $default = $_[1];

my $redis = get_redis();
my $redis = get_redis_config();

if ( $redis->hexists( "LRR_CONFIG", $param ) ) {

Expand Down Expand Up @@ -181,5 +182,6 @@ sub enable_dateadded { return &get_redis_conf( "usedateadded", "1" ) }
sub use_lastmodified { return &get_redis_conf( "usedatemodified", "0" ) }
sub enable_cryptofs { return &get_redis_conf( "enablecryptofs", "0" ) }
sub get_hqthumbpages { return &get_redis_conf( "hqthumbpages", "0" ) }
sub get_replacedupe { return &get_redis_conf( "replacedupe", "0" ) }

1;
Loading

0 comments on commit 3dbce9f

Please sign in to comment.