Skip to content

Commit

Permalink
Merge pull request #322 from Difegue/dev
Browse files Browse the repository at this point in the history
LANraragi Release 0.7.1
  • Loading branch information
Difegue authored Jul 25, 2020
2 parents 7752c15 + 0859006 commit 1585d6c
Show file tree
Hide file tree
Showing 42 changed files with 801 additions and 408 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/push-continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ jobs:
- name: Build and test bundled homebrew formula
run: |
brew update
tar -cvzf /tmp/lanraragi.tar.gz .
cd tools/build/homebrew
echo "Moving checked out'd code to the brew cache location $(brew --cache -s Lanraragi.rb)"
mv /tmp/lanraragi.tar.gz $(brew --cache -s Lanraragi.rb)
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@12
brew install --verbose --build-from-source Lanraragi.rb
brew install --force --verbose --build-from-source Lanraragi.rb
brew test --verbose Lanraragi.rb
brew audit --verbose Lanraragi.rb
2 changes: 1 addition & 1 deletion .github/workflows/release-delivery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
TAG=${GITHUB_REF:10:10}
docker buildx build --pull \
--platform linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x \
--output "type=image,push=true" \
--output "type=registry" \
--tag difegue/lanraragi:latest \
--tag difegue/lanraragi:$TAG \
--file ./tools/build/docker/Dockerfile .
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[<img src="https://img.shields.io/docker/pulls/difegue/lanraragi.svg">](https://hub.docker.com/r/difegue/lanraragi/)
[<img src="https://img.shields.io/github/downloads/difegue/lanraragi/total.svg">](https://github.com/Difegue/LANraragi/releases)
[<img src="https://img.shields.io/github/release/difegue/lanraragi.svg?label=latest%20release">](https://github.com/Difegue/LANraragi/releases/latest)
[<img src="https://img.shields.io/homebrew/v/lanraragi.svg">](https://formulae.brew.sh/formula/lanraragi)
[<img src="https://img.shields.io/website/https/lrr.tvc-16.science.svg?label=demo%20website&up_message=online">](https://lrr.tvc-16.science/)
[<img src="https://action-badges.now.sh/Difegue/lanraragi">](https://github.com/Difegue/LANraragi/actions)
[<img src="https://img.shields.io/discord/612709831744290847">](https://discord.gg/aRQxtbg)
Expand Down Expand Up @@ -30,7 +31,7 @@ Open source server for archival of comics/manga, running on Mojolicious + Redis.

## Features

* Stores your comics in archive format. (zip/rar/targz/lzma/7z/xz/cbz/cbr/pdf supported)
* Stores your comics in archive format. (zip/rar/targz/lzma/7z/xz/cbz/cbr/pdf supported, barebones support for epub)

* Read archives directly from your web browser: the server reads from within compressed files using temporary folders.

Expand Down
60 changes: 40 additions & 20 deletions lib/LANraragi/Controller/Api/Archive.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,22 @@ use Encode;
use Storable;
use Mojo::JSON qw(decode_json encode_json from_json);

use LANraragi::Utils::Generic qw(render_api_response);

use LANraragi::Model::Archive;
use LANraragi::Model::Backup;
use LANraragi::Model::Config;
use LANraragi::Model::Plugins;
use LANraragi::Model::Reader;
use LANraragi::Model::Stats;

# Archive API. To be refactored soon!
# Archive API.

# Handle missing ID parameter for a whole lot of api methods down below.
sub check_id_parameter {
my ( $mojo, $endpoint ) = @_;
my ( $mojo, $operation ) = @_;

my $id = $mojo->req->param('id') || 0;
# Use either the id query param(deprecated), or the URL component.
my $id = $mojo->req->param('id') || $mojo->stash('id') || 0;
unless ($id) {

#High-level API documentation!
$mojo->render(
json => { error => "API usage: $endpoint?id=YOUR_ID" },
status => 400
);
render_api_response($mojo, $operation, "No archive ID specified.");
}
return $id;
}
Expand All @@ -43,6 +38,16 @@ sub serve_untagged_archivelist {
$self->render( json => \@idlist );
}

sub serve_metadata {
my $self = shift;
my $id = check_id_parameter( $self, "metadata" ) || return;
my $redis = $self->LRR_CONF->get_redis;

my $arcdata = LANraragi::Utils::Database::build_archive_JSON( $redis, $id );
$redis->quit;
$self->render( json => $arcdata );
}

sub serve_thumbnail {
my $self = shift;
my $id = check_id_parameter( $self, "thumbnail" ) || return;
Expand All @@ -64,23 +69,22 @@ 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::Archive::serve_page( $self, $id );
my $id = check_id_parameter( $self, "serve_page" ) || return;
my $path = $self->req->param('path') || "404.xyz";

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

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

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

if ($err) {
$self->render(
json => { error => $err },
status => 500
);
render_api_response($self, "extract_archive", $err);
} else {
$self->render( json => decode_json($readerjson) );
}
Expand Down Expand Up @@ -137,11 +141,27 @@ sub use_enabled_plugins {
operation => "autoplugin",
id => $id,
success => 0,
message => "ID not found in database or AutoPlugin disabled by admin."
error => "ID not found in database or AutoPlugin disabled by admin."
}
);
}
$redis->quit();
}

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

my $title = $self->req->param('title') || undef;
my $tags = $self->req->param('tags') || undef;

my $res = LANraragi::Model::Archive::update_metadata( $id, $title, $tags );

if ($res eq "") {
render_api_response( $self, "add_to_category" );
} else {
render_api_response($self, "update_metadata", $res);
}
}

1;
12 changes: 11 additions & 1 deletion lib/LANraragi/Controller/Api/Other.pm
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package LANraragi::Controller::Api::Other;
use Mojo::Base 'Mojolicious::Controller';

use Mojo::JSON qw(encode_json);
use Redis;

use LANraragi::Utils::TempFolder qw(get_tempsize clean_temp_full);
use LANraragi::Utils::Plugins qw(get_plugin get_plugin_parameters);
use LANraragi::Utils::Plugins qw(get_plugin get_plugins get_plugin_parameters);

sub serve_serverinfo {
my $self = shift;
Expand Down Expand Up @@ -49,6 +50,15 @@ sub clean_tempfolder {
);
}

# List all plugins of the given type.
sub list_plugins {
my $self = shift;
my $type = $self->stash('type');

my @plugins = get_plugins($type);
$self->render( json => \@plugins );
}

# Uses a plugin, with the standard global arguments and a provided oneshot argument.
sub use_plugin {

Expand Down
2 changes: 2 additions & 0 deletions lib/LANraragi/Controller/Batch.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use Mojo::Base 'Mojolicious::Controller';
use Redis;
use Encode;
use Mojo::IOLoop::Subprocess;
use Mojo::Util qw(xml_escape);
use Mojo::JSON qw(decode_json encode_json from_json);

use LANraragi::Utils::Generic qw(generate_themes_selector generate_themes_header);
Expand All @@ -28,6 +29,7 @@ sub index {
my $zipfile = $redis->hget( $id, "file" );
my $title = $redis->hget( $id, "title" );
$title = redis_decode($title);
$title = xml_escape($title);

if ( -e $zipfile ) {
$arclist .= "<li><input type='checkbox' name='archive' id='$id' class='archive' >";
Expand Down
2 changes: 2 additions & 0 deletions lib/LANraragi/Controller/Category.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use utf8;
use URI::Escape;
use Redis;
use Encode;
use Mojo::Util qw(xml_escape);

use LANraragi::Utils::Generic qw(generate_themes_selector generate_themes_header);
use LANraragi::Utils::Database qw(redis_decode);
Expand Down Expand Up @@ -32,6 +33,7 @@ sub index {
my $zipfile = $redis->hget( $id, "file" );
my $title = $redis->hget( $id, "title" );
$title = redis_decode($title);
$title = xml_escape($title);

if ( -e $zipfile ) {
$arclist .=
Expand Down
2 changes: 2 additions & 0 deletions lib/LANraragi/Controller/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ sub index {
devmode => $self->LRR_CONF->enable_devmode,
nofunmode => $self->LRR_CONF->enable_nofun,
apikey => $self->LRR_CONF->get_apikey,
enablecors => $self->LRR_CONF->enable_cors,
tagregex => $self->LRR_CONF->get_tagregex,
enableresize => $self->LRR_CONF->enable_resize,
sizethreshold => $self->LRR_CONF->get_threshold,
Expand Down Expand Up @@ -64,6 +65,7 @@ sub save_config {
#for checkboxes,
#we check if the parameter exists in the POST to return either 1 or 0.
enablepass => ( scalar $self->req->param('enablepass') ? '1' : '0' ),
enablecors => ( scalar $self->req->param('enablecors') ? '1' : '0' ),
autotag => ( scalar $self->req->param('autotag') ? '1' : '0' ),
devmode => ( scalar $self->req->param('devmode') ? '1' : '0' ),
enableresize => ( scalar $self->req->param('enableresize') ? '1' : '0' ),
Expand Down
46 changes: 5 additions & 41 deletions lib/LANraragi/Controller/Edit.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,12 @@ use File::Basename;
use Redis;
use Encode;
use Template;
use Mojo::Util qw(xml_escape);

use LANraragi::Utils::Generic qw(generate_themes_selector generate_themes_header remove_spaces remove_newlines);
use LANraragi::Utils::Database qw(redis_decode invalidate_cache);
use LANraragi::Utils::Generic qw(generate_themes_selector generate_themes_header);
use LANraragi::Utils::Database qw(redis_decode);
use LANraragi::Utils::Plugins qw(get_plugins);

sub save_metadata {
my $self = shift;

my $id = $self->req->param('id');
my $title = $self->req->param('title');
my $tags = $self->req->param('tags');

#clean up the user's inputs and encode them.
( remove_spaces($_) ) for ( $title, $tags );
( remove_newlines($_) ) for ( $title, $tags );

#Input new values into redis hash.
#prepare the hash which'll be inserted.
my %hash = (
title => encode_utf8($title),
tags => encode_utf8($tags)
);

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

# For all keys of the hash, add them to the redis hash $id with the matching keys.
$redis->hset( $id, $_, $hash{$_}, sub { } ) for keys %hash;
$redis->wait_all_responses;
$redis->quit();

#Trigger a JSON rebuild.
invalidate_cache();

$self->render(
json => {
id => $id,
operation => "edit",
success => 1
}
);
}

sub delete_archive {
my $self = shift;
my $id = $self->req->param('id');
Expand Down Expand Up @@ -86,8 +50,8 @@ sub index {
template => "edit",
id => $id,
name => $name,
arctitle => $title,
tags => $tags,
arctitle => xml_escape($title),
tags => xml_escape($tags),
file => decode_utf8($file),
thumbhash => $thumbhash,
plugins => \@pluginlist,
Expand Down
5 changes: 5 additions & 0 deletions lib/LANraragi/Controller/Index.pm
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,17 @@ sub index {

my $userlogged = $self->LRR_CONF->enable_pass == 0 || $self->session('is_logged');

# Get static category list to populate the right-click menu
my @categories = LANraragi::Model::Category::get_category_list;
@categories = grep { %$_{"search"} eq "" } @categories;

$self->render(
template => "index",
version => $self->LRR_VERSION,
title => $self->LRR_CONF->get_htmltitle,
pagesize => $self->LRR_CONF->get_pagesize,
userlogged => $userlogged,
categories => \@categories,
motd => $self->LRR_CONF->get_motd,
cssdrop => generate_themes_selector,
csshead => generate_themes_header($self),
Expand Down
13 changes: 6 additions & 7 deletions lib/LANraragi/Controller/Login.pm
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,19 @@ sub logged_in {
sub logged_in_api {
my $self = shift;

# Uncomment this to send Access-Control-Allow-Origin = '*'
#$self->res->headers->access_control_allow_origin('*');
# The API outputs CORS headers if the user allows it in the settings
if ( $self->LRR_CONF->enable_cors ) {
$self->res->headers->access_control_allow_origin('*');
}

# The API key can be either a key parameter, or in the Authentication header.
# The parameter variant is deprecated and will be removed in a future release.
my $key = $self->req->param('key') || '';
# The API key is in the Authentication header.
my $expected_key = $self->LRR_CONF->get_apikey;

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

return 1
if ( $key ne "" && $key eq $expected_key )
|| ( $expected_key ne "" && $auth_header eq $expected_header )
if ( $expected_key ne "" && $auth_header eq $expected_header )
|| $self->session('is_logged')
|| $self->LRR_CONF->enable_pass == 0;
$self->render(
Expand Down
Loading

0 comments on commit 1585d6c

Please sign in to comment.