Skip to content

Commit

Permalink
(#287) PerlTidy pass + commit in .perltidyrc
Browse files Browse the repository at this point in the history
  • Loading branch information
Difegue committed May 20, 2020
1 parent 82284d8 commit 683eea3
Show file tree
Hide file tree
Showing 42 changed files with 876 additions and 924 deletions.
6 changes: 6 additions & 0 deletions .perltidyrc
@@ -0,0 +1,6 @@
-bar
-ce
-vt=2
-nsfs
-nolq
-l=132
28 changes: 11 additions & 17 deletions lib/LANraragi.pm
Expand Up @@ -29,8 +29,8 @@ sub startup {
my $config = $self->plugin( 'Config', { file => 'lrr.conf' } );

# Load package.json to get version/vername
my $packagejson = decode_json(Mojo::File->new('package.json')->slurp);
my $packagejson = decode_json( Mojo::File->new('package.json')->slurp );

my $version = $packagejson->{version};
my $vername = $packagejson->{version_name};

Expand Down Expand Up @@ -70,8 +70,7 @@ sub startup {

if ($devmode) {
$self->mode('development');
$self->LRR_LOGGER->info(
"LANraragi $version (re-)started. (Debug Mode)");
$self->LRR_LOGGER->info("LANraragi $version (re-)started. (Debug Mode)");

#Tell the mojo logger to print to stdout as well
$self->log->on(
Expand All @@ -83,11 +82,9 @@ sub startup {
print "\n";
}
);
}
else {
} else {
$self->mode('production');
$self->LRR_LOGGER->info(
"LANraragi $version started. (Production Mode)");
$self->LRR_LOGGER->info("LANraragi $version started. (Production Mode)");
}

#Plugin listing
Expand All @@ -104,28 +101,25 @@ sub startup {
}

#Start Background worker
if ( -e "./.shinobu-pid" && eval { retrieve("./.shinobu-pid"); }) {
if ( -e "./.shinobu-pid" && eval { retrieve("./.shinobu-pid"); } ) {

# Deserialize process
my $proc = ${retrieve("./.shinobu-pid")};
my $proc = ${ retrieve("./.shinobu-pid") };
my $pid = $proc->pid;

$self->LRR_LOGGER->info(
"Terminating previous Shinobu Worker if it exists... (PID is $pid)"
);
$proc->kill();
$self->LRR_LOGGER->info("Terminating previous Shinobu Worker if it exists... (PID is $pid)");
$proc->kill();
}

my $proc = start_shinobu();
$self->LRR_LOGGER->debug(
"Shinobu Worker new PID is " . $proc->pid );
$self->LRR_LOGGER->debug( "Shinobu Worker new PID is " . $proc->pid );

LANraragi::Utils::Routing::apply_routes($self);
$self->LRR_LOGGER->info("Routing done! Ready to receive requests.");

# Warm search cache
$self->LRR_LOGGER->info("Warming up search cache...");
LANraragi::Model::Search::do_search("","",0,"title","asc", 0, 0);
LANraragi::Model::Search::do_search( "", "", 0, "title", "asc", 0, 0 );
$self->LRR_LOGGER->info("Done!");
}

Expand Down
87 changes: 40 additions & 47 deletions lib/LANraragi/Controller/Api.pm
Expand Up @@ -26,29 +26,27 @@ sub check_id_parameter {
my ( $mojo, $endpoint ) = @_;

my $id = $mojo->req->param('id') || 0;
unless ( $id ) {
unless ($id) {

#High-level API documentation!
$mojo->render(
json => {
error => "API usage: $endpoint?id=YOUR_ID"
},
status => 400
json => { error => "API usage: $endpoint?id=YOUR_ID" },
status => 400
);
}
return $id;
}

# Renders the basic success API JSON template.
sub success {
my ($mojo, $operation) = @_;
my ( $mojo, $operation ) = @_;

$mojo->render(
json => {
operation => $operation,
success => 1
}
);
json => {
operation => $operation,
success => 1
}
);
}

sub serve_archivelist {
Expand All @@ -58,8 +56,8 @@ sub serve_archivelist {
}

sub serve_opds {
my $self = shift;
$self->render( text => LANraragi::Model::Api::generate_opds_catalog($self), format => 'xml');
my $self = shift;
$self->render( text => LANraragi::Model::Api::generate_opds_catalog($self), format => 'xml' );
}

sub serve_untagged_archivelist {
Expand All @@ -70,17 +68,17 @@ sub serve_untagged_archivelist {

sub serve_tag_stats {
my $self = shift;
$self->render( json => from_json(LANraragi::Model::Stats::build_tag_json));
$self->render( json => from_json(LANraragi::Model::Stats::build_tag_json) );
}

sub serve_backup {
my $self = shift;
$self->render( json => from_json(LANraragi::Model::Backup::build_backup_JSON));
$self->render( json => from_json(LANraragi::Model::Backup::build_backup_JSON) );
}

sub drop_database {
LANraragi::Utils::Database::drop_database();
success(shift, "drop_database");
success( shift, "drop_database" );
}

sub clean_database {
Expand All @@ -97,7 +95,7 @@ sub clean_database {

sub clear_cache {
invalidate_cache();
success(shift, "clear_cache");
success( shift, "clear_cache" );
}

# Uses a plugin, with the standard global arguments and a provided oneshot argument.
Expand All @@ -108,15 +106,15 @@ sub use_plugin {

sub serve_thumbnail {
my $self = shift;
my $id = check_id_parameter($self, "thumbnail") || return;
LANraragi::Model::Api::serve_thumbnail($self, $id);
my $id = check_id_parameter( $self, "thumbnail" ) || return;
LANraragi::Model::Api::serve_thumbnail( $self, $id );
}

# Use RenderFile to get the file of the provided id to the client.
sub serve_file {

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

my $file = $redis->hget( $id, "file" );
Expand All @@ -126,30 +124,25 @@ sub serve_file {

# Serve an archive page from the temporary folder, using RenderFile.
sub serve_page {
my $self = shift;
my $id = check_id_parameter($self, "servefile") || return;
LANraragi::Model::Api::serve_page($self, $id);
my $self = shift;
my $id = check_id_parameter( $self, "servefile" ) || return;
LANraragi::Model::Api::serve_page( $self, $id );
}

sub extract_archive {
my $self = shift;
my $id = check_id_parameter($self, "extract") || return;
my $id = check_id_parameter( $self, "extract" ) || return;
my $readerjson;

eval {
$readerjson =
LANraragi::Model::Reader::build_reader_JSON( $self, $id, "0", "0" );
};
eval { $readerjson = LANraragi::Model::Reader::build_reader_JSON( $self, $id, "0", "0" ); };
my $err = $@;

if ($err) {
$self->render(
json => {
error => $err
},
status => 500);
}
else {
$self->render(
json => { error => $err },
status => 500
);
} else {
$self->render( json => decode_json($readerjson) );
}
}
Expand All @@ -173,12 +166,13 @@ sub clean_tempfolder {

sub clear_new {
my $self = shift;
my $id = check_id_parameter($self, "clear_new") || return;
my $id = check_id_parameter( $self, "clear_new" ) || return;

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

# Just set isnew to false for the provided ID.
if ($redis->hget( $id, "isnew") ne "false") {
if ( $redis->hget( $id, "isnew" ) ne "false" ) {

# Bust search cache...partially!
LANraragi::Utils::Database::invalidate_isnew_cache();

Expand All @@ -198,12 +192,12 @@ sub clear_new {
#Clear new flag in all archives.
sub clear_new_all {

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

# Get all archives thru redis
# 40-character long keys only => Archive IDs
my @keys = $redis->keys('????????????????????????????????????????');
my @keys = $redis->keys('????????????????????????????????????????');

foreach my $idall (@keys) {
$redis->hset( $idall, "isnew", "false" );
Expand All @@ -212,21 +206,20 @@ sub clear_new_all {
# Bust search cache completely, this is a big change
invalidate_cache();
$redis->quit();
success($self, "clear_new_all");
success( $self, "clear_new_all" );
}

#Use all enabled plugins on an archive ID. Tags are automatically saved in the background.
#Returns number of successes and failures.
sub use_enabled_plugins {

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

if ( $redis->exists($id) && LANraragi::Model::Config->enable_autotag ) {

my ( $succ, $fail, $addedtags ) =
LANraragi::Model::Plugins::exec_enabled_plugins_on_file($id);
my ( $succ, $fail, $addedtags ) = LANraragi::Model::Plugins::exec_enabled_plugins_on_file($id);

$self->render(
json => {
Expand All @@ -251,7 +244,7 @@ sub use_enabled_plugins {

sub shinobu_status {
my $self = shift;
my $shinobu = ${retrieve("./.shinobu-pid")};
my $shinobu = ${ retrieve("./.shinobu-pid") };

$self->render(
json => {
Expand All @@ -264,16 +257,16 @@ sub shinobu_status {

sub stop_shinobu {
my $self = shift;
my $shinobu = ${retrieve("./.shinobu-pid")};
my $shinobu = ${ retrieve("./.shinobu-pid") };

#commit sudoku
$shinobu->kill();
success($self, "shinobu_stop");
success( $self, "shinobu_stop" );
}

sub restart_shinobu {
my $self = shift;
my $shinobu = ${retrieve("./.shinobu-pid")};
my $shinobu = ${ retrieve("./.shinobu-pid") };

#commit sudoku
$shinobu->kill();
Expand Down
8 changes: 3 additions & 5 deletions lib/LANraragi/Controller/Backup.pm
Expand Up @@ -12,7 +12,7 @@ sub index {
if ( $self->req->param('dobackup') ) {
my $json = LANraragi::Model::Backup::build_backup_JSON();

#Write json to file in the user directory and serve that file through render_static
#Write json to file in the user directory and serve that file through render_static
my $file = $self->LRR_CONF->get_userdir . '/backup.json';

if ( -e $file ) { unlink $file }
Expand All @@ -25,8 +25,7 @@ sub index {

$self->render_file( filepath => $file );

}
else { #Get with no parameters => Regular HTML printout
} else { #Get with no parameters => Regular HTML printout
$self->render(
template => "backup",
title => $self->LRR_CONF->get_htmltitle,
Expand All @@ -52,8 +51,7 @@ sub restore {
success => 1
}
);
}
else {
} else {
$self->render(
json => {
operation => "restore_backup",
Expand Down

0 comments on commit 683eea3

Please sign in to comment.