Skip to content

Commit

Permalink
Merge pull request #877 from Difegue/dev
Browse files Browse the repository at this point in the history
LRR 0.9.0
  • Loading branch information
Difegue committed Oct 31, 2023
2 parents 3dbce9f + 846d0a7 commit 3e10960
Show file tree
Hide file tree
Showing 112 changed files with 5,149 additions and 1,038 deletions.
3 changes: 2 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# Dropping copies of the files in the .devcontainer folder should also work, but I cba to duplicate my build files for this and symlinks aint working I hate computers
RUN wget -P /tools https://raw.githubusercontent.com/Difegue/LANraragi/dev/tools/cpanfile \
&& wget -P /tools https://raw.githubusercontent.com/Difegue/LANraragi/dev/tools/install.pl \
&& wget https://raw.githubusercontent.com/Difegue/LANraragi/dev/package.json
&& wget https://raw.githubusercontent.com/Difegue/LANraragi/dev/package.json \
&& wget https://raw.githubusercontent.com/Difegue/LANraragi/dev/package-lock.json

RUN npm run lanraragi-installer install-full

3 changes: 3 additions & 0 deletions .github/action-run-tests/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

echo "🎌 Running LRR Test Suite 🎌"

# Install cpan deps in case some are missing
perl ./tools/install.pl install-back

# Run the perl tests on the repo
prove -r -l -v tests/

2 changes: 1 addition & 1 deletion .github/workflows/push-continous-delivery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- uses: actions/checkout@master
- name: Docker Build and export
run: |
docker build -t difegue/lanraragi -f ./tools/build/docker/Dockerfile-legacy .
docker build -t difegue/lanraragi -f ./tools/build/docker/Dockerfile --build-arg INSTALL_PARAMETER=-w .
docker create --name rootfs difegue/lanraragi
docker export --output=package.tar rootfs
- name: Upload rootfs
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-delivery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@master
- name: Docker Build and export
run: |
docker build -t difegue/lanraragi -f ./tools/build/docker/Dockerfile-legacy .
docker build -t difegue/lanraragi -f ./tools/build/docker/Dockerfile --build-arg INSTALL_PARAMETER=-w .
docker create --name rootfs difegue/lanraragi
docker export --output=package.tar rootfs
- name: Upload rootfs
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ content
.minion.db*
npm-debug.log
dump.rdb
package-lock.json
.vstags
.gitbook
*qemu-*-static*
Dockerfile.*
.DS_Store
config.log
autobackup.json
autobackup.json
Makefile
oshino
58 changes: 34 additions & 24 deletions lib/LANraragi.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use Storable;
use Sys::Hostname;
use Config;

use LANraragi::Utils::Generic qw(start_shinobu start_minion);
use LANraragi::Utils::Logging qw(get_logger get_logdir);
use LANraragi::Utils::Plugins qw(get_plugins);
use LANraragi::Utils::Generic qw(start_shinobu start_minion);
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;
use LANraragi::Utils::Minion;
Expand All @@ -36,8 +36,19 @@ sub startup {
my $vername = $packagejson->{version_name};
my $descstr = $packagejson->{description};

# Use the hostname and osname for a sorta-unique set of secrets.
$self->secrets( [ hostname(), $Config{"osname"}, 'oshino' ] );
my $secret = "";
my $secretfile_path = $ENV{LRR_DATA_DIRECTORY} ? $ENV{LRR_DATA_DIRECTORY} . "/oshino" : "oshino";
if ( -e $secretfile_path ) {
$secret = Mojo::File->new($secretfile_path)->slurp;
} else {

# Generate a random string as the secret and store it in a file
$secret .= sprintf( "%x", rand 16 ) for 1 .. 8;
Mojo::File->new($secretfile_path)->spew($secret);
}

# Use the hostname alongside the random secret
$self->secrets( [ $secret . hostname() ] );
$self->plugin('RenderFile');

# Set Template::Toolkit as default renderer so we can use the LRR templates
Expand Down Expand Up @@ -70,19 +81,11 @@ 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,
# Where Redis lets us send commands but doesn't necessarily reply to them properly.
# (https://github.com/redis/redis/issues/4624)
while (1) {
eval { $devmode = $self->LRR_CONF->enable_devmode; };
eval { $self->LRR_CONF->get_redis->keys('*') };

last unless ($@);

Expand All @@ -91,13 +94,13 @@ sub startup {
sleep 2;
}

# Enable AOF saving on the Redis server.
# This allows us to start creating an aof file using existing RDB snapshot data.
# Later LRR releases will then be able to set appendonly directly in redis.conf without fearing data loss.
say "Enabling AOF on Redis... This might take a while.";
$self->LRR_CONF->get_redis->config_set( "appendonly", "yes" );
# 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);
}

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

Expand All @@ -111,7 +114,9 @@ sub startup {
open( my $fh, '>>', $logpath )
or die "Could not open file '$logpath' $!";

print $fh "[Mojolicious] " . $lines[0] . " " . $lines[1] . "\n";
my $l1 = $lines[0] // "";
my $l2 = $lines[1] // "";
print $fh "[Mojolicious] $l1 $l2 \n";
close $fh;
}
);
Expand Down Expand Up @@ -143,9 +148,14 @@ sub startup {
# Enable Minion capabilities in the app
shutdown_from_pid( get_temp . "/minion.pid" );

my $miniondb = $self->LRR_CONF->get_redisad . "/" . $self->LRR_CONF->get_miniondb;
my $miniondb = $self->LRR_CONF->get_redisad . "/" . $self->LRR_CONF->get_miniondb;
my $redispassword = $self->LRR_CONF->get_redispassword;

# If the password is non-empty, add the required delimiters
if ($redispassword) { $redispassword = "x:" . $redispassword . "@"; }

say "Minion will use the Redis database at $miniondb";
$self->plugin( 'Minion' => { Redis => "redis://$miniondb" } );
$self->plugin( 'Minion' => { Redis => "redis://$redispassword$miniondb" } );
$self->LRR_LOGGER->info("Successfully connected to Minion database.");
$self->minion->missing_after(5); # Clean up older workers after 5 seconds of unavailability

Expand Down Expand Up @@ -199,7 +209,7 @@ sub add_sigint_handler {
shutdown_from_pid( get_temp . "/minion.pid" );

\&$old_int; # Calling the old handler to cleanly exit the server
}
}
}

sub migrate_old_settings {
Expand Down
35 changes: 19 additions & 16 deletions lib/LANraragi/Controller/Api/Archive.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use Mojo::Base 'Mojolicious::Controller';
use Redis;
use Encode;
use Storable;
use Mojo::JSON qw(decode_json);
use Mojo::JSON qw(decode_json);
use Scalar::Util qw(looks_like_number);

use LANraragi::Utils::Generic qw(render_api_response);
use LANraragi::Utils::Generic qw(render_api_response);
use LANraragi::Utils::Database qw(get_archive_json set_isnew);

use LANraragi::Model::Archive;
Expand Down Expand Up @@ -64,7 +64,7 @@ sub serve_metadata {
sub get_categories {

my $self = shift;
my $id = check_id_parameter( $self, "find_arc_categories" ) || return;
my $id = check_id_parameter( $self, "find_arc_categories" ) || return;

my @categories = LANraragi::Model::Category::get_categories_containing_archive($id);

Expand All @@ -79,13 +79,13 @@ sub get_categories {

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

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

Expand All @@ -105,14 +105,14 @@ sub serve_file {
sub serve_page {
my $self = shift;
my $id = check_id_parameter( $self, "serve_page" ) || return;
my $path = $self->req->param('path') || "404.xyz";
my $path = $self->req->param('path') || "404.xyz";

LANraragi::Model::Archive::serve_page( $self, $id, $path );
}

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

my $force = $self->req->param('force') eq "true" || "0";
my $reader_json;
Expand All @@ -129,7 +129,7 @@ sub get_file_list {

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

set_isnew( $id, "false" );

Expand All @@ -144,7 +144,7 @@ sub clear_new {

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

my $delStatus = LANraragi::Utils::Database::delete_archive($id);

Expand All @@ -160,7 +160,7 @@ sub delete_archive {

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

my $title = $self->req->param('title');
my $tags = $self->req->param('tags');
Expand All @@ -176,9 +176,10 @@ sub update_metadata {

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

my $page = $self->stash('page') || 0;
my $time = time();

# Undocumented parameter to force progress update
my $force = $self->req->param('force') || 0;
Expand All @@ -205,7 +206,8 @@ sub update_progress {
}

# Just set the progress value.
$redis->hset( $id, "progress", $page );
$redis->hset( $id, "progress", $page );
$redis->hset( $id, "lastreadtime", $time );

# Update total pages read statistic
$redis_cfg->incr("LRR_TOTALPAGESTAT");
Expand All @@ -215,10 +217,11 @@ sub update_progress {

$self->render(
json => {
operation => "update_progress",
id => $id,
page => $page,
success => 1
operation => "update_progress",
id => $id,
page => $page,
lastreadtime => $time,
success => 1
}
);

Expand Down
16 changes: 12 additions & 4 deletions lib/LANraragi/Controller/Api/Category.pm
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ sub add_to_category {

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

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

Expand All @@ -124,7 +124,15 @@ sub remove_from_category {
my ( $result, $err ) = LANraragi::Model::Category::remove_from_category( $catid, $arcid );

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

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

render_api_response( $self, "remove_from_category", undef, $successMessage );
} else {
render_api_response( $self, "remove_from_category", $err );
}
Expand Down
Loading

0 comments on commit 3e10960

Please sign in to comment.