Skip to content

Commit

Permalink
LANraragi Release 0.8.6
Browse files Browse the repository at this point in the history
Merge pull request #663 from Difegue/dev
  • Loading branch information
Difegue committed Jul 26, 2022
2 parents 0edd1b2 + 4cb3b36 commit 3e25a66
Show file tree
Hide file tree
Showing 97 changed files with 4,449 additions and 1,730 deletions.
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
3000
],
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "sudo service redis-server start",
"postCreateCommand": "npm run lanraragi-installer install-front && sudo service redis-server start",
// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "koyomi"
}
}
3 changes: 1 addition & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
tools/_screenshots
tools/Documentation
tools/build/windows
tools/build/homebrew
tools/build/vagrant
tools/build/homebrew
8 changes: 6 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"jquery": true
},
"extends": [
"airbnb-base"
"airbnb-base",
"eslint:recommended"
],
"parserOptions": {
"ecmaVersion": 12,
Expand All @@ -23,6 +24,7 @@
"IndexTable": "readonly",
"Swiper": "readonly"
},
"ignorePatterns": ["**/vendor/*.js"],
"rules": {
"func-names": ["error", "never"],
"indent": ["error", 4],
Expand All @@ -41,6 +43,8 @@
],
"one-var": "off",
"one-var-declaration-per-line": ["error", "initializations"],
"prefer-destructuring": ["error", {"object": true, "array": false}]
"prefer-destructuring": ["error", {"object": true, "array": false}],
"function-paren-newline": "off",
"function-call-argument-newline": "off"
}
}
1 change: 0 additions & 1 deletion .github/workflows/push-brewtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ jobs:
cd tools/build/homebrew
echo "Replacing commit hash in formula with current hash $(git rev-parse --verify HEAD)"
sed -i.bck "s/COMMIT_HASH/$(git rev-parse --verify HEAD)/" Lanraragi.rb
brew unlink node@14
brew install --force --verbose --build-from-source Lanraragi.rb
brew test --verbose Lanraragi.rb
3 changes: 2 additions & 1 deletion .github/workflows/push-continous-delivery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
branches:
- dev
- test-builds
- actions-testing
name: Continuous Delivery
jobs:
buildNightlyDocker:
Expand Down Expand Up @@ -43,7 +44,7 @@ jobs:
- uses: actions/checkout@master
- name: Docker Build and export
run: |
docker build -t difegue/lanraragi -f ./tools/build/docker/Dockerfile .
docker build -t difegue/lanraragi -f ./tools/build/docker/Dockerfile-legacy .
docker create --name rootfs difegue/lanraragi
docker export --output=package.tar rootfs
- name: Upload rootfs
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ LANraragi

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)
#### 💬 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/v/dev) | [⏬ 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)

Expand Down
17 changes: 2 additions & 15 deletions lib/LANraragi/Controller/Api/Archive.pm
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,12 @@ sub get_categories {
my $self = shift;
my $id = check_id_parameter( $self, "find_arc_categories" ) || return;

my @categories = LANraragi::Model::Category->get_category_list;
@categories = grep { %$_{"search"} eq "" } @categories;

my @filteredcats = ();

# Check if the id is in any categories
for my $category (@categories) {

my @archives = @{ $category->{"archives"} };

if ( grep( /^$id$/, @archives ) ) {
push @filteredcats, $category;
}
}
my @categories = LANraragi::Model::Category::get_categories_containing_archive($id);

$self->render(
json => {
operation => "find_arc_categories",
categories => \@filteredcats,
categories => \@categories,
success => 1
}
);
Expand Down
4 changes: 2 additions & 2 deletions lib/LANraragi/Controller/Api/Search.pm
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ sub handle_api {
my $start = $req->param('start');
my $sortkey = $req->param('sortby');
my $sortorder = $req->param('order');
my $newfilter = $req->param('newonly');
my $untaggedf = $req->param('untaggedonly');
my $newfilter = $req->param('newonly') || "false";
my $untaggedf = $req->param('untaggedonly') || "false";

$sortorder = ( $sortorder && $sortorder eq 'desc' ) ? 1 : 0;

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 @@ -7,7 +7,7 @@ use Mojo::JSON qw(decode_json);

use LANraragi::Utils::Generic qw(generate_themes_header);
use LANraragi::Utils::Tags qw(rewrite_tags split_tags_to_array restore_CRLF);
use LANraragi::Utils::Database qw(redis_decode get_computed_tagrules);
use LANraragi::Utils::Database qw(get_computed_tagrules);
use LANraragi::Utils::Plugins qw(get_plugins get_plugin get_plugin_parameters);
use LANraragi::Utils::Logging qw(get_logger);

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 @@ -37,7 +37,7 @@ sub index {

if ( -e $zipfile ) {
$arclist .=
"<li><input type='checkbox' name='archive' id='$id' class='archive' onchange='updateArchiveInCategory(this.id, this.checked)'>";
"<li><input type='checkbox' name='archive' id='$id' class='archive' onchange='Category.updateArchiveInCategory(this.id, this.checked)'>";
$arclist .= "<label for='$id'> $title</label></li>";
}
}
Expand Down
8 changes: 6 additions & 2 deletions lib/LANraragi/Controller/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package LANraragi::Controller::Config;
use Mojo::Base 'Mojolicious::Controller';

use LANraragi::Utils::Generic qw(generate_themes_header remove_spaces remove_newlines);
use LANraragi::Utils::Database qw(redis_encode redis_decode save_computed_tagrules);
use LANraragi::Utils::Database qw(redis_encode save_computed_tagrules);
use LANraragi::Utils::TempFolder qw(get_tempsize);
use LANraragi::Utils::Tags qw(tags_rules_to_array replace_CRLF restore_CRLF);
use Mojo::JSON qw(encode_json);
Expand Down Expand Up @@ -42,6 +42,8 @@ sub index {
theme => $self->LRR_CONF->get_style,
usedateadded => $self->LRR_CONF->enable_dateadded,
usedatemodified => $self->LRR_CONF->use_lastmodified,
enablecryptofs => $self->LRR_CONF->enable_cryptofs,
hqthumbpages => $self->LRR_CONF->get_hqthumbpages,
csshead => generate_themes_header($self),
tempsize => get_tempsize
);
Expand Down Expand Up @@ -79,7 +81,9 @@ sub save_config {
tagruleson => ( scalar $self->req->param('tagruleson') ? '1' : '0' ),
nofunmode => ( scalar $self->req->param('nofunmode') ? '1' : '0' ),
usedateadded => ( scalar $self->req->param('usedateadded') ? '1' : '0' ),
usedatemodified => ( scalar $self->req->param('usedatemodified') ? '1' : '0' )
usedatemodified => ( scalar $self->req->param('usedatemodified') ? '1' : '0' ),
enablecryptofs => ( scalar $self->req->param('enablecryptofs') ? '1' : '0' ),
hqthumbpages => ( scalar $self->req->param('hqthumbpages') ? '1' : '0' ),
);

# Only add newpassword field as password if enablepass = 1
Expand Down
8 changes: 7 additions & 1 deletion lib/LANraragi/Controller/Login.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ sub check {
my $ppr = Authen::Passphrase->from_rfc2307( $self->LRR_CONF->get_password );

if ( $ppr->match($pw) ) {

$self->LRR_LOGGER->info( "Successful login attempt from " . $self->tx->remote_address );

$self->session( is_logged => 1 );
$self->session( expiration => 60 * 60 * 24 );
$self->redirect_to('index');
} else {

$self->LRR_LOGGER->warn( "Failed login attempt with password '$pw' from " . $self->tx->remote_address );

$self->render(
template => "login",
title => $self->LRR_CONF->get_htmltitle,
Expand Down Expand Up @@ -50,7 +56,7 @@ sub logged_in_api {
# The API key is in the Authentication header.
my $expected_key = $self->LRR_CONF->get_apikey;

my $auth_header = $self->req->headers->authorization || "";
my $auth_header = $self->req->headers->authorization || "";
my $expected_header = "Bearer " . encode_base64( $expected_key, "" );

return 1
Expand Down
3 changes: 1 addition & 2 deletions lib/LANraragi/Controller/Reader.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use Mojo::URL;
use Encode;

use LANraragi::Utils::Generic qw(generate_themes_header);
use LANraragi::Utils::Database qw(redis_decode);

use LANraragi::Model::Reader;

Expand All @@ -24,7 +23,7 @@ sub index {
# Get query string from referrer URL, if there's one
my $referrer = $self->req->headers->referrer;
my $query = "";

if ($referrer) {
$query = Mojo::URL->new($referrer)->query->to_string;
}
Expand Down
27 changes: 20 additions & 7 deletions lib/LANraragi/Controller/Upload.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use File::Copy;
use File::Find;
use File::Basename;

use LANraragi::Utils::Generic qw(generate_themes_header is_archive);
use LANraragi::Utils::Generic qw(generate_themes_header is_archive get_bytelength);

sub process_upload {
my $self = shift;
Expand All @@ -23,7 +23,19 @@ sub process_upload {
if ( is_archive($filename) ) {

# Move file to a temp folder (not the default LRR one)
my $tempdir = tempdir();
my $tempdir = tempdir();

my ( $fn, $path, $ext ) = fileparse( $filename, qr/\.[^.]*/ );
my $byte_limit = LANraragi::Model::Config->enable_cryptofs ? 143 : 255;

# don't allow the main filename to exceed 143/255 bytes after accounting
# for extension and .upload prefix used by `handle_incoming_file`
$filename = $fn;
while ( get_bytelength( $filename . $ext . ".upload" ) > $byte_limit ) {
$filename = substr( $filename, 0, -1 );
}
$filename = $filename . $ext;

my $tempfile = $tempdir . '/' . $filename;
$file->move_to($tempfile) or die "Couldn't move uploaded file.";

Expand All @@ -44,11 +56,12 @@ sub process_upload {
# Reply with a reference to the job so the client can check on its progress.
$self->render(
json => {
operation => "upload",
name => $file->filename,
type => $uploadMime,
success => 1,
job => $jobid
operation => "upload",
name => $file->filename,
debug_name => $filename,
type => $uploadMime,
success => 1,
job => $jobid
}
);

Expand Down
2 changes: 1 addition & 1 deletion lib/LANraragi/Model/Archive.pm
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ sub update_thumbnail {
my $newthumb = "";

# Get the required thumbnail we want to make the main one
eval { $newthumb = extract_thumbnail( $thumbdir, $id, $page ) };
eval { $newthumb = extract_thumbnail( $thumbdir, $id, $page, 1 ) };

if ( $@ || !$newthumb ) {
render_api_response( $self, "update_thumbnail", $@ );
Expand Down
7 changes: 4 additions & 3 deletions lib/LANraragi/Model/Backup.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ sub build_backup_JSON {

# Parse the category list and add them to JSON.
foreach my $key (@cats) {

# Use an eval block in case decode_json fails. This'll drop the category from the backup,
# But it's probably dinged anyways...
eval {
Expand All @@ -53,7 +54,7 @@ sub build_backup_JSON {
# Backup archives themselves next
my @keys = $redis->keys('????????????????????????????????????????'); #40-character long keys only => Archive IDs

#Parse the archive list and add them to JSON.
# Parse the archive list and add them to JSON.
foreach my $id (@keys) {

eval {
Expand All @@ -63,7 +64,7 @@ sub build_backup_JSON {
( $_ = redis_decode($_) ) for ( $name, $title, $tags );
( remove_newlines($_) ) for ( $name, $title, $tags );

#Backup all user-generated metadata, alongside the unique ID.
# Backup all user-generated metadata, alongside the unique ID.
my %arc = (
arcid => $id,
title => $title,
Expand Down Expand Up @@ -129,7 +130,7 @@ sub restore_from_JSON {
$redis->hset( $id, "tags", $tags );

if ( $redis->hexists( $id, "thumbhash" )
&& $redis->hget( $id, "thumbhash" ) eq "" ) {
&& $redis->hget( $id, "thumbhash" ) ne "" ) {
$redis->hset( $id, "thumbhash", $thumbhash );
}

Expand Down
26 changes: 26 additions & 0 deletions lib/LANraragi/Model/Category.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,32 @@ sub get_category_list {
return @result;
}

# get_categories_containing_archive(id)
# Returns a list of all the categories that contain the given archive.
sub get_categories_containing_archive {
my $archive_id = shift;

my $logger = get_logger( "Categories", "lanraragi" );
$logger->debug("Finding categories containing $archive_id");

my @categories = get_category_list();
@categories = grep { %$_{"search"} eq "" } @categories;

my @filteredcats = ();

# Check if the id is in any categories
for my $category (@categories) {
my @archives = @{ $category->{"archives"} };

if ( grep( /^$archive_id$/, @archives ) ) {
$logger->debug( "$archive_id is in '" . $category->{name} . "'" );
push @filteredcats, $category;
}
}

return @filteredcats;
}

# get_category(id)
# Returns the category matching the given id.
# Returns undef if the id doesn't exist.
Expand Down
2 changes: 2 additions & 0 deletions lib/LANraragi/Model/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,7 @@ sub get_readquality { return &get_redis_conf( "readerquality", "50" ) }
sub get_style { return &get_redis_conf( "theme", "modern.css" ) }
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" ) }

1;
3 changes: 2 additions & 1 deletion lib/LANraragi/Model/Plugins.pm
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ sub exec_metadata_plugin {
my $thumbdir = LANraragi::Model::Config->get_thumbdir;

# Eval the thumbnail extraction, as it can error out and die
eval { extract_thumbnail( $thumbdir, $id, 0 ) };
eval { extract_thumbnail( $thumbdir, $id, 0, 1 ) };
if ($@) {
$logger->warn("Error building thumbnail: $@");
$thumbhash = "";
Expand All @@ -226,6 +226,7 @@ sub exec_metadata_plugin {

# Bundle all the potentially interesting info in a hash
my %infohash = (
archive_id => $id,
archive_title => $title,
existing_tags => $tags,
thumbnail_hash => $thumbhash,
Expand Down
6 changes: 6 additions & 0 deletions lib/LANraragi/Model/Reader.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ sub resize_image {

#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' );

$img->Read($imgpath);

my ( $origw, $origh ) = $img->Get( 'width', 'height' );
Expand Down
10 changes: 7 additions & 3 deletions lib/LANraragi/Model/Upload.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use File::Copy qw(move);
use LANraragi::Utils::Database qw(invalidate_cache compute_id);
use LANraragi::Utils::Logging qw(get_logger);
use LANraragi::Utils::Database qw(redis_encode);
use LANraragi::Utils::Generic qw(is_archive remove_spaces remove_newlines trim_url);
use LANraragi::Utils::Generic qw(is_archive remove_spaces remove_newlines trim_url get_bytelength);

use LANraragi::Model::Config;
use LANraragi::Model::Plugins;
Expand Down Expand Up @@ -179,10 +179,14 @@ sub download_url {
$filename =~ s@[\\/:"*?<>|]+@@g;

my ( $fn, $path, $ext ) = fileparse( $filename, qr/\.[^.]*/ );
my $byte_limit = LANraragi::Model::Config->enable_cryptofs ? 143 : 255;

# don't allow the main filename to exceed 255 chars after accounting
# don't allow the main filename to exceed the given byte limit
# for extension and .upload prefix used by `handle_incoming_file`
$filename = substr $fn, 0, 254 - length($ext) - length(".upload");
$filename = $fn;
while ( get_bytelength( $filename . $ext . ".upload" ) > $byte_limit ) {
$filename = substr( $filename, 0, -1 );
}
$filename = $filename . $ext;
$logger->debug("Filename post clean: $filename");
$tx->result->save_to("$tempdir\/$filename");
Expand Down
Loading

0 comments on commit 3e25a66

Please sign in to comment.