Skip to content

Commit

Permalink
LANraragi Release 0.8.3
Browse files Browse the repository at this point in the history
Merge pull request #548 from Difegue/dev
  • Loading branch information
Difegue committed Nov 24, 2021
2 parents de298af + c4884be commit 2ad9c57
Show file tree
Hide file tree
Showing 88 changed files with 954 additions and 1,427 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-delivery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
with:
args: 'Windows Installer built and available on the Release page! 🐱‍🐉'
args: 'Windows Installer built and available on the Release page! :logo:🪟'

buildLatestDocker:
name: Build Latest Docker image
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ npm-debug.log
dump.rdb
package-lock.json
.vstags
.gitbook
*qemu-*-static*
Dockerfile.*
.DS_Store
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Open source server for archival of comics/manga, running on Mojolicious + Redis.

#### 💬 Talk with other fellow LANraragi Users on [Discord](https://discord.gg/aRQxtbg) or [Github Discussions](https://github.com/Difegue/LANraragi/discussions)

#### [📄 Documentation](https://sugoi.gitbook.io/lanraragi/) | [⏬ Download](https://github.com/Difegue/LANraragi/releases/latest) | [🎞 Demo](https://lrr.tvc-16.science) | [🐱‍👓 Windows Nightlies](https://nightly.link/Difegue/LANraragi/workflows/push-continous-delivery/dev) | [💵 Sponsor Development](https://ko-fi.com/T6T2UP5N)
#### [📄 Documentation](https://sugoi.gitbook.io/lanraragi/) | [⏬ Download](https://github.com/Difegue/LANraragi/releases/latest) | [🎞 Demo](https://lrr.tvc-16.science) | [🪟🌃 Windows Nightlies](https://nightly.link/Difegue/LANraragi/workflows/push-continous-delivery/dev) | [💵 Sponsor Development](https://ko-fi.com/T6T2UP5N)

## The 2021 User Survey results have landed!

Expand Down
11 changes: 9 additions & 2 deletions lib/LANraragi/Model/Archive.pm
Original file line number Diff line number Diff line change
Expand Up @@ -166,21 +166,28 @@ sub serve_page {

my $logger = get_logger( "File Serving", "lanraragi" );

$logger->debug("Page /$id/$path was requested");

my $tempfldr = get_temp();
my $file = LANraragi::Utils::Archive::sanitize_filename( $tempfldr . "/$id/$path" );
my $file = $tempfldr . "/$id/$path";

if ( -e $file ) {

# Freshly created files might not be complete yet.
# We have to wait before trying to serve them out...
my $last_size = 0;
my $size = -s $file;
my $timeout = 0;
while (1) {
$logger->debug("Waiting for file to be fully written ($size, previously $last_size)");
usleep(10000); # 10ms
$timeout += 10; # Sanity check in case the file remains at 0 bytes forever
$last_size = $size;
$size = -s $file;
last if ( $last_size eq $size ); # If the size hasn't changed since the last loop, it's likely the file is ready.

# If the size hasn't changed since the last loop, it's likely the file is ready.
last
if ( $last_size eq $size && ( $size ne 0 || $timeout > 1000 ) );
}

} else {
Expand Down
16 changes: 1 addition & 15 deletions lib/LANraragi/Model/Reader.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ use LANraragi::Utils::Generic qw(is_image shasum);
use LANraragi::Utils::Archive qw(extract_archive generate_thumbnail get_filelist);
use LANraragi::Utils::Database qw(redis_decode);

#magical sort function used below
sub expand {
my $file = shift;
$file =~ s{(\d+)}{sprintf "%04d", $1}eg;
return $file;
}

# resize_image(image,quality, size_threshold)
# Convert an image to a cheaper on bandwidth format through ImageMagick.
sub resize_image {
Expand Down Expand Up @@ -68,12 +61,7 @@ sub build_reader_JSON {
# Parse archive to get its list of images
my @images = get_filelist($archive);

# TODO: @images = nsort(@images); would theorically be better, but Sort::Naturally's nsort puts letters before numbers,
# which isn't what we want at all for pages in an archive.
# To investigate further, perhaps with custom sorting algorithms?
@images = sort { &expand($a) cmp &expand($b) } @images;

$self->LRR_LOGGER->debug( "Files found in archive: \n " . Dumper @images );
$self->LRR_LOGGER->debug( "Files found in archive (encoding might be incorrect): \n " . Dumper @images );

# Build a browser-compliant filepath array from @images
my @images_browser;
Expand All @@ -92,8 +80,6 @@ sub build_reader_JSON {
# Then we bring the slashes back.
$imgpath =~ s!%2F!/!g;

$self->LRR_LOGGER->debug("Will be extracted to disk as: $imgpath");

# Bundle this path into an API call which will be used by the browser
push @images_browser, "./api/archives/$id/page?path=$imgpath";
}
Expand Down
99 changes: 53 additions & 46 deletions lib/LANraragi/Utils/Archive.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use strict;
use warnings;
use utf8;

use feature qw(say);
use Time::HiRes qw(gettimeofday);
use File::Basename;
use File::Path qw(remove_tree make_path);
Expand All @@ -15,6 +16,7 @@ use Redis;
use Cwd;
use Data::Dumper;
use Image::Magick;
use Archive::Libarchive qw( ARCHIVE_OK );
use Archive::Libarchive::Extract;
use Archive::Libarchive::Peek;

Expand Down Expand Up @@ -47,37 +49,14 @@ sub generate_thumbnail {
undef $img;
}

# sanitize_filename(filename)
# Converts extracted filenames to an ascii variant to avoid extra filesystem headaches.
sub sanitize_filename {

my $filename = $_[0];
eval {
# Try a guess to regular japanese encodings first
$filename = decode( "Guess", $filename );
};

# Fallback to utf8
$filename = decode_utf8($filename) if $@;

# Re-encode the result to ASCII and move the file to said result name.
# Use Encode's coderef feature to map non-ascii characters to their Unicode codepoint equivalent.
$filename = encode( "ascii", $filename, sub { sprintf "%04X", shift } );

if ( length $filename > 254 ) {
$filename = substr( $filename, 0, 254 );
}

return $filename;
}

# extract_archive(path, archive_to_extract, force)
# Extract the given archive to the given path.
# This sub won't re-extract files already present in the destination unless force = 1.
sub extract_archive {

my ( $destination, $to_extract, $force_extract ) = @_;
my $logger = get_logger( "Archive", "lanraragi" );
$logger->debug("Fully extracting archive $to_extract");

# PDFs are handled by Ghostscript (alas)
if ( is_pdf($to_extract) ) {
Expand All @@ -92,14 +71,16 @@ sub extract_archive {
if ($force_extract) { return 1; }

my $filename = $e->pathname;
$filename = sanitize_filename($filename);
if ( -e "$destination/$filename" ) {
$logger->debug("$filename already exists in $destination");
return 0;
}
$logger->debug("Extracting $filename");

# Pre-emptively create the file to signal we're working on it
open( my $fh, ">", "$destination/$filename" ) or return 0;
open( my $fh, ">", "$destination/$filename" )
or
$logger->error("Couldn't create placeholder file $destination/$filename (might be a folder?), moving on nonetheless");
close $fh;
return 1;
}
Expand All @@ -112,16 +93,6 @@ sub extract_archive {
my $result_dir = $ae->to;
my $cwd = getcwd();

# Rename extracted files and folders to an encoded version for easier handling
finddepth(
sub {
unless ( $_ eq '.' ) {
move( $_, sanitize_filename($_) );
}
},
$result_dir
);

# chdir back to the base cwd in case finddepth died midway
chdir $cwd;

Expand Down Expand Up @@ -202,31 +173,58 @@ sub extract_thumbnail {
return $thumbname;
}

#magical sort function used below
sub expand {
my $file = shift;
$file =~ s{(\d+)}{sprintf "%04d", $1}eg;
return $file;
}

# get_filelist($archive)
# Returns a list of all the files contained in the given archive.
sub get_filelist {

my $archive = $_[0];
my @files = ();
my @sizes = ();

if ( is_pdf($archive) ) {

# For pdfs, extraction returns images from 1.jpg to x.jpg, where x is the pdf pagecount.
my $pages = `gs -q -c "($archive) (r) file runpdfbegin pdfpagecount = quit"`;
for my $num ( 1 .. $pages ) {
push @files, "$num.jpg";
push @sizes, 0;
}
} else {
my $peek = Archive::Libarchive::Peek->new( filename => $archive );

# Filter out non-images
foreach my $file ( $peek->files ) {
if ( is_image($file) ) {
push @files, $file;
my $r = Archive::Libarchive::ArchiveRead->new;
$r->support_filter_all;
$r->support_format_all;

my $ret = $r->open_filename( $archive, 10240 );
die unless ( $ret == ARCHIVE_OK );

my $e = Archive::Libarchive::Entry->new;
while ( $r->next_header($e) == ARCHIVE_OK ) {

my $filesize = ( $e->size_is_set eq 64 ) ? $e->size : 0;
my $filename = $e->pathname;
if ( is_image($filename) ) {
push @files, $filename;
push @sizes, $filesize;
}
$r->read_data_skip;
}

}

# TODO: @images = nsort(@images); would theorically be better, but Sort::Naturally's nsort puts letters before numbers,
# which isn't what we want at all for pages in an archive.
# To investigate further, perhaps with custom sorting algorithms?
@files = sort { &expand($a) cmp &expand($b) } @files;

# TODO: Return file and sizes in a hash
return @files;
}

Expand Down Expand Up @@ -291,18 +289,27 @@ sub extract_single_file {
} else {

my $contents = "";
my $peek = Archive::Libarchive::Peek->new( filename => $archive );
$contents = $peek->file($filepath);
my $peek = Archive::Libarchive::Peek->new( filename => $archive );
my @files = $peek->files;

for my $name (@files) {
my $decoded_name = LANraragi::Utils::Database::redis_decode($name);

# This sub can receive either encoded or raw filenames, so we have to test for both.
if ( $decoded_name eq $filepath || $name eq $filepath ) {
$logger->debug("Found file $filepath in archive $archive");
$contents = $peek->file($name);
last;
}
}

open( my $fh, '>', $outfile )
or die "Could not open file '$outfile' $!";
print $fh $contents;
close $fh;
}

my $fixed_name = sanitize_filename($outfile);
move( $outfile, $fixed_name );
return $fixed_name;
return $outfile;
}

# extract_file_from_archive($archive, $file)
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "lanraragi",
"version": "0.8.2",
"version_name": "Nite Flights",
"version": "0.8.3",
"version_name": "Nite Flights (Moodswings Back to Basics Mix)",
"description": "I'm under Japanese influence and my honor's at stake!",
"scripts": {
"test": "prove -r -l -v tests/",
Expand Down Expand Up @@ -45,4 +45,4 @@
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.22.1"
}
}
}
2 changes: 1 addition & 1 deletion public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Index.initializeAll = function () {
Server.callAPI("/api/info", "GET", null, "Error getting basic server info!", (data) => {
Index.serverVersion = data.version;
Index.debugMode = data.debug_mode === "1";
Index.isProgressLocal = data.server_tracks_progress === "1";
Index.isProgressLocal = data.server_tracks_progress !== "1";
Index.pageSize = data.archives_per_page;

// Check version if not in debug mode
Expand Down
2 changes: 1 addition & 1 deletion templates/plugins.html.tt2
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

</head>

<body>
<body onload="initUpload()">

<div class="ido" style="text-align:center;">
<h1 class="ih" style="text-align:center">Plugin Configuration</h1>
Expand Down
Binary file not shown.
Binary file removed tools/Documentation/.gitbook/assets/batch.png
Binary file not shown.
Binary file not shown.
Binary file removed tools/Documentation/.gitbook/assets/edit.PNG
Binary file not shown.
Binary file removed tools/Documentation/.gitbook/assets/index.png
Binary file not shown.
Binary file not shown.
Binary file removed tools/Documentation/.gitbook/assets/themes.png
Binary file not shown.
1 change: 1 addition & 0 deletions tools/Documentation/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.gitbook
Binary file added tools/Documentation/.screenshots/batch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added tools/Documentation/.screenshots/edit.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tools/Documentation/.screenshots/karen.jpg
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added tools/Documentation/.screenshots/themes.png
18 changes: 13 additions & 5 deletions tools/Documentation/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
---
cover: ../_screenshots/archive_thumb.png
coverY: -164.01117318435755
---

# LANraragi Documentation

_I know when to go out_
_Know when to stay in_
_I know when to go out_\
_Know when to stay in_\
_Get things done_

Thank you for showing interest in this networked chinese comic reading software.

Just getting started? Check out how to install the software:

{% page-ref page="installing-lanraragi/methods.md" %}
{% content-ref url="installing-lanraragi/methods.md" %}
[methods.md](installing-lanraragi/methods.md)
{% endcontent-ref %}

Or how to use your freshly installed instance:

{% page-ref page="basic-operations/first-steps.md" %}

{% content-ref url="basic-operations/first-steps.md" %}
[first-steps.md](basic-operations/first-steps.md)
{% endcontent-ref %}
Loading

0 comments on commit 2ad9c57

Please sign in to comment.