Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
还原部分代码片段 并尝试修复 (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
WindyCloudCute committed Dec 10, 2023
1 parent 5fb48e8 commit 612c2a5
Show file tree
Hide file tree
Showing 28 changed files with 179 additions and 120 deletions.
5 changes: 3 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ENV LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8

# Install needed packages and setup non-root user. Use a separate RUN statement to add your own dependencies.
ARG USERNAME=root
ARG USER_UID=1000
ARG USER_UID=0
ARG USER_GID=$USER_UID
RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y update && apt-get -y install wget \
Expand All @@ -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/WindyCloudCute/LANraragi_Chinese/dev/tools/cpanfile \
&& wget -P /tools https://raw.githubusercontent.com/WindyCloudCute/LANraragi_Chinese/dev/tools/install.pl \
&& wget https://raw.githubusercontent.com/WindyCloudCute/LANraragi_Chinese/dev/package.json
&& wget https://raw.githubusercontent.com/WindyCloudCute/LANraragi_Chinese/dev/package.json \
&& wget https://raw.githubusercontent.com/WindyCloudCute/LANraragi_Chinese/dev/package-lock.json

RUN npm run lanraragi-installer install-full

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ autobackup.json
lib/LANraragi/Plugin/Scripts/ETagConverter.pm
lib/LANraragi/Plugin/Metadata/ETagCN.pm
Makefile
oshino
oshino
12 changes: 6 additions & 6 deletions lib/LANraragi/Controller/Batch.pm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ sub socket {

my $logger = get_logger( "Batch Tagging", "lanraragi" );

$logger->info('客户端连接到 Batch Tagging 服务');
$logger->info('Client connected to Batch Tagging service');

# Increase inactivity timeout for connection a bit to account for clientside timeouts
$self->inactivity_timeout(80);
Expand Down Expand Up @@ -81,7 +81,7 @@ sub socket {
my @args = @{ $command->{"args"} };

if ( !@args ) {
$logger->debug("没有覆盖插件全局参数.");
$logger->debug("No user overrides given.");

# Try getting the saved defaults
@args = get_plugin_parameters($pluginname);
Expand Down Expand Up @@ -127,7 +127,7 @@ sub socket {

if ( $operation eq "tagrules" ) {

$logger->debug("将标签规则应用于$id...");
$logger->debug("Applying tag rules to $id...");
my $tags = $redis->hget( $id, "tags" );
$tags = redis_decode($tags);

Expand All @@ -137,7 +137,7 @@ sub socket {

# Merge array with commas
my $newtags = join( ', ', @tagarray );
$logger->debug("新标签: $newtags");
$logger->debug("New tags: $newtags");
set_tags( $id, $newtags );

$client->send(
Expand All @@ -155,7 +155,7 @@ sub socket {
}

if ( $operation eq "delete" ) {
$logger->debug("正在删除 $id...");
$logger->debug("Deleting $id...");

my $delStatus = LANraragi::Model::Archive::delete_archive($id);

Expand Down Expand Up @@ -187,7 +187,7 @@ sub socket {

# If the client doesn't respond, halt processing
finish => sub {
$logger->info('客户端断开连接,停止剩余操作');
$logger->info('Client disconnected, halting remaining operations');
$cancelled = 1;
$redis->quit();
}
Expand Down
46 changes: 46 additions & 0 deletions lib/LANraragi/Model/Archive.pm
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,50 @@ sub update_metadata {
return "";
}

# Deletes the archive with the given id from redis, and the matching archive file/thumbnail.
sub delete_archive ($id) {

my $redis = LANraragi::Model::Config->get_redis;
my $filename = $redis->hget( $id, "file" );
my $oldtags = $redis->hget( $id, "tags" );
$oldtags = redis_decode($oldtags);

my $oldtitle = lc( redis_decode( $redis->hget( $id, "title" ) ) );
$oldtitle = trim($oldtitle);
$oldtitle = trim_CRLF($oldtitle);
$oldtitle = redis_encode($oldtitle);

$redis->del($id);
$redis->quit();

# Remove matching data from the search indexes
my $redis_search = LANraragi::Model::Config->get_redis_search;
$redis_search->zrem( "LRR_TITLES", "$oldtitle\0$id" );
$redis_search->srem( "LRR_NEW", $id );
$redis_search->srem( "LRR_UNTAGGED", $id );
$redis_search->quit();

LANraragi::Utils::Database::update_indexes( $id, $oldtags, "" );

if ( -e $filename ) {
my $status = unlink $filename;

my $thumbdir = LANraragi::Model::Config->get_thumbdir;
my $subfolder = substr( $id, 0, 2 );

my $jpg_thumbname = "$thumbdir/$subfolder/$id.jpg";
unlink $jpg_thumbname;

my $jxl_thumbname = "$thumbdir/$subfolder/$id.jxl";
unlink $jxl_thumbname;

# Delete the thumbpages folder
remove_tree("$thumbdir/$subfolder/$id/");

return $status ? $filename : "0";
}

return "0";
}

1;
2 changes: 1 addition & 1 deletion lib/LANraragi/Model/Opds.pm
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ sub generate_opds_catalog {
version => $mojo->LRR_VERSION,
api_key_query => $api_key ? "?key=" . $api_key : "",
api_key_and => $api_key ? "&key=" . $api_key : ""
);
);
}else{
return $mojo->render_to_string(
template => "opds",
Expand Down
2 changes: 1 addition & 1 deletion lib/LANraragi/Model/Plugins.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package LANraragi::Model::Plugins;

use strict;
use warnings;

use utf8;
use feature 'fc';

use Redis;
Expand Down
2 changes: 1 addition & 1 deletion lib/LANraragi/Model/Reader.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package LANraragi::Model::Reader;

use strict;
use warnings;

use utf8;

use Redis;
use File::Basename;
Expand Down
34 changes: 17 additions & 17 deletions lib/LANraragi/Model/Search.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package LANraragi::Model::Search;

use strict;
use warnings;

use utf8;

use List::Util qw(min);
use Redis;
use Storable qw/ nfreeze thaw /;
Expand All @@ -27,7 +27,7 @@ sub do_search {
my $logger = get_logger( "Search Engine", "lanraragi" );

unless ( $redis->exists("LAST_JOB_TIME") ) {
$logger->error("搜索引擎尚未初始化。 请稍等几秒钟。");
$logger->error("Search engine is not initialized yet. Please wait a few seconds.");
return ( -1, -1, () );
}

Expand All @@ -41,7 +41,7 @@ sub do_search {
my ( $cachehit, @filtered ) = check_cache( $cachekey, $cachekey_inv );

unless ($cachehit) {
$logger->debug("没有可用的缓存,进行完整的DB解析。");
$logger->debug("No cache available, doing a full DB parse.");
@filtered = search_uncached( $category_id, $filter, $sortkey, $sortorder, $newonly, $untaggedonly );

# Cache this query in the search database
Expand Down Expand Up @@ -70,18 +70,18 @@ sub check_cache {

my @filtered = ();
my $cachehit = 0;
$logger->debug("搜索请求: $cachekey");
$logger->debug("Search request: $cachekey");

if ( $redis->exists("LRR_SEARCHCACHE") && $redis->hexists( "LRR_SEARCHCACHE", $cachekey ) ) {
$logger->debug("将缓存用于此查询。");
$logger->debug("Using cache for this query.");
$cachehit = 1;

# Thaw cache and use that as the filtered list
my $frozendata = $redis->hget( "LRR_SEARCHCACHE", $cachekey );
@filtered = @{ thaw $frozendata };

} elsif ( $redis->exists("LRR_SEARCHCACHE") && $redis->hexists( "LRR_SEARCHCACHE", $cachekey_inv ) ) {
$logger->debug("与对面的排序订单存在缓存密钥.");
$logger->debug("A cache key exists with the opposite sortorder.");
$cachehit = 1;

# Thaw cache, invert the list to match the sortorder and use that as the filtered list
Expand Down Expand Up @@ -147,7 +147,7 @@ sub search_uncached {
my $isneg = $token->{isneg};
my $isexact = $token->{isexact};

$logger->debug("正在搜索 $tag, isneg=$isneg, isexact=$isexact");
$logger->debug("Searching for $tag, isneg=$isneg, isexact=$isexact");

# Encode tag as we'll use it in redis operations
$tag = redis_encode($tag);
Expand All @@ -162,7 +162,7 @@ sub search_uncached {
my $operator = $2;
my $pagecount = $3;

$logger->debug("搜索具有页面的ID $operator $pagecount $col");
$logger->debug("Searching for IDs with $operator $pagecount $col");

# If no operator is specified, we assume it's an exact match
$operator = "=" if !$operator;
Expand Down Expand Up @@ -194,7 +194,7 @@ sub search_uncached {

# Get the list of IDs for this tag
@ids = $redis->smembers("INDEX_$tag");
$logger->debug( "找到了 $tag 的索引,包含 " . scalar @ids . "个 ID" );
$logger->debug( "Found tag index for $tag, containing " . scalar @ids . " IDs" );
} else {

# Get index keys that match this tag.
Expand All @@ -206,7 +206,7 @@ sub search_uncached {
# Get the list of IDs for each key
foreach my $key (@keys) {
my @keyids = $redis->smembers($key);
$logger->trace( "找到了 $tag 的索引 $key,包含了 " . scalar @ids . " 个 ID" );
$logger->trace( "Found index $key for $tag, containing " . scalar @ids . " IDs" );
push @ids, @keyids;
}
}
Expand All @@ -218,15 +218,15 @@ sub search_uncached {

# First iteration
if ( $scan == -1 ) { $scan = 0; }
$logger->trace("正在扫描 $namesearch, cursor=$scan");
$logger->trace("Scanning for $namesearch, cursor=$scan");

my @result = $redis->zscan( "LRR_TITLES", $scan, "MATCH", $namesearch, "COUNT", 100 );
$scan = $result[0];

foreach my $title ( @{ $result[1] } ) {

if ( $title eq "0" ) { next; } # Skip scores
$logger->trace("找到标题匹配项: $title");
$logger->trace("Found title match: $title");

# Strip everything before \x00 to get the ID out of the key
my $id = substr( $title, index( $title, "\x00" ) + 1 );
Expand All @@ -237,11 +237,11 @@ sub search_uncached {
if ( scalar @ids == 0 && !$isneg ) {

# No more results, we can end search here
$logger->trace("该标记没有结果,正在停止搜索。");
$logger->trace("No results for this token, halting search.");
@filtered = ();
last;
} else {
$logger->trace( "找到此标记的 " . scalar @ids . " 个结果." );
$logger->trace( "Found " . scalar @ids . " results for this token." );

# Intersect the new list with the previous ones
@filtered = intersect_arrays( \@ids, \@filtered, $isneg );
Expand All @@ -250,7 +250,7 @@ sub search_uncached {
}

if ( $#filtered > 0 ) {
$logger->debug( "筛选后找到了 " . $#filtered . " 个结果" );
$logger->debug( "Found " . $#filtered . " results after filtering." );

if ( !$sortkey ) {
$sortkey = "title";
Expand All @@ -268,7 +268,7 @@ sub search_uncached {
# Remove the titles from the keys, which are stored as "title\x00id"
@ordered = map { substr( $_, index( $_, "\x00" ) + 1 ) } @ordered;

$logger->trace( "有序列表中的示例元素: " . $ordered[0] );
$logger->trace( "Example element from ordered list: " . $ordered[0] );

# Just intersect the ordered list with the filtered one to get the final result
@filtered = intersect_arrays( \@filtered, \@ordered, 0 );
Expand Down Expand Up @@ -382,7 +382,7 @@ sub compute_search_filter {
}

# Escape already present regex characters
$logger->debug("预转义标签: $tag");
$logger->debug("Pre-escaped tag: $tag");

$tag = trim($tag);

Expand Down
4 changes: 2 additions & 2 deletions lib/LANraragi/Model/Stats.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package LANraragi::Model::Stats;

use strict;
use warnings;

use utf8;

use Redis;
use File::Find;
Expand All @@ -21,7 +21,7 @@ sub get_archive_count {
sub get_page_stat {

my $redis = LANraragi::Model::Config->get_redis_config;
my $stat = $redis->get("LRR_TOTALPAGESTAT") || 0;
my $stat = $redis->get("LRR_TOTALPAGESTAT") || 0;
$redis->quit();

return $stat;
Expand Down
2 changes: 1 addition & 1 deletion lib/LANraragi/Plugin/Metadata/Koromo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ sub plugin_info {
author => "CirnoT, Difegue",
version => "2.1",
description => " 在Koromo 风格的 Info.json 文件收集作为嵌入到档案中的元数据. ( {'Tags': [xxx] } syntax)",
icon =>
icon =>
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABhGlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw1AUhU9TpVoqDmYQcchQnSyIijhKFYtgobQVWnUweekfNDEkKS6OgmvBwZ/FqoOLs64OroIg+APi4uqk6CIl3pcUWsR44fE+zrvn8N59gNCoMs3qGgc03TbTibiUy69IoVeE0QsRAYgys4xkZiEL3/q6pz6quxjP8u/7s/rUgsWAgEQ8ywzTJl4nnt60Dc77xCIryyrxOfGYSRckfuS64vEb55LLAs8UzWx6jlgklkodrHQwK5sa8RRxVNV0yhdyHquctzhr1Rpr3ZO/MFLQlzNcpzWMBBaRRAoSFNRQQRU2YrTrpFhI03ncxz/k+lPkUshVASPHPDagQXb94H/we7ZWcXLCS4rEge4Xx/kYAUK7QLPuON/HjtM8AYLPwJXe9m80gJlP0uttLXoE9G8DF9dtTdkDLneAwSdDNmVXCtISikXg/Yy+KQ8M3ALhVW9urXOcPgBZmtXSDXBwCIyWKHvN5909nXP7t6c1vx8dzXKFeWpUawAAAAZiS0dEAOwAEABqpSa6lwAAAAlwSFlzAAAuIwAALiMBeKU/dgAAAAd0SU1FB+MKCRQBJSKMeg0AAAGVSURBVDjLpZMxa9tQFIXPeaiyhxiZzKFjBme1JFfYgYAe9Bd0yA8JIaQhkJLBP6T/wh3qpZYzm2I8dyilJJMTW7yTIVGRFasE8uAt93K+d+5991IS8Ybj1SVIer24ty8Jk2wyl5S/GkDSi+O4s9PaOYOQh91wSHK2DeLViVut1pmkTwAQtAPUQcz/xCRBEpKOg3ZwEnbDDklvK6AQ+77fds4tSJbBcM7Nm83GbhXiVcXj8fiHpO/WWgfgHAAkXYxGoy8k/UG/nzxDnsqRxF7cO0iS5AhAQxKLm6bpVZqmn8sxAI3kQ2KjKDqQ9GRFEqDNfpQcukrMkDRF3ADAJJvM1+v1n0G/n5D0AcBaew3gFMCFtfbyuVT/cHCYrFarX1mWLQCgsAWSXtgNO81mY/ed7380xpyUn3XOXefr/Ntyufw9vZn+LL7zn21J+fRmOru/f/hrjNmThFLOGWPeV8UvBklSTnIWdsNh0A4g6RiAI/n17vZuWBVvncQNSBAYEK5OvNGDbSMdRdE+AJdl2aJumfjWdX4EIwDvDt7UjSEAAAAASUVORK5CYII=",
parameters => []
);
Expand Down
2 changes: 1 addition & 1 deletion lib/LANraragi/Plugin/Metadata/Ksk.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package LANraragi::Plugin::Metadata::Ksk;

use strict;
use warnings;

use utf8;
use LANraragi::Model::Plugins;
use LANraragi::Utils::Logging qw(get_plugin_logger);
use LANraragi::Utils::Archive qw(is_file_in_archive extract_file_from_archive);
Expand Down
2 changes: 1 addition & 1 deletion lib/LANraragi/Utils/Database.pm
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ sub set_title ( $id, $newtitle ) {
# Set $append to 1 if you want to append the tags instead of replacing them.
sub set_tags ( $id, $newtags, $append = 0 ) {

my $redis = LANraragi::Model::Config->get_redis;
my $redis = LANraragi::Model::Config->get_redis;
my $oldtags = $redis->hget( $id, "tags" );
$oldtags = redis_decode($oldtags);

Expand Down
12 changes: 6 additions & 6 deletions lib/LANraragi/Utils/Generic.pm
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ sub start_minion {
my $logger = get_logger( "Minion", "minion" );

my $numcpus = Sys::CpuAffinity::getNumCpus();
$logger->info("在子进程中使用 $numcpus 并行作业启动新的 Minion 工作进程。");
$logger->info("Starting new Minion worker in subprocess with $numcpus parallel jobs.");

my $worker = $mojo->app->minion->worker;
$worker->status->{jobs} = $numcpus;
Expand All @@ -103,9 +103,9 @@ sub start_minion {
my $proc = Proc::Simple->new();
$proc->start(
sub {
$logger->info("Minion 工作线程 $$ 开始运行");
$logger->info("Minion worker $$ started");
$worker->run;
$logger->info("Minion 工作线程 $$ 停止运行");
$logger->info("Minion worker $$ stopped");
return 1;
}
);
Expand All @@ -123,7 +123,7 @@ sub _spawn {
my ( $job, $pid ) = @_;
my ( $id, $task ) = ( $job->id, $job->task );
my $logger = get_logger( "Minion Worker", "minion" );
$job->app->log->debug(qq{进程 $pid 正在执行作业 "$id" 和任务 "$task"});
$job->app->log->debug(qq{Process $pid is performing job "$id" with task "$task"});
}

# Start Shinobu and return its Proc::Background object.
Expand All @@ -134,7 +134,7 @@ sub start_shinobu {
$proc->start( $^X, "./lib/Shinobu.pm" );
$proc->kill_on_destroy(0);

$mojo->LRR_LOGGER->debug( "Shinobu 工作进程新的 PID " . $proc->pid );
$mojo->LRR_LOGGER->debug( "Shinobu Worker new PID is " . $proc->pid );

# Freeze the process object in the PID file
store \$proc, get_temp() . "/shinobu.pid";
Expand All @@ -159,7 +159,7 @@ sub shasum {
};

if ($@) {
$logger->error( "创建哈希时出错" . $_[0] . " -- " . $@ );
$logger->error( "Error building hash for " . $_[0] . " -- " . $@ );

return "";
}
Expand Down
Loading

0 comments on commit 612c2a5

Please sign in to comment.