Skip to content

Commit

Permalink
LANraragi Release 0.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Difegue authored Jul 1, 2018
2 parents c9d325c + 51f5e0e commit d0025f7
Show file tree
Hide file tree
Showing 48 changed files with 2,018 additions and 1,449 deletions.
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
<img alt="LANraragi" src="https://raw.githubusercontent.com/Difegue/LANraragi/master/tools/logo.png" width="300">

#### [Documentation/Install Guide](https://github.com/Difegue/LANraragi/wiki) - [Download](https://github.com/Difegue/LANraragi/releases) - [Demo](https://dj.faglord.party/)
#### [Documentation/Install Guide](https://github.com/Difegue/LANraragi/wiki) - [Download](https://github.com/Difegue/LANraragi/releases) - [Demo](https://lrr.tvc-16.science/)

[<img src="https://img.shields.io/docker/pulls/difegue/lanraragi.svg">](https://hub.docker.com/r/difegue/lanraragi/) ![GitHub release](https://img.shields.io/github/release/difegue/lanraragi.svg)

Web interface and reader for archival of comics/manga, running on Mojolicious + Redis.

![](https://a.pomf.cat/vihuaz.PNG)

## Features

* Stores your comics in archive format. (zip/rar/targz/lzma/7z/xz/cbz/cbr supported)

* Read archives directly from your web browser: they're extracted automatically when you want to read them, and deleted when you're done.
* Read archives directly from your web browser: the server reads from within compressed files using temporary folders.

* Two different user interfaces : compact archive list with thumbnails-on-hover, or thumbnail view.

Expand All @@ -26,10 +24,10 @@ Web interface and reader for archival of comics/manga, running on Mojolicious +

## Screenshots


[Main Page, Thumbnail View](https://a.pomf.cat/dvquch.png)
[Main Page, List View](https://a.pomf.cat/efxoel.png)
[Archive Reader](https://a.pomf.cat/meloaj.jpg)
[Reader with overlay](https://a.pomf.cat/blndcr.jpg)
[Configuration](https://a.pomf.cat/vhzcou.png)

[Main Page, Thumbnail View](https://raw.githubusercontent.com/Difegue/LANraragi/dev/tools/_screenshots/archive_thumb.jpg)
[Main Page, List View](https://raw.githubusercontent.com/Difegue/LANraragi/dev/tools/_screenshots/archive_list.png)
[Archive Reader](https://raw.githubusercontent.com/Difegue/LANraragi/dev/tools/_screenshots/reader.jpg)
[Reader with overlay](https://raw.githubusercontent.com/Difegue/LANraragi/dev/tools/_screenshots/reader_overlay.jpg)
[Configuration](https://raw.githubusercontent.com/Difegue/LANraragi/dev/tools/_screenshots/cfg.png)
[Plugin Configuration](https://raw.githubusercontent.com/Difegue/LANraragi/dev/tools/_screenshots/cfg_plugin.png)
36 changes: 22 additions & 14 deletions lib/LANraragi.pm
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package LANraragi;

use local::lib;

use open ':std', ':encoding(UTF-8)';

use Mojo::Base 'Mojolicious';

use Mojo::IOLoop::ProcBackground;
Expand Down Expand Up @@ -31,14 +33,14 @@ sub startup {
#Remove upload limit
$self->max_request_size(0);

#Helper so controllers can reach the app's Redis DB quickly
#Helper so controllers can reach the app's Redis DB quickly
#(they still need to declare use Model::Config)
$self->helper( LRR_CONF => sub { LANraragi::Model::Config:: } );

#Second helper to build logger objects quickly
$self->helper(
LRR_LOGGER => sub {
return LANraragi::Model::Utils::get_logger( "LANraragi",
return LANraragi::Utils::Generic::get_logger( "LANraragi",
"lanraragi" );
}
);
Expand Down Expand Up @@ -80,20 +82,24 @@ sub startup {
#Check if a Redis server is running on the provided address/port
$self->LRR_CONF->get_redis;

#Start Background worker
#Start Background worker
if ( -e "./shinobu-pid" ) {

#Read PID from file
open( my $pidfile, '<', "shinobu-pid" ) || die( "cannot open file: " . $! );
open( my $pidfile, '<', "shinobu-pid" )
|| die( "cannot open file: " . $! );
my $pid = <$pidfile>;
close( $pidfile );
close($pidfile);

$self->LRR_LOGGER->info("Terminating previous Shinobu Worker... (PID is $pid)");
$self->LRR_LOGGER->info(
"Terminating previous Shinobu Worker... (PID is $pid)");

#This is the only cross-platform check in the entire app so we're pretty good I think
if ($^O eq "MSWin32") {
#TASKKILL seems superflous on Windows as sub-PIDs are always cleanly killed when the main process dies
#But you can never be safe enough
if ( $^O eq "MSWin32" ) {
`TASKKILL /F /T /PID $pid`;
} else {
}
else {
`kill -9 $pid`;
}

Expand All @@ -116,11 +122,11 @@ sub startup {

$proc->run( [ $^X, "./lib/Shinobu.pm" ] );

#Create file to store the process' PID
#Create file to store the process' PID
open( my $pidfile, '>', "shinobu-pid" ) || die( "cannot open file: " . $! );
my $newpid = $proc->proc->pid;
print $pidfile $newpid;
close( $pidfile );
close($pidfile);

$self->LRR_LOGGER->debug("Shinobu Worker PID is $newpid");

Expand All @@ -134,15 +140,16 @@ sub startup {
my $logged_in = $r->under('/')->to('login#logged_in');

#No-Fun Mode locks the base routes behind login as well
if ($self->LRR_CONF->enable_nofun) {
if ( $self->LRR_CONF->enable_nofun ) {
$logged_in->get('/')->to('index#index');
$logged_in->get('/index')->to('index#index');
$logged_in->get('/random')->to('index#random_archive');
$logged_in->get('/reader')->to('reader#index');
$logged_in->get('/api/thumbnail')->to('api#serve_thumbnail');
$logged_in->get('/api/servefile')->to('api#serve_file');
$logged_in->get('/stats')->to('stats#index');
} else {
}
else {
#Standard behaviour is to leave those routes loginless for all clients
$r->get('/')->to('index#index');
$r->get('/index')->to('index#index');
Expand All @@ -151,14 +158,15 @@ sub startup {
$r->get('/api/thumbnail')->to('api#serve_thumbnail');
$r->get('/api/servefile')->to('api#serve_file');
$r->get('/stats')->to('stats#index');
}
}

#Those routes are only accessible if user is logged in
$logged_in->get('/config')->to('config#index');
$logged_in->post('/config')->to('config#save_config');

$logged_in->get('/config/plugins')->to('plugins#index');
$logged_in->post('/config/plugins')->to('plugins#save_config');
$logged_in->post('/config/plugins/upload')->to('plugins#process_upload');

$logged_in->get('/edit')->to('edit#index');
$logged_in->post('/edit')->to('edit#save_metadata');
Expand Down
73 changes: 16 additions & 57 deletions lib/LANraragi/Controller/Api.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use Encode;
use File::Find::utf8;
use File::Path qw(remove_tree);

use LANraragi::Model::Utils;
use LANraragi::Utils::Generic;
use LANraragi::Utils::Archive;
use LANraragi::Utils::Database;

use LANraragi::Model::Config;
use LANraragi::Model::Plugins;

Expand Down Expand Up @@ -36,7 +39,7 @@ sub clean_tempfolder {
$cleanmsg = "General error: $message\n";
}
else {
$self->LRR_LOGGER->error( "Problem unlinking $file: $message" );
$self->LRR_LOGGER->error("Problem unlinking $file: $message");
$cleanmsg = "Problem unlinking $file: $message\n";
}
}
Expand Down Expand Up @@ -65,61 +68,14 @@ sub serve_thumbnail {
my $thumbname = $dirname . "/thumb/" . $id . ".jpg";

unless ( -e $thumbname ) {
mkdir $dirname . "/thumb";
my $redis = $self->LRR_CONF->get_redis();

my $file = $redis->hget( $id, "file" );
$file = LANraragi::Model::Utils::redis_decode($file);

my $path = "./public/temp/thumb";

#delete everything in thumb temp to prevent file mismatch errors.
unlink glob $path . "/*.*";

#Get lsar's output, jam it in an array, and use it as @extracted.
my $vals = `lsar "$file"`;
my @lsarout = split /\n/, $vals;
my @extracted;

#The -i 0 option on unar doesn't always return the first image, so we gotta rely on lsar.
#Sort on the lsar output to find the first image.
foreach my $lsarfile (@lsarout) {
#is it an image? lsar can give us folder names.
if ( $lsarfile =~ /^(.*\/)*.+\.(png|jpg|gif|bmp|jpeg|PNG|JPG|GIF|BMP)$/) {
push @extracted, $lsarfile;
}
}

@extracted = sort { lc($a) cmp lc($b) } @extracted;
$thumbname =
LANraragi::Utils::Archive::extract_thumbnail( $dirname, $id );

#unar sometimes crashes on certain folder names inside archives. To solve that, we replace folder names with the wildcard * through regex.
my $unarfix = $extracted[0];
$unarfix =~ s/[^\/]+\//*\//g;

#let's extract now.
my $res = `unar -D -o $path "$file" "$unarfix"`;

if ($?) {
$self->LRR_LOGGER->error( "Error extracting thumbnail: $res" );
}

#Path to the first image of the archive
my $arcimg = $path . '/' . $extracted[0];

#While we have the image, grab its SHA-1 hash for potential tag research later.
#That way, no need to repeat the costly extraction later.
my $shasum = LANraragi::Model::Utils::shasum( $arcimg, 1 );
$redis->hset( $id, "thumbhash", encode_utf8($shasum) );

#Thumbnail generation
LANraragi::Model::Utils::generate_thumbnail( $arcimg, $thumbname );

#Delete the previously extracted file.
unlink $arcimg;
}

#Simply serve the thumbnail. If it doesn't exist, serve an error placeholder instead.
if (-e $thumbname) {
#Simply serve the thumbnail. If it doesn't exist, serve an error placeholder instead.
if ( -e $thumbname ) {
$self->render_file( filepath => $thumbname );
}
else {
Expand All @@ -131,7 +87,7 @@ sub serve_thumbnail {
sub force_refresh {

my $self = shift;
LANraragi::Model::Utils::invalidate_cache();
LANraragi::Utils::Database::invalidate_cache();

$self->render(
json => {
Expand All @@ -151,7 +107,9 @@ sub use_enabled_plugins {
my $id = $self->req->param('id');
my $redis = $self->LRR_CONF->get_redis();

if ( $redis->hexists( $id, "title" ) && LANraragi::Model::Config::enable_autotag ) {
if ( $redis->hexists( $id, "title" )
&& LANraragi::Model::Config::enable_autotag )
{

my ( $succ, $fail ) =
LANraragi::Model::Plugins::exec_enabled_plugins_on_file($id);
Expand All @@ -173,7 +131,8 @@ sub use_enabled_plugins {
operation => "autotag",
id => $id,
success => 0,
message => "ID not found in database or AutoTagging disabled by admin."
message =>
"ID not found in database or AutoTagging disabled by admin."
}
);
}
Expand Down Expand Up @@ -202,7 +161,7 @@ sub use_plugin {
#Get the matching argument in Redis
my $namerds = "LRR_PLUGIN_" . uc($namespace);
my $globalarg = $redis->hget( $namerds, "customarg" );
$globalarg = LANraragi::Model::Utils::redis_decode($globalarg);
$globalarg = LANraragi::Utils::Database::redis_decode($globalarg);

#Finally, execute the plugin
my %plugin_result =
Expand Down
11 changes: 7 additions & 4 deletions lib/LANraragi/Controller/Backup.pm
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package LANraragi::Controller::Backup;
use Mojo::Base 'Mojolicious::Controller';

use LANraragi::Model::Utils;
use LANraragi::Utils::Generic;
use LANraragi::Utils::Archive;
use LANraragi::Utils::Database;

use LANraragi::Model::Config;
use LANraragi::Model::Backup;

Expand All @@ -13,7 +16,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 @@ -31,7 +34,7 @@ sub index {
$self->render(
template => "backup",
title => $self->LRR_CONF->get_htmltitle,
cssdrop => LANraragi::Model::Utils::generate_themes
cssdrop => LANraragi::Utils::Generic::generate_themes
);
}
}
Expand All @@ -41,7 +44,7 @@ sub restore {
my $file = $self->req->upload('file');

if ( $file->headers->content_type eq "application/json" ) {

my $json = $file->slurp;
LANraragi::Model::Backup::restore_from_JSON($json);

Expand Down
Loading

0 comments on commit d0025f7

Please sign in to comment.