From 9995d70d605fb1ff0030739f6ce251ba13b3ad5e Mon Sep 17 00:00:00 2001 From: difegue Date: Mon, 21 Mar 2022 00:43:18 +0100 Subject: [PATCH] (#590) Add an endpoint to Shinobu API for resetting the filemap --- lib/LANraragi/Controller/Api/Shinobu.pm | 26 +++++++++++++++++++ lib/LANraragi/Utils/Routing.pm | 1 + templates/config.html.tt2 | 9 +++++++ .../templates_config/config_files.html.tt2 | 14 ++++++++++ 4 files changed, 50 insertions(+) diff --git a/lib/LANraragi/Controller/Api/Shinobu.pm b/lib/LANraragi/Controller/Api/Shinobu.pm index 9fa6f77fb..0001fb7aa 100644 --- a/lib/LANraragi/Controller/Api/Shinobu.pm +++ b/lib/LANraragi/Controller/Api/Shinobu.pm @@ -19,6 +19,32 @@ sub shinobu_status { ); } +sub reset_filemap { + my $self = shift; + + # This is a shinobu endpoint even though we're deleting stuff in redis + # since we'll have to restart shinobu anyway to proc filemap re-creation. + + my $redis = $self->LRR_CONF->get_redis; + $redis->del("LRR_FILEMAP"); + + my $shinobu = ${ retrieve( get_temp . "/shinobu.pid" ) }; + + #commit sudoku + $shinobu->kill(); + + # Create a new Process, automatically stored in TEMP_FOLDER/shinobu.pid + my $proc = start_shinobu($self); + + $self->render( + json => { + operation => "shinobu_rescan", + success => $proc->poll(), + new_pid => $proc->pid + } + ); +} + sub stop_shinobu { my $self = shift; my $shinobu = ${ retrieve( get_temp . "/shinobu.pid" ) }; diff --git a/lib/LANraragi/Utils/Routing.pm b/lib/LANraragi/Utils/Routing.pm index 3cad501ed..4d078fbcc 100644 --- a/lib/LANraragi/Utils/Routing.pm +++ b/lib/LANraragi/Utils/Routing.pm @@ -130,6 +130,7 @@ sub apply_routes { $logged_in_api->get('/api/shinobu')->to('api-shinobu#shinobu_status'); $logged_in_api->post('/api/shinobu/stop')->to('api-shinobu#stop_shinobu'); $logged_in_api->post('/api/shinobu/restart')->to('api-shinobu#restart_shinobu'); + $logged_in_api->post('/api/shinobu/rescan')->to('api-shinobu#reset_filemap'); # Minion API $public_api->get('/api/minion/:jobid')->to('api-minion#minion_job_status'); diff --git a/templates/config.html.tt2 b/templates/config.html.tt2 index f83bbbce8..189a17af2 100644 --- a/templates/config.html.tt2 +++ b/templates/config.html.tt2 @@ -148,6 +148,15 @@ }); } + function rescanContentFolder() { + $("#rescan-button").prop("disabled", true); + Server.callAPI("/api/shinobu/rescan", "POST", "Content folder rescan started!", "Error while restarting Worker:", + () => { + $("#rescan-button").prop("disabled", false); + shinobuStatus(); + }); + } + // Update the status of the background worker. function shinobuStatus() { Server.callAPI("/api/shinobu", "GET", null, "Error while querying Shinobu status:", diff --git a/templates/templates_config/config_files.html.tt2 b/templates/templates_config/config_files.html.tt2 index 00376a72e..35ac9c51e 100644 --- a/templates/templates_config/config_files.html.tt2 +++ b/templates/templates_config/config_files.html.tt2 @@ -11,6 +11,20 @@ + + + + + + + + Click this button to trigger a rescan of the Archive Directory in case you're missing files,
+ or some data such as total page counts.
+
+ + +

Maximum
Temporary Folder Size